{ 2005 06 11 mod by amg & Terry } { Added DEMO symbol for use of ESPL in playback} { Added Chart1 DEMO symbol with YM as the default setting. } { ******* READ READ READ CAUTION CAUTION READ OR YOUR PLAYBACK SUFFERS ******* } { For DEMO with *other* symbols change the symbol in line 229 which looks like this: } { **** if LeftStr(cSymbol,4)='DEMO' then cSymbol :='YM'; **** } { change this ----> ^^ <----- } { THE DYO "AlanBars" to highlight CONFLICTS do not use } { REMEMBER TO SAVE THEN RUN } { 2005 05 22 mod by Quartz } { Tab 14 now sets line colors too, added ZB support w/ 32's, } { added allowing multiple Boxes per chart, } { removed ESPL 1, fixed %levels in Gann to draw quartile percents correctly, } { autodelete alanbox study with safety catches, fixed to allow other ESPL's on chart } { added NQ, added back 50% verical line option, added abort code for playback etc } {todo: TimeZone needs testing? } { 2005 05 04 mod by Terry Thrift terry@thrift.com} { Tab 14 of Gann Box may be used to set colors, line style, markers of Gann boxes only } { eLine Properties are preset in ESPL } { Adjust Start Times of Symbols by the Time Zone set in Ensign } { Added @ES symbol for DTN ES contract } { Added support to draw boxes on prior dates } { Improved support for Prior High and Low suggestions } { Added draw the prior day when the start bar for current date does not yet exist } { original version by Kent } var G_firstTime :integer; G_upAngColor, G_dnAngColor, G_dnAngStyle, G_upAngStyle :integer; procedure TimeZoneAdjust( GMTTime :integer ) :integer; var h, m, z :integer; begin h := trunc(GMTTime /100); m := GMTTime - 100*h; h := h -5 -System( eTimeZone ); // assumes that time coming in is gmt time zone if h < 0 then h := h + 24; if h > 23 then h := h - 24; Result := m + 100*h; end; procedure MyAddLine( bar0 :integer; price0 :real; bar1 :integer; price1 :real; lineColor :integer; lineStyle :integer ); var h :integer; begin h := Addline(eLine,0,bar0,price0,bar1,price1); SetStudy( h, 100, 1 ); // enable the first checkbox only (DrawLine) SetStudy( h, 50, lineColor ); // color it SetStudy( h, 110, lineStyle ); // style to thin line SetStudy( h, 70, 0 ); // no left marker SetStudy( h, 81, 0 ); // no right marker if (False) then begin // If want angulars to extend past box set to True SetStudy( h, 100, 1+2 ); // enable the first 2 checkboxs only (DrawLine) SetStudy( h, 51, lineColor ); // color it SetStudy( h, 111, lineStyle ); // style to thin line SetStudy( h, 71, 0 ); // no left marker SetStudy( h, 82, 0 ); // no right marker SetStudy( h, 28, 1 ); // extend once end; SetStudy( h, 12, False ); // uncheck Horizontal SetStudy( h, 13, False ); // uncheck Alarmed SetStudy( h, 14, False ); // uncheck Lock Length SetStudy( h, 15, False ); // uncheck H/L Channel SetStudy( h, 16, False ); // uncheck PTT Channel end; procedure MyAddGann( bar0 :integer; price0 :real; bar1 :integer; price1 :real; Tab :integer; bottomP :boolean; topP :boolean ); var h,i,horizontal50 :integer; begin {the color, line style, markers and globals should be set and stored in a Tab} {the rest is controlled by this function} h := AddLine(eGannSquare,Tab,bar0,price0,bar1,price1); G_upAngColor := GetStudy( 0, 50+5 ); // get up angular line color G_dnAngColor := GetStudy( 0, 50+6 ); // get dn angular line color G_upAngStyle := GetStudy( 0, 110+5 ); // get up angular line style G_dnAngStyle := GetStudy( 0, 110+6 ); // get dn angular line style i := 2+4+8; // check 3 horizontal skipping 1st if bottomP then i := i + 1; // check 1st horizontal when bottom if topP then i := i + 16; // check 5th horizontal when top SetStudy( h, 100, i ); // check horizontal boxes horizontal50 := GetStudy( h, 101 ); horizontal50 := horizontal50 shl 22; // shift it 22 bits - so strange - no real bitwise operators in espl? horizontal50 := horizontal50 shr 31; // shift it 31 bits if horizontal50 = 1 then horizontal50 := 512 else horizontal50 := 0; SetStudy( h, 101, 256+horizontal50+1024 ); // check last 3 vert boxes SetStudy( h, 30, 0 ); // set level SetStudy( h, 31, 25 ); // set level SetStudy( h, 32, 50 ); // set level SetStudy( h, 33, 75 ); // set level SetStudy( h, 34, 100 ); // set level SetStudy( h, 35, 1 ); // set level SetStudy( h, 36, 1 ); // set level SetStudy( h, 37, 1 ); // set level SetStudy( h, 38, 0 ); // set level SetStudy( h, 39, 50 ); // set level SetStudy( h, 40, 100 ); // set level SetStudy( h, 12, False ); // uncheck Fan Lines SetStudy( h, 13, False ); // uncheck % of Price A end; procedure FindHL( StartBar, EndBar :integer; var hPrice, lPrice :real ); var i :integer; bDate,bVol,bTime :integer; h, l, bOpen,bHigh,bLow,bClose :real; begin h := -1000000; // max neg num? l := 1000000; // max pos num? writeln( StartBar, ' ', EndBar ); for i:= StartBar to EndBar do begin GetBar(i, bDate, bOpen, bHigh, bLow, bClose, bVol, bTime); if bHigh > h then h := bHigh; if bLow < l then l := bLow; end; hPrice := h; lPrice := l; end; procedure PriorNonWeekendTradingDay( var sDate :TDateTime; sTime :TDateTime ) :integer; var i,loop :integer; done :boolean; begin loop:=0; Result := 1; repeat inc(loop); sDate := sDate -1; done := (Bar(eIndex,DateToLong(sDate),sTime) <> 0) AND (DayOfWeek(sDate)>1) AND (DayOfWeek(sDate)<7) ; if (loop>1000) then begin Result := -1; done:= True; end; until done = True; end; procedure FindAlanBox(i:integer) : integer; var loop,studyHandle :integer; begin loop:=10; Result := -1; while (loop>0) do begin studyHandle:=FindStudy(eESPL,loop); if (studyHandle<>False) then begin if (GetStudy(studyHandle,27) = "Alan Box") then begin if (GetStudy(studyHandle,11) = 56) then begin loop:=0; Result := 1; end; end; end; dec(loop); end; end; procedure RemoveAlanBox; var loop,studyHandle :integer; begin if (GetStudy(0,11)<60) then begin loop:=10; while (loop>0) do begin studyHandle:=FindStudy(eESPL,loop); if (studyHandle<>False) then begin if (GetStudy(studyHandle,11) = 56) then begin if (GetStudy(studyHandle,27) = "Alan Box") then begin Remove(studyHandle); end; end; end; dec(loop); end; end; end; procedure AlanBox; var {local variables} i, StartBar,EndBar,StartTime,BarCnt,h,retval :integer; B1Top, B1Low :Float; sDate, sTime :TDateTime; s,e,y,cSymbol :String; lDate :LongInt; oPrice,hPrice,lPrice,cPrice,dRange :real; {oIndex,hIndex,lIndex,cIndex,Tab :integer;} Tab :integer; DebugOn :boolean; label Abort; begin if ((GetStudy(0,11) = 56) AND (GetStudy(0,67)<>36)) then begin // sanity check -prevents erroneous calls if FindAlanBox(i)>0 then Begin SetStudy(0,67,36); // for sanity check to prevent repeats on refresh etc DebugOn := True; SetUser(eRepaint, False); SetUser(eClose, True); SetUser(eShow1,False); SetUser(eShow2,False); SetUser(eShow3,False); SetUser(eShow4,False); SetUser(eShow5,False); {Test for which symbol is on the chart and set defaults } cSymbol:=GetVariable(eSymbol); if LeftStr(cSymbol,4)='DEMO' then cSymbol :='YM'; {set Defaults for the Symbols } if LeftStr(cSymbol,2)='YM' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,3)='EUR' then begin StartTime:= TimeZoneAdjust( 0010 ); //---Set the time of the Start Bar BarCnt:=137; //<----Set the number of bars for the trading session ,191 sundays Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,3)='ER2' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,2)='AB' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,3)='@ES' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,2)='ES' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,2)='NQ' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,2)='DE' then begin StartTime:= TimeZoneAdjust( 1330 ); //---Set the time of the Start Bar BarCnt:=47; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,2)='ZB' then begin StartTime:= TimeZoneAdjust( 1300 ); //---Set the time of the Start Bar BarCnt:=39; //<----Set the number of bars for the trading session Tab:=13; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,3)='GBL' then begin StartTime:= TimeZoneAdjust( 0810 ); //---Set the time of the Start Bar BarCnt:=65; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,2)='AX' then begin StartTime:= TimeZoneAdjust( 0810 ); //---Set the time of the Start Bar BarCnt:=65; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; if LeftStr(cSymbol,3)='DAX' then begin StartTime:= TimeZoneAdjust( 0810 ); //---Set the time of the Start Bar BarCnt:=65; //<----Set the number of bars for the trading session Tab:=14; //<----Set the tab for default gann box properties. end; sDate:=Date; { Verify Date with the user via an Input Box} lDate:=DateToLong(sDate)-1000000; repeat lDate:=InputBox(cSymbol,'Verify Date', lDate); if DebugOn then writeln('You entered ',lDate); until (lDate<>0); sDate:=LongToDate(lDate+1000000); sTime:=StartTime; if 0 = Bar(eIndex,DateToLong(sDate),sTime) then //today's start bar does not yet exist retval := PriorNonWeekendTradingDay(sDate,sTime); // so go back to yesterday if (retval = -1) then goto Abort; // end of this routine lDate:=DateToLong(sDate); StartBar:=Bar(eIndex,ldate,sTime); if DebugOn then writeln(eIndex,' ',ldate,' ',sTime,' ',StartBar,' ',EndBar); {GetLevels(-2, oIndex, hIndex, lIndex, cIndex);} {GetLevels(2, oPrice, hPrice, lPrice, cPrice);} retval := PriorNonWeekendTradingDay(sDate,sTime); // so go back one more day if (retval = -1) then goto Abort; // end of this routine FindHL( Bar(eIndex,DateToLong(sDate),sTime), StartBar-1, hPrice, lPrice ); if DebugOn then if StartBar > BarEnd then writeln( 'start ', StartBar, ' end ', BarEnd ); if LeftStr(cSymbol,2)='YM' then begin hPrice:=Format('%5.0f',hPrice); lPrice:=Format('%5.0f',lPrice); end; if LeftStr(cSymbol,3)='EUR' then begin hPrice:=Format('%1.4f',hPrice); lPrice:=Format('%1.4f',lPrice); end; if LeftStr(cSymbol,4)='ER2' then begin hPrice:=Format('%3.1f',hPrice); lPrice:=Format('%3.1f',lPrice); end; if LeftStr(cSymbol,2)='AB' then begin hPrice:=Format('%3.1f',hPrice); lPrice:=Format('%3.1f',lPrice); end; if LeftStr(cSymbol,3)='@ES' then begin hPrice:=Format('%4.2f',hPrice); lPrice:=Format('%4.2f',lPrice); end; if LeftStr(cSymbol,2)='ES' then begin hPrice:=Format('%4.2f',hPrice); lPrice:=Format('%4.2f',lPrice); end; if LeftStr(cSymbol,2)='DE' then begin hPrice:=Format('%4.2f',hPrice); lPrice:=Format('%4.2f',lPrice); end; if LeftStr(cSymbol,2)='NQ' then begin hPrice:=Format('%4.2f',hPrice); lPrice:=Format('%4.2f',lPrice); end; if LeftStr(cSymbol,2)='ZB' then begin hPrice:= Trunc(hPrice) + ((Frac(hPrice) / 0.03125)/100); hPrice:=Format('%3.5f',hPrice); lPrice:= Trunc(lPrice) + ((Frac(lPrice) / 0.03125)/100); lPrice:=Format('%3.5f',lPrice); end; if LeftStr(cSymbol,5)='GBL' then begin hPrice:=Format('%3.2f',hPrice); lPrice:=Format('%3.2f',lPrice); end; if LeftStr(cSymbol,2)='AX' then begin hPrice:=Format('%4.2f',hPrice); lPrice:=Format('%4.2f',lPrice); end; if LeftStr(cSymbol,3)='DAX' then begin hPrice:=Format('%4.2f',hPrice); lPrice:=Format('%4.2f',lPrice); end; { Verify High and Low Price with the user via an Input Box} repeat hPrice:=InputBox(cSymbol,'Verify Prior High', hPrice); if DebugOn then writeln('You entered '+hPrice); lPrice:=InputBox(cSymbol,'Verify Prior Low', lPrice); if DebugOn then writeln('You entered '+lPrice); until (hPrice<>0); if LeftStr(cSymbol,2)='ZB' then begin hPrice:= Trunc(hPrice) + ((Frac(hPrice)*100) / 32.0); hPrice:=Format('%3.5f',hPrice); lPrice:= Trunc(lPrice) + ((Frac(lPrice)*100) / 32.0); lPrice:=Format('%3.5f',lPrice); end; dRange:=hPrice-lPrice; {if DebugOn then writeln('Debug ','lDate ',ldate,' ',sTime,' ',StartBar,' ',hIndex,' ',lIndex,' ',Format('%1.4f',hPrice),' ',Format('%1.4f',lPrice),' ',i,' ',cSymbol);} if DebugOn then writeln('Debug ','lDate ',ldate,' ',sTime,' ',StartBar,' ',Format('%1.4f',hPrice),' ',Format('%1.4f',lPrice),' ',i,' ',cSymbol); MyAddGann(StartBar,hPrice ,StartBar+BarCnt,hPrice+dRange,Tab,True,True); //Add Top Square MyAddGann(StartBar,lPrice ,StartBar+BarCnt,hPrice ,Tab,True,False); //Add Middle Square MyAddGann(StartBar,lPrice ,StartBar+BarCnt,lPrice-dRange,Tab,False,True); //Add Bottom Square MyAddline(StartBar,lPrice ,StartBar+BarCnt,hPrice , G_upAngColor, G_upAngStyle); //Add MSqr Low to High MyAddline(StartBar,hPrice ,StartBar+BarCnt,lPrice , G_dnAngColor, G_dnAngStyle); //Add MSqr High to low MyAddline(StartBar,hPrice ,StartBar+BarCnt,hPrice+dRange, G_upAngColor, G_upAngStyle); //Add HSqr Low to High MyAddline(StartBar,hPrice+dRange,StartBar+BarCnt,hPrice , G_dnAngColor, G_dnAngStyle); //Add HSqr High to low MyAddline(StartBar,lPrice-dRange,StartBar+BarCnt,lPrice , G_upAngColor, G_upAngStyle); //Add LSqr Low to High MyAddline(StartBar,lPrice ,StartBar+BarCnt,lPrice-dRange, G_dnAngColor, G_dnAngStyle); //Add LSqr High to low MyAddline(StartBar,lPrice-(dRange/2),StartBar+BarCnt,lPrice+(dRange/2), G_upAngColor, G_upAngStyle); //Add LSqr 50% to Mid 50% MyAddline(StartBar,lPrice+(dRange/2),StartBar+BarCnt,HPrice+(dRange/2), G_upAngColor, G_upAngStyle); //Add Mid 50% to HSqr 50% MyAddline(StartBar,HPrice+(dRange/2),StartBar+BarCnt,lPrice+(dRange/2), G_dnAngColor, G_dnAngStyle); //Add HSqr 50% to Mid 50% MyAddline(StartBar,lPrice+(dRange/2),StartBar+BarCnt,lPrice-(dRange/2), G_dnAngColor, G_dnAngStyle); //Add Mid 50% to LSqr 50% MyAddline(StartBar,lPrice-(dRange/2)-dRange,StartBar+BarCnt,lPrice-(dRange/2) , G_upAngColor, G_upAngStyle); //Add LLSqr 50% to LSqr 50% MyAddline(StartBar,lPrice+(dRange/2)+dRange,StartBar+BarCnt,HPrice+(dRange/2)+dRange, G_upAngColor, G_upAngStyle); //Add HSqr 50% to HHSqr 50% MyAddline(StartBar,HPrice+(dRange/2)+dRange,StartBar+BarCnt,lPrice+(dRange/2)+dRange, G_dnAngColor, G_dnAngStyle); //Add HHSqr 50% to HSqr 50% MyAddline(StartBar,lPrice-(dRange/2) ,StartBar+BarCnt,lPrice-(dRange/2)-dRange, G_dnAngColor, G_dnAngStyle); //Add LSqr 50% to LLSqr 50% end; end; Abort: if (retval = -1) then writeln("__aborting alan box"); end; procedure RegisterStudies; Begin if G_firstTime=0 then begin G_firstTime := 1; registerStudy("Alan Box",56,1); writeln("studies registered"); end; end; {********** Main Program **********} begin btnESPL56.Caption:='Alan Box'; RegisterStudies; if ESPL=56 then AlanBox; if ESPL<>56 then RemoveAlanBox; if ESPL=2 then writeln(TimeZoneAdjust( 1430 )); end;