// Note this is a work in progress, and a combination of many other pieces of code // I am working on. Several of the "if" statements are zeroed out to leave it mainly // just for swing lines at this time. It is also untested code. // procedure AutoRemoveFibs2; var loop,myHandle: integer; begin loop:=1; while (loop<80) do begin myHandle:=FindStudy(eFibonacci,loop); if (myHandle=False) then begin loop:=80; end else begin if (GetStudy(myHandle,17) = "AFib") then if (Remove(myHandle)=False) then writeln("error in AFib remove"); end; inc(loop); end; end; procedure AutoFibs2; var i,t,mhigh,mhigh2,mlow,mlow2,mhighB,mhighB2,mlowB,mlowB2,fibtabup,fibtabdn,goingdown: integer; prevdayStart,DoneFlag,myHandle,myHandle2,myHandle3,InitSizeReq2,InitSizeReq3: integer; savedBarRight,myBarLeft,SizeReq,SizeReq2,SizeReq3,InitSizeReq: integer; ext1up,ext2up,ext3up,ext1dn,ext2dn,ext3dn,extFup,extFdn: integer; mTrue,mFalse,AddUp,AddDown: integer; begin InitSizeReq:=250; InitSizeReq2:=500; InitSizeReq3:=0; mTrue:=2348; mFalse:=8945; SetUser(eScaleMode, eNormal); SetUser(eRepaint, True); SetUser(eClose, True); SetUser(eName,"Auto Fibs"); DoneFlag:=GetUser(6,9); if (GetUser(6,15)<>ChartBar(0,eOpen,5)) then begin AutoRemoveFibs2; AutoRemoveFibs2; AutoRemoveFibs2; AutoRemoveFibs2; AutoRemoveFibs2; AutoRemoveFibs2; if (DoneFlag=1234) then SetUser(6,4776,1); end; if ((GetUser(6,1)<>4777) OR (DoneFlag<>1234)) then begin if (GetUser(6,1)<>4776) then begin SetUser(eParm1,InitSizeReq); SetUser(eParm2,InitSizeReq2); SetUser(eParm3,InitSizeReq3); fibtabup:=5; SetUser(6,fibtabup,16); fibtabdn:=7; SetUser(6,fibtabdn,18); goingdown:=0; SetUser(6,goingdown,17); ext1up:=0; ext2up:=0; ext3up:=0; ext1dn:=0; ext2dn:=0; ext3dn:=0; extFup:=0; extFdn:=0; end; SetUser(6,ChartBar(0,eOpen,5),15); DoneFlag:=0; SetUser(6,DoneFlag,9); savedBarRight:=0; myHandle:=0; myHandle2:=0; SetUser(6,myHandle,2); SetUser(6,myHandle2,14); mhigh:=0; mhigh2:=0; mlow:=0; mlow2:=0; mhighB:=0; mhighB2:=0; mlowB:=0; mlowB2:=0; SetUser(6,4777,1); myBarLeft:=BarLeft-200; savedBarRight:=BarRight; SetUser(6,myBarLeft,7); SetUser(6,savedBarRight,8); mhigh:=Bar(eHigh,myBarLeft); mhighB:=myBarLeft; mlow:=Bar(eLow,myBarLeft); mlowB:=myBarLeft; SetUser(6,mhigh,3); SetUser(6,mhighB,4); SetUser(6,mlow,5); SetUser(6,mlowB,6); mhigh2:=mhigh; mhighB2:=mhighB; mlow2:=mlow; mlowB2:=mlowB; SetUser(6,mhigh,10); SetUser(6,mhighB,11); SetUser(6,mlow,12); SetUser(6,mlowB,13); AddUp:=0; AddDown:=0; end else begin if (GetUser(eParm1)<=0) then SetUser(eParm1,InitSizeReq); if (GetUser(eParm2)<0) then SetUser(eParm2,0); if (GetUser(eParm3)<0) then SetUser(eParm3,0); fibtabup:=GetUser(6,16); if (fibtabup<=0) then fibtabup:=5; fibtabdn:=GetUser(6,18); if (fibtabdn<=0) then fibtabdn:=7; myHandle:=GetUser(6,2); myHandle2:=GetUser(6,14); goingdown:=GetUser(6,17); mhigh:=GetUser(6,3); mhighB:=GetUser(6,4); mlow:=GetUser(6,5); mlowB:=GetUser(6,6); mhigh:=GetUser(6,10); mhighB:=GetUser(6,11); mlow:=GetUser(6,12); mlowB:=GetUser(6,13); myBarLeft:=GetUser(6,7); savedBarRight:=GetUser(6,8); if (savedBarRightBarRight) then begin myBarLeft:=savedBarRight; savedBarRight:=savedBarRight; DoneFlag:=False; end; end; SizeReq:=GetUser(eParm1); SizeReq2:=GetUser(eParm2); SizeReq3:=GetUser(eParm3); i:=myBarLeft; fibtabup:=6; fibtabdn:=8; // Wave new trend size SizeReq:=275; // Wave minor pullbacks reset size SizeReq2:=150; // Wave Symmetry min size SizeReq3:=200; while (i < BarRight) do begin if ((Bar(eDate,i)<>Bar(eDate,i-1)) AND 1) then begin ext1up:=0; ext2up:=0; ext3up:=0; ext1dn:=0; ext2dn:=0; ext3dn:=0; extFup:=0; extFdn:=0; AddUp:=0; AddDown:=0; mhighB2:=i; mhigh2:=Bar(eHigh,i); mlowB2:=i; mlow2:=Bar(eLow,i); end; if (0) then begin //Going Down Fib lines if (goingdown) then begin if (mhigh= SizeReq) AND (mlowB<>i)) then begin goingdown:=0; mhigh:=Bar(eHigh,i); mhighB:=i; myHandle:=AddLine(eFibonacci,fibtabup,mlowB,mlow,mhighB,mhigh); SetStudy(myHandle,17,"AFib"); end else begin if (((Bar(eHigh,i)-mlow) >= SizeReq2) AND (mlowB<>i)) then begin if (mhighB>=mlowB) then begin if (mhighBar(eLow,i)) then begin mlow:=Bar(eLow,i); mlowB:=i; if (myHandle<>0) then if (GetStudy(myHandle,17) = "AFib") then if (Remove(myHandle)=False) then writeln("error in AFib remove"); if ((mhigh-Bar(eLow,i)) >= SizeReq) then begin myHandle:=AddLine(eFibonacci,fibtabdn,mhighB,mhigh,mlowB,mlow); SetStudy(myHandle,17,"AFib"); end; end; end //Going Up Fib lines else begin if (mlow>Bar(eLow,i)) then begin mlow:=Bar(eLow,i); mlowB:=i; end; if (((mhigh-Bar(eLow,i)) >= SizeReq) AND (mhighB<>i)) then begin goingdown:=1; mlow:=Bar(eLow,i); mlowB:=i; myHandle:=AddLine(eFibonacci,fibtabdn,mhighB,mhigh,mlowB,mlow); SetStudy(myHandle,17,"AFib"); end else begin if (((mhigh-Bar(eLow,i)) >= SizeReq2) AND (mhighB<>i)) then begin if (mlowB>=mhighB) then begin if (mlow>Bar(eLow,i)) then begin mlow:=Bar(eLow,i); mlowB:=i; myHandle:=0; end; end else begin mlow:=Bar(eLow,i); mlowB:=i; myHandle:=0; end; end; end; if (mhigh0) then if (GetStudy(myHandle,17) = "AFib") then if (Remove(myHandle)=False) then writeln("error in AFib remove"); if ((Bar(eHigh,i)-mlow) >= SizeReq) then begin myHandle:=AddLine(eFibonacci,fibtabup,mlowB,mlow,mhighB,mhigh); SetStudy(myHandle,17,"AFib"); end; end; end; end; //Down Symmetry if (mhighB2= SizeReq3)) then begin mhigh2:=Bar(eHigh,i); mhighB2:=i; AddDown:=1; AddNote(extFdn,12,mlowB2,mlow2-50); extFup:=mhigh2-mlow2; end; if (mlow2>Bar(eLow,i)) then begin if (((Bar(eHigh,i)-mlow2)Bar(eLow,i)) then begin mlow2:=Bar(eLow,i); mlowB2:=i; end; if ((mhigh2-Bar(eLow,i)) >= SizeReq3) then begin mlow2:=Bar(eLow,i); mlowB2:=i; AddUp:=1; AddNote(extFup,13,mhighB2,mhigh2+150); extFdn:=mhigh2-mlow2; end; if (mhigh2=800) then begin ext1dn:=ext2dn; ext2dn:=ext3dn; ext3dn:=0; end; if (ext2up>=800) then begin ext1up:=ext2up; ext2up:=ext3up; ext3up:=0; end; if (ext2dn>=600) then begin if ((ext1dn-ext2dn)<=125) then begin ext2dn:=ext3dn; ext3dn:=0; end; end; if (ext2up>=600) then begin if ((ext1up-ext2up)<=125) then begin ext2up:=ext3up; ext3up:=0; end; end; if (extFdn=0) then AddDown:=0; if (extFup=0) then AddUp:=0; if (AddDown) then begin if (extFdn)>ext1dn then begin ext3dn:=ext2dn; ext2dn:=ext1dn; ext1dn:=extFdn; end else begin if ((extFdn<>ext1dn) AND (extFdn<>ext2dn)) then begin if (extFdn>ext2dn) then begin if (ext3dn=0) then ext3dn:=ext2dn; ext2dn:=extFdn; end else ext3dn:=extFdn; end; end; AddDown:=0; end; if (AddUp) then begin if (extFup)>ext1up then begin ext3up:=ext2up; ext2up:=ext1up; ext1up:=extFup; end else begin if ((extFup<>ext1up) AND (extFup<>ext2up)) then begin if (extFup>ext2up) then begin if (ext3up=0) then ext3up:=ext2up; ext2up:=extFup; end else ext3up:=extFup; end; end; AddUp:=0; end; i:=i+1; end; if (i=BarRight AND 0) then begin SetPen(clFuchsia,2,eSolid); if (ext1up<>0) then begin MoveToLineTo(IndextoX(BarRight)+10,PriceToY(mlow2+ext1up),IndextoX(BarRight)+40,PriceToY(mlow2+ext1up)); MoveToLineTo(IndextoX(BarRight)+17,PriceToY(mlow2+ext1up)+1,IndextoX(BarRight)+17,PriceToY(mlow2+ext1up)+12); end; if (ext2up<>0) then begin MoveToLineTo(IndextoX(BarRight)+10,PriceToY(mlow2+ext2up),IndextoX(BarRight)+40,PriceToY(mlow2+ext2up)); MoveToLineTo(IndextoX(BarRight)+17,PriceToY(mlow2+ext2up)+1,IndextoX(BarRight)+17,PriceToY(mlow2+ext2up)+12); end; if (ext3up<>0) then begin MoveToLineTo(IndextoX(BarRight)+10,PriceToY(mlow2+ext3up),IndextoX(BarRight)+40,PriceToY(mlow2+ext3up)); MoveToLineTo(IndextoX(BarRight)+17,PriceToY(mlow2+ext3up)+1,IndextoX(BarRight)+17,PriceToY(mlow2+ext3up)+12); end; SetPen(0x00FF00,2,eSolid); if (ext1dn<>0) then begin MoveToLineTo(IndextoX(BarRight)+15,PriceToY(mhigh2-ext1dn),IndextoX(BarRight)+40,PriceToY(mhigh2-ext1dn)); MoveToLineTo(IndextoX(BarRight)+20,PriceToY(mhigh2-ext1dn)-2,IndextoX(BarRight)+20,PriceToY(mhigh2-ext1dn)-11); end; if (ext2dn<>0) then begin MoveToLineTo(IndextoX(BarRight)+15,PriceToY(mhigh2-ext2dn),IndextoX(BarRight)+40,PriceToY(mhigh2-ext2dn)); MoveToLineTo(IndextoX(BarRight)+20,PriceToY(mhigh2-ext2dn)-2,IndextoX(BarRight)+20,PriceToY(mhigh2-ext2dn)-11); end; if (ext3dn<>0) then begin MoveToLineTo(IndextoX(BarRight)+15,PriceToY(mhigh2-ext3dn),IndextoX(BarRight)+40,PriceToY(mhigh2-ext3dn)); MoveToLineTo(IndextoX(BarRight)+20,PriceToY(mhigh2-ext3dn)-2,IndextoX(BarRight)+20,PriceToY(mhigh2-ext3dn)-11); end; end; myBarLeft:=savedBarRight; DoneFlag:=1234; SetUser(6,myHandle,2); SetUser(6,mhigh,3); SetUser(6,mhighB,4); SetUser(6,mlow,5); SetUser(6,mlowB,6); SetUser(6,myBarLeft,7); SetUser(6,savedBarRight,8); SetUser(6,DoneFlag,9); SetUser(6,mhigh,10); SetUser(6,mhighB,11); SetUser(6,mlow,12); SetUser(6,mlowB,13); SetUser(6,myHandle2,14); SetUser(6,fibtabup,16); SetUser(6,fibtabdn,18); SetUser(6,goingdown,17); end;