Even with fixed font the formating is off but anyone with the determination to understand it shouldn't mind too much.
var: dir(0), mtDir(0), inside(false), longRngH(0), longRngL(0), myBar(0), myH(0), myL(0), myC(0), offset(0), Si(2), pi(0), mtLi(0), mtHi(0), BRi(0), TRi(0), rev(0), repeat(0), asc(false), des(false), p2t(false), p2b(false), nullAscPrice(0), nullDesPrice(0), nullP2Tprice(0), nullP2Bprice(0);
array:S[999,17](0), mtL[99,3](0), mtH[99,3](0), p[999,7,2](0), BR[999,3](0), TR[999,3](0);
if inside[1] then begin if H>longRngH or L<longRngL then inside=false; if H>longRngH and L>longRngL then dir=1; {up} if H<longRngH and L<longRngL then dir= -1; {down} end else begin if H<=H[1] and L>=L[1] then begin longRngL=L[1]; longRngH=H[1]; inside=true; {inside} end; if H>H[1] and L>L[1] then dir= 1; {up} if H<H[1] and L<L[1] then dir= -1; {down} end;
if inside=false then begin myBar=currentbar; myH=H; myL=L; myC=C; end;
if dir<>dir[1] then begin si=si+1; s[si,0]=myBar[1]; s[si,1]=myH[1]; s[si,2]=myL[1]; s[si,3]=myC[1]; if dir>0 then begin S[si,4]=myL[1]; s[si,5]=1; {swing=B} if s[si,2]<mtL[mtLi,2] then begin s[si,15]=-1; {mtL=lowerB} mtLi=mtLi+1; mtL[mtLi,0]=myBar[1]; mtL[mtLi,1]=myH[1]; mtL[mtLi,2]=myL[1]; mtL[mtLi,3]=myC[1]; end; if s[si,1]-s[si,2]>mtL[mtLi,1]-mtL[mtLi,2] then begin s[si,16]=-1; {mtL=largerRangeB} mtLi=mtLi+1; mtL[mtLi,0]=myBar[1]; mtL[mtLi,1]=myH[1]; mtL[mtLi,2]=myL[1]; mtL[mtLi,3]=myC[1]; end; if asc and s[si,1]<nullAscPrice then begin {nullAsc} asc=false; s[si,13]=-1; end; if mtDir<=0 and asc and c>=c[1] then begin {revBuyAsc found} rev=1; asc=false; s[si,8]=1; end; if s[si,2]>mtL[mtLi,1] then begin {asc found} asc=true; nullAscPrice=s[si,2]; s[si,6]=1; end; if p2t and s[si,1]<nullP2Tprice then begin p2t=false; s[si,14]=-1; {nullP2T} end; if mtDir<=0 and p2t and c>=c[1]then begin {revBuyP2T found} rev=1; p2t=false; s[si,9]=1; end; if s[si,3]<s[si-2,2] and s[si,3]<s[si-4,2] then begin {p2b found} p2b=true; nullP2Bprice=s[si-1,1]; s[si,7]=-1; end; if mtDir=mtDir[1] and asc and c>=c[1] then begin {repeatBuyAsc} repeat=1; asc=false; s[si,10]=1; end; if mtDir>0 and s[si,2]<s[si-2,1] and s[si,1]>s[si-2,2] and c>=c[1] then begin repeat=1; s[si,11]=1; {repeatBuyTOB 1st B back} end; if mtDir>0 and s[si,2]<s[si-4,1] and s[si,1]>s[si-4,2] and c>=c[1] then begin repeat=1; s[si,12]=1; {repeatBuyTOB 2nd B back} end; end else begin S[si,4]=myH[1]; s[si,5]=-1; {swing=T} if s[si,1]>mtH[mtHi,1] then begin s[si,15]=1; {mtH=higherTop} mtHi=mtHi+1; mtH[mtHi,0]=myBar[1]; mtH[mtHi,1]=myH[1]; mtH[mtHi,2]=myL[1]; mtH[mtHi,3]=myC[1]; end; if s[si,1]-s[si,2]>mtH[mtHi,1]-mtH[mtHi,2] then begin s[si,16]=1; {mtH=largerRangeTop} mtHi=mtHi+1; mtH[mtHi,0]=myBar[1]; mtH[mtHi,1]=myH[1]; mtH[mtHi,2]=myL[1]; mtH[mtHi,3]=myC[1]; end; if des and s[si,2]>nullDesPrice then begin des=false; s[si,13]=1;{nullDes} end; if mtDir>=0 and des and c<=c[1] then begin {revSellDes found} rev=-1; des=false; s[si,8]=-1; end; if s[si,1]<mtH[mtHi,2] then begin {des found} des=true; nullDesPrice=s[si,1]; s[si,6]=-1; end; if p2b and s[si,2]>nullP2Bprice then begin p2B=false; s[si,14]=1; {nullP2B} end; if mtDir>=0 and p2b and c<=c[1]then begin {revSellP2B found} rev=-1; p2b=false; s[si,9]=-1; end; if s[si,3]>s[si-2,1] and s[si,3]>s[si-4,1] then begin {p2t found} p2t=true; nullP2Tprice=s[si-1,2]; s[si,7]=1; end; if mtDir=mtDir[1] and des and c<=c[1] then begin {repeatSellDes} repeat= -1; des=false; s[si,10]=-1; end; if mtDir<0 and s[si,2]<s[si-2,1] and s[si,1]>s[si-2,2] and c<=c[1] then begin repeat= -1; s[si,11]=-1; {repeatSellTOT 1st T back} end; if mtDir<0 and s[si,2]<s[si-4,1] and s[si,1]>s[si-4,2] and c<=c[1] then begin repeat= -1; s[si,12]=-1; {repeatSellTOT 2nd T back} end; end; end;
if dir<0 and mtDir>0 and inside=false and L<L[1] and c>c[1] then begin repeat=1; BRi=BRi+1; BR[BRi,0]=currentBar; BR[BRi,1]=H; BR[BRi,2]=L; BR[BRi,3]=C; {repeatBuyBR} end; if dir>0 and mtDir<0 and inside=false and H>H[1] and c<c[1] then begin repeat= -1; TRi=TRi+1; TR=currentBar; TR=H; TR=L; TR=C; {repeatSellTR} end;
if mtDir>0 then begin {p1 doesn't use target} {error when target+stop hit same bar} if p[pi,3,2]>0 and p[pi,4,2]=0 and L>p[pi,3,2]+p[pi,6,2] then {p2 target hit} p[pi,4,2]=maxList(p[pi,3,2]+p[pi,6,2],open); {exit p2} end else begin if p[pi,3,2]>0 and p[pi,4,2]=0 and H<p[pi,3,2]-p[pi,6,2] then {p2 target hit} p[pi,4,2]=minList(p[pi,3,2]-p[pi,6,2],open); {exit p2} end;
{before revEntry resets mtDir} if mtDir>0 then begin {stop trails maxPaperProfitChandelier} {error when target+stop hit same bar} if p[pi,3,1]>0 and p[pi,4,1]=0 and L<=p[pi,7,1]-p[pi,6,1] then {p1 stop hit} p[pi,4,1]=minList(p[pi,7,1]-p[pi,6,1],open); {exit p1} if p[pi,3,2]>0 and p[pi,4,2]=0 and L<=p[pi,7,2]-p[pi,6,2] then {p2 stop hit} p[pi,4,2]=minList(p[pi,7,2]-p[pi,6,2],open); {exit p2} end else begin if p[pi,3,1]>0 and p[pi,4,1]=0 and H>=p[pi,7,1]+p[pi,6,1] then {p1 stop hit} p[pi,4,1]=maxList(p[pi,7,1]+p[pi,6,1],open); {exit p1} if p[pi,3,2]>0 and p[pi,4,2]=0 and H>=p[pi,7,2]+p[pi,6,2] then {p2 stop hit} p[pi,4,2]=maxList(p[pi,7,2]+p[pi,6,2],open); {exit p2} end;
if rev<>0 then begin {rev exit+entry} if p[pi,3,1]>0 and p[pi,4,1]=0 then p[pi,4,1]=c; {exit} if p[pi,3,2]>0 and p[pi,4,2]=0 then p[pi,4,2]=c; {exit} pi=pi+1; p[pi,0,1]=currentbar; p[pi,1,1]=H; p[pi,2,1]=L; p[pi,3,1]=C; {entry} p[pi,4,1]=0; p[pi,6,1]=squareRoot(c); if rev>0 then begin mtDir=1; s[si,17]=1; p[pi,5,1]=1; p[pi,7,1]=H; {reset mtDir+dir} mtHi=mtHi+1; mtH[mtHi,0]=currentBar; mtH[mtHi,1]=H; mtH[mtHi,2]=L; mtH[mtHi,3]=C; {mtH freshStart} end else begin mtDir=-1; s[si,17]=-1; p[pi,5,1]=-1; p[pi,7,1]=L; {reset mtDir+dir} mtLi=mtLi+1; mtL[mtLi,0]=currentBar; mtL[mtLi,1]=H; mtL[mtLi,2]=L; mtL[mtLi,3]=C; {mtL freshStart} end; rev=0; repeat=0; {reset rev+repeat} end; {p[pi,7,1]=C,H,L?}
if repeat>0 then begin {repeatEntry} if p[pi,4,1]>0 then begin {last p1 closed} p[pi,0,1]=currentBar; p[pi,1,1]=H; p[pi,2,1]=L; p[pi,3,1]=C; p[pi,4,1]=0; p[pi,5,1]=1; p[pi,6,1]=squareRoot(c); p[pi,7,1]=H;{or p[pi,7,1]=c;?} end else begin {p1 still open} if c>p[pi,3,1] and p[pi,4,2]>0 then begin {p1 profitable} {last p2 closed} p[pi,0,2]=currentBar; p[pi,1,2]=H; p[pi,2,2]=L; p[pi,3,2]=C; p[pi,4,2]=0; p[pi,5,2]=1; p[pi,6,2]=squareRoot(c); p[pi,7,2]=H;{or p[pi,7,2]=c;?} end; if c>p[pi,3,1] and p[pi,3,2]=0 then begin {p2 empty} p[pi,0,2]=currentBar; p[pi,1,2]=H; p[pi,2,2]=L; p[pi,3,2]=C; p[pi,4,2]=0; p[pi,5,2]=1; p[pi,6,2]=squareRoot(c); p[pi,7,2]=H;{or p[pi,7,2]=c;?} end; end; repeat=0; {resetRepeat} end; if repeat<0 then begin {repeatEntry} if p[pi,4,1]>0 then begin {last p1 closed} p[pi,0,1]=currentBar; p[pi,1,1]=H; p[pi,2,1]=L; p[pi,3,1]=C; p[pi,4,1]=0; p[pi,5,1]=-1; p[pi,6,1]=squareRoot(c); p[pi,7,1]=L;{or p[pi,7,1]=c;?} end else begin {p1 still open} if c<p[pi,3,1] and p[pi,4,2]>0 then begin {p1 profitable} {last p2 closed} p[pi,0,2]=currentBar; p[pi,1,2]=H; p[pi,2,2]=L; p[pi,3,2]=C; p[pi,4,2]=0; p[pi,5,2]=-1; p[pi,6,2]=squareRoot(c); p[pi,7,2]=L;{or p[pi,7,2]=c;?} end; if c<p[pi,3,1] and p[pi,3,2]=0 then begin {p2 empty} p[pi,0,2]=currentBar; p[pi,1,2]=H; p[pi,2,2]=L; p[pi,3,2]=C; p[pi,4,2]=0; p[pi,5,2]=-1; p[pi,6,2]=squareRoot(c); p[pi,7,2]=L;{or p[pi,7,2]=c;?} end; end; repeat=0; {resetRepeat} end;
if mtDir>0 then begin if p[pi,3,1]>0 and p[pi,4,1]=0 and c>p[pi,7,1] then p[pi,7,1]=c; {raise chandelier} if p[pi,3,2]>0 and p[pi,4,2]=0 and c>p[pi,7,2] then p[pi,7,2]=c; {raise chandelier} end else begin if p[pi,3,1]>0 and p[pi,4,1]=0 and c<p[pi,7,1] then p[pi,7,1]=c; {lower chandelier} if p[pi,3,2]>0 and p[pi,4,2]=0 and c<p[pi,7,2] then p[pi,7,2]=c; {lower chandelier} end; {H,L instead of C moves chandelier?} {repeat+rev entry use p[pi,7,n]=H or L;?}
for offset=currentbar-S[Si,0] downto 0 begin if dir<0 then setPlotColor[offset](1,red); if dir>0 then setPlotColor[offset](1,darkgreen); end; plot1[currentbar-S[Si,0]](S[Si,4]); {if s[si,5]<0 then plotPaintBar[currentbar-s[si,0]](s[si,1],s[si,2]);} {paintBar all B's}
{---------------NOTES------------------ swing array index: 0= myBar 1= H 2= L 3= C 4= swing price {myL or myH} 5= 1 if B, -1 if T 6= 1 if asc, -1 if des 7= 1 if p2t found, -1 if p2b found 8= 1 if revBuyAsc, -1 if revSellDes 9= 1 if revBuyP2T, -1 if revSellP2B 10=1 if repeatBuyAsc, -1 if repeatSellDes 11=1 if repeatBuyTOB, -1 if repeatSellTOT {back[1]} 12=1 if repeatBuyTOB, -1 if repeatSellTOT {back[2] but not both[1]+[2]} 13=1 if nullDes, -1 if nullAsc 14=1 if nullP2B, -1 if nullP2T 15=1 if mtH higherTop, -1 if mtL lower B 16=1 if mtH largerRangeH, -1 if mtL largerRangeB {16 isn't red green logic} 17=1 if mtDir=1, and -1 if mtDir=-1
p array index: p1 = LT pos p2 = ST pos 0=barNumber 1=H 2=L 3=C 4=exitPrice {entry resets it to zero} 5= 1 if long, -1 if short. 6= target+stop factor {squareRoot p[pi,3,n];} 7= chandelier, max c since entry if long (5=1), min c since entry if short (5=-1)
for n=0 to 4 begin {fill array} p2B[p2Bi,n]=B[bi,n]; end;
for n=1 to 4 begin {fill 3d array} if mtDir>0 then begin if p[pi,3,n]>0 and p[pi,4,n]<0 and c>p[pi,7,n] then p[pi,7,n]=c; end else begin if p[pi,3,n]>0 and p[pi,4,n]<0 and c<p[pi,7,n] then p[pi,7,n]=c; end; end; {H>p[pi,7,n] then p[pi,7,n]=H;?}
TOB+TOT hybrid sweetspot = extreme % of range. Low risk, high reward, high probability variant. Histogram of combined range of 2 or 3b's. Percent of range plot. Sweetspot=50% of range if b's overlap, otherwise sweetspot=50% of lowest B. Histogram of range from H to L of highest B to lowest B of last 2b's? Range B[1] + range B[2]=? It's < otherRange since these 2bars form inside edges of profit zone within range. Subtract from swing range when used as stops? TOT+TOB don't subtract but I want a bar stop. Histogram T+B and B+B and T+T combos.
stop 1 times factor away from chandelier without regard for max percentage gain. Dunnigan adapts factor based on max paper profit as percent of entry price.
Goal 1. matrix of all swing classes. 2. paintbar or showme all swing classes. 3. line plot target+stop} |