Code: Select all
[LegacyColorValue = true];
{ _TRO_BuyZone }
{Attn: TS
if this indicator is posted on the TS Forum, I, TheRumpledOne, did NOT post it there,
so I can't be blamed for this indicator having my contact info.}
{Programmer: Avery T. Horton, Jr. aka TheRumpledOne,
gifts and donations accepted, PO Box 43575, Tucson, AZ 85733 }
{ © Copyright 2007 Avery T. Horton, Jr.}
// Value1 = GetAppInfo(aiApplicationType); // returns a value that identifies the calling window type
// cUnknown = 0 cChart = 1 cRadarScreen = 2 cOptionStation = 3
inputs:
iDecimals(4),
iOpen(dailyopen),
iOpenBuyZone(.1),
iBuyZoneHI(.2), {inside ask must be <= (OPEN + iBuyZoneHI) to place buy order}
iBuyZoneLO(.2), {inside bid must be >= (OPEN - iBuyZoneLO) to place buy order}
iPlotOpen(true),
ShortBotColor( red),
ShortTopColor( red),
OpenColor(white),
LongTopColor( blue),
LongBotColor( blue) ,
TLSize( 0 ), // 0 - 6 for thin to thick
TLStyle( 2 ), // 1 = solid, 2 = dashed, 3 = dotted, 4 = dashed 2, 5 = dashed 3
TL_Text_HVal ( 0 ) , // HVal: 0=left, 1=right, 2=centered,
TL_Text_VVal ( 1 ) ; // VVal: 1=Top, 0=Bottom, 2=Centered
variables:
FG1(white),
BG1(black),
FG2(white),
BG2(black),
FG3(white),
BG3(black),
FG4(white),
BG4(black),
PrevSessionDate( 0 ),
PrevSessionTime(0),
PrevSessionHigh( 0 ),
PrevSessionLow( 0 ),
PrevSessionClose( 0 ),
PrevSessionMid( 0 ),
PrevSessionOpen( 0 ),
SessionDate( 0 ),
SessionTime(0),
SessionOpen( 0 ),
SessionClose( 0 ),
SessionHigh( 0 ),
SessionLow( 0 ),
PrevSession(999999),
Candle(0),
CandleDaily(0),
ShortDiff( 0 ),
LongDiff( 0 ),
tShortDiff( "" ),
tLongDiff( "" ),
BuyZone( 0 ),
xBuyZone(0),
tBuyZone(""),
sSession(false),
sFirstPass(true),
xAppType(0),
TL_TextTime( 0 ),
xDailyOpen(0),
xBuyZoneHI(0), {inside ask must be <= (OPEN + iBuyZoneHI) to place buy order}
xBuyZoneLO(0), {inside bid must be >= (OPEN - iBuyZoneLO) to place buy order}
textShortBot(0),
textShortTop(0),
textLongTop(0),
textLongBot(0),
textOpen(0),
TLOpen( 0 ),
HavePrevLines( false ),
TLShortTop( 0 ),
TLLongTop( 0 ),
TLLongBot( 0 ),
TLShortBot( 0 ),
ShortBot( 0 ),
ShortTop( 0 ),
LongTop( 0 ),
LongBot( 0 ) ;
{commentary variables}
variables:
xcomm(0),
oComm1( "" ),
oComm2( "" ),
oComm3( "" ),
oComm4( "" ),
oComm5( "" ),
oComm6( "" ),
oComm7( "" ),
oComm8( "" ),
oComm9( "" ),
oComm10( "" );
{first time through}
if sFirstPass
then begin
sFirstPass = false;
xAppType = GetAppInfo(aiApplicationType); // cUnknown = 0 cChart = 1 cRadarScreen = 2 cOptionStation = 3
end; {if sFirstPass}
{ INITIALIZE }
FG1 = WHITE;
BG1 = BLACK;
fg2 = WHITE;
bg2 = BLACK;
fg3 = WHITE;
bg3 = BLACK;
fg4 = WHITE;
bg4 = BLACK;
{*************************************************}
{ C A L C U L A T I O N S }
{*************************************************}
Commentary(" ");
Commentary("CurrentSession(0) = ", numtostr( CurrentSession(0), 0 ) , NewLine);
Commentary("PrevSession = ", numtostr( PrevSession, 0 ) , NewLine);
sSession = false ;
if CurrentSession(0) <> PrevSession
then begin
sSession = true ;
PrevSessionOpen = SessionOpen;
PrevSessionDate = SessionDate;
PrevSessionTime = SessionTime;
PrevSessionClose = close[1];
PrevSessionHigh = SessionHigh;
PrevSessionLow = SessionLow;
SessionDate = date;
SessionTime = time;
SessionOpen = iOpen;
SessionHigh = iOpen;
SessionLow = iOpen;
PrevSession = CurrentSession(0);
PrevSessionMid = ( PrevSessionHigh + PrevSessionLow ) * .50 ;
end; // if CurrentSession(0) <> PrevSession
if High > SessionHigh then
SessionHigh = High ;
if Low < SessionLow then
SessionLow = Low ;
if d <> currentdate
then xDailyOpen = Opend(0)
else xDailyOpen = SessionOpen ;
// xDailyOpen = SessionOpen ;
LongTop = xDailyOpen + iBuyZoneHI;
LongBot = xDailyOpen + iOpenBuyZone;
ShortTop = xDailyOpen - iOpenBuyZone;
ShortBot = xDailyOpen - iBuyZoneLO;
ShortDiff = ShortTop - close ;
LongDiff = close - LongBot ;
tShortDiff = numtostr( ShortDiff , iDecimals ) ;
tLongDiff = numtostr( LongDiff , iDecimals ) ;
if xAppType = 1
then begin
TL_TextTime = AddTime( Time , 2 * BarInterval ) ;
{*************************************************}
if date this bar = currentdate
then begin
if HavePrevLines
then begin
If TLShortTop > 0
then value9 = TL_Delete( TLShortTop ) ;
If TLLongTop > 0
then value9 = TL_Delete( TLLongTop ) ;
If TLLongBot > 0
then value9 = TL_Delete( TLLongBot ) ;
If TLShortBot > 0
then value9 = TL_Delete( TLShortBot ) ;
If TLOpen > 0
then value9 = TL_Delete( TLOpen ) ;
end ; // if HavePrevLines
{ insert the new lines and set their colors/extents }
TLShortTop = TL_New( SessionDate, SessionTime, ShortTop, Date, Time, ShortTop ) ;
TLLongTop = TL_New( SessionDate, SessionTime, LongTop, Date, Time, LongTop ) ;
TLLongBot = TL_New( SessionDate, SessionTime, LongBot, Date, Time, LongBot ) ;
TLShortBot = TL_New( SessionDate, SessionTime, ShortBot, Date, Time, ShortBot ) ;
TL_SetColor( TLShortTop, ShortTopColor ) ;
TL_SetColor( TLLongTop, LongTopColor ) ;
TL_SetColor( TLLongBot, LongBotColor ) ;
TL_SetColor( TLShortBot, ShortBotColor ) ;
TL_SetStyle(TLLongTop,TLStyle);
TL_SetStyle(TLLongBot,TLStyle);
TL_SetStyle(TLShortTop,TLStyle);
TL_SetStyle(TLShortBot,TLStyle);
TL_SetExtLeft( TLShortTop, false ) ;
TL_SetExtLeft( TLLongTop, false ) ;
TL_SetExtLeft( TLLongBot,false ) ;
TL_SetExtLeft( TLShortBot,false ) ;
TL_SetExtRight( TLShortTop, true ) ;
TL_SetExtRight( TLLongTop, true ) ;
TL_SetExtRight( TLLongBot, true ) ;
TL_SetExtRight( TLShortBot, true ) ;
if iPlotOpen
then begin
TLOpen = TL_New( SessionDate, SessionTime, xDailyOpen, Date, Time, xDailyOpen ) ;
TL_SetColor( TLOpen, OpenColor ) ;
TL_SetStyle(TLOpen,TLStyle);
TL_SetExtLeft( TLOpen,false ) ;
TL_SetExtRight( TLOpen, true ) ;
end; // if iPlotOpen
{ set flag }
if HavePrevLines = false
then HavePrevLines = true ;
end ; // if date this bar <> currentdate
If textShortBot > 0
then value9 = Text_Delete( textShortBot ) ;
textShortBot = Text_New(Date, TL_TextTime ,ShortBot,"ShortBot ("+ NumToStr(ShortBot, iDecimals )+")");
Text_SetStyle(textShortBot, TL_Text_HVal , TL_Text_VVal );
Text_SetColor(textShortBot, ShortBotColor );
Text_SetLocation( textShortBot , date , TL_TextTime , ShortBot );
If textShortTop > 0
then value9 = Text_Delete( textShortTop) ;
textShortTop = Text_New(Date, TL_TextTime ,ShortTop,"ShortTop ("+ NumToStr(ShortTop, iDecimals )+")");
Text_SetStyle(textShortTop, TL_Text_HVal , TL_Text_VVal ); // HVal: 0=left, 1=right, 2=centered, / VVal: 0=Top, 1=Bottom, 2=Centered
Text_SetColor(textShortTop, ShortTopColor );
Text_SetLocation( textShortTop , date , TL_TextTime , ShortTop );
If textLongTop > 0
then value9 = Text_Delete( textLongTop) ;
textLongTop = Text_New(Date, TL_TextTime ,LongTop,"LongTop ("+ NumToStr(LongTop, iDecimals )+")");
Text_SetStyle(textLongTop, TL_Text_HVal , TL_Text_VVal ); // HVal: 0=left, 1=right, 2=centered, / VVal: 0=Top, 1=Bottom, 2=Centered
Text_SetColor(textLongTop, LongTopColor );
Text_SetLocation( textLongTop , date , TL_TextTime , LongTop );
If textLongBot > 0
then value9 = Text_Delete( textLongBot ) ;
textLongBot = Text_New(Date, TL_TextTime ,LongBot,"LongBot ("+ NumToStr(LongBot, iDecimals )+")");
Text_SetStyle(textLongBot,TL_Text_HVal , TL_Text_VVal ); // HVal: 0=left, 1=right, 2=centered, / VVal: 0=Top, 1=Bottom, 2=Centered
Text_SetColor(textLongBot, LongBotColor );
Text_SetLocation( textLongBot , date , TL_TextTime , LongBot );
If textOpen > 0
then value9 = Text_Delete( textOpen ) ;
textOpen = Text_New(Date, TL_TextTime , xDailyOpen ,"Open ("+ NumToStr(xDailyOpen, iDecimals )+")");
Text_SetStyle(textOpen,TL_Text_HVal , TL_Text_VVal ); // HVal: 0=left, 1=right, 2=centered, / VVal: 0=Top, 1=Bottom, 2=Centered
Text_SetColor(textOpen, OpenColor );
Text_SetLocation( textOpen , date , TL_TextTime , xDailyOpen );
end ; // if xAppType = 1
if xAppType = 2
then begin
candle = close - open ;
//CandleDaily = close - closeD(1) ;
CandleDaily = close - PrevSessionClose ;
{ Alert criteria }
If candle > 0
then begin
Fg3 = BLACK;
Bg3 = green;
end
else
If candle < 0
then begin
Fg3 = BLACK;
Bg3 = red;
end
else
begin
Fg3 = yellow;
Bg3 = BLACK;
end;
If CandleDaily > 0
then begin
Fg4 = BLACK;
Bg4 = green;
end
else
If CandleDaily < 0
then begin
Fg4 = BLACK;
Bg4 = red;
end
else
begin
Fg4 = yellow;
Bg4 = BLACK;
end;
If close < xdailyopen
and close > ShortTop
then begin
tBuyZone = "Wait " + tShortDiff ;
FG1 = RED;
BG1 = YELLOW;
end
else
If close > xdailyopen
and close < LongBot
then begin
tBuyZone = "Wait " + tLongDiff ;
FG1 = BLACK;
BG1 = YELLOW;
end;
If close crosses below xdailyopen
then begin
tBuyZone = "X Open " + tShortDiff ;
FG1 = RED;
BG1 = YELLOW;
end
else
If close crosses above xdailyopen
then begin
tBuyZone = "X Open " + tLongDiff ;
FG1 = BLACK;
BG1 = YELLOW;
end
else
If close crosses below LongTop
then begin
tBuyZone = "X LgTOP " + tLongDiff ;
FG1 = RED;
BG1 = YELLOW;
end
else
If close crosses above LongBot
then begin
tBuyZone = "X LgBOT " + tLongDiff ;
FG1 = BLACK;
BG1 = YELLOW;
end
else
If close > LongTop
then begin
tBuyZone = "ABOVE " + tLongDiff ;
FG1 = GREEN;
BG1 = BLACK;
end
else
If close crosses below ShortTop
then begin
tBuyZone = "X ShTOP " + tShortDiff ;
FG1 = red;
BG1 = YELLOW;
end
else
If close crosses above ShortBot
then begin
tBuyZone = "X ShBOT " + tShortDiff ;
FG1 = black;
BG1 = YELLOW;
end
else
If close < ShortBot
then begin
tBuyZone = "BELOW " + tShortDiff ;
FG1 = RED;
BG1 = BLACK;
end
else
If close > LongBot
and close <= LongTop
then begin
tBuyZone = "BUY " + tLongDiff ;
FG1 = BLACK;
BG1 = green;
end
else
If close >= ShortBot
and close < ShortTop
then begin
tBuyZone = "SHORT " + tShortDiff ;
FG1 = BLACK;
BG1 = red;
end;
if close > prevclose
then begin
FG2 = BLACK;
BG2 = green;
end
else
if close < prevclose
then begin
FG2 = yellow;
BG2 = BLACK;
end;
{ PLOTS }
Plot1( tBuyZone, "BuyZone", fg1 ) ;
SetPlotBGColor( 1, bg1);
Plot2( xdailyopen, "dailyopen", FG2 ) ;
SetPlotBGColor( 2, BG2);
Plot3( candle, "Candle", fg3 ) ;
SetPlotBGColor( 3, bg3);
Plot4( CandleDaily, "Dly C-C[1]", fg4 ) ;
SetPlotBGColor( 4, bg4);
Plot5( SessionTime, "Start", WHITE ) ;
SetPlotBGColor( 5, BLACK);
end ; // if xAppType = 2
xComm = _fCommentary(oComm1, oComm2, oComm3, oComm4, oComm5, oComm6, oComm7, oComm8, oComm9, oComm10);
CommentaryCl(oComm1 );
CommentaryCl(oComm2 );
CommentaryCl(oComm3 );
CommentaryCl(oComm4 );
CommentaryCl(oComm5 );
CommentaryCl(oComm6 );
CommentaryCl(oComm7 );
CommentaryCl(oComm8 );
CommentaryCl(oComm9 );
CommentaryCl(oComm10 );
Commentary(" ");
CommentaryCl( "CurrentDate: ", ELDateToString(CurrentDate) );
CommentaryCl( "Date: ", ELDateToString(Date) );
Commentary("CurrentSession(0) = ", numtostr( CurrentSession(0), 0 ) , NewLine);
Commentary(" ");
Commentary("Prev.Open = ", numtostr( PrevSessionOpen,iDecimals) , NewLine);
Commentary("Prev.High = ", numtostr( PrevSessionHigh,iDecimals) , NewLine);
Commentary("Prev.Low = ", numtostr( PrevSessionLow,iDecimals) , NewLine);
Commentary("Prev.Close = ", numtostr( PrevSessionClose,iDecimals) , NewLine);
Commentary("Prev.Mid = ", numtostr( PrevSessionMid,iDecimals) , NewLine);
Commentary(" ");
Commentary("Open = ", numtostr( Open,iDecimals) , NewLine);
Commentary("Opend(0) = ", numtostr( Opend(0),iDecimals) , NewLine);
Commentary("xdailyopen = ", numtostr( xdailyopen ,iDecimals) , NewLine);
Commentary("SessionOpen = ", numtostr( SessionOpen ,iDecimals) , NewLine);
Commentary(" ");
Commentary("LongTop = ", numtostr( LongTop,iDecimals) , NewLine);
Commentary("LongBot = ", numtostr( LongBot,iDecimals) , NewLine);
Commentary("ShortTop = ", numtostr( ShortTop,iDecimals) , NewLine);
Commentary("ShortBot = ", numtostr( ShortBot,iDecimals) , NewLine);
Commentary("iOpenBuyZone = ", numtostr( iOpenBuyZone,iDecimals) , NewLine);
Commentary("iBuyZoneHI = ", numtostr( iBuyZoneHI,iDecimals) , NewLine);
Commentary("iBuyZoneLO = ", numtostr( iBuyZoneLO,iDecimals) , NewLine);