Test Move After Signal
input Nx1 = 5;
input N = 5;
def h = high;
def l = low;
def c = close;
def o = open;
def bn = barnumber();
def nan = double.nan;
def BodyMax = Max(o, c);
def BodyMin = Min(o, c);
def BodyMid = AbsValue(o + c ) / 2;
def TR = TrueRange(h, c, l);
def hxTR = highest(TR, n);
def lxTR = lowest(TR, n);
def r = (TR-lxTR)/(hxTR-lxTR);
def xHH =h == GetValue(h, GetMaxValueOffset(h, Nx1), Nx1);
def sHm =if(xHH,BodyMid,sHm[1]);
def xLL = l == GetValue(l, GetMinValueOffset(l, Nx1), Nx1);
def slm =if(xll,BodyMid,slm[1]);
def trChannel = if l>l[1]&& h>h[1] then 100 else if l<l[1]&& h<h[1] then -100 else 0;
DEF trChcnt = if trChannel!=trChannel[1] then 1 else trChcnt[1]+1;
def trDelta = if c>C[1] then 100 else if c<c[1] then -100 else 0;
DEF trDcnt = if trDelta!=trDelta[1] then 1 else TrDcnt[1]+1;
def trMd= if BodyMid>BodyMid[1] then 100 else if BodyMid<BodyMid[1] then -100 else 0;
DEF trMcnt = if trMd!=trMd[1] then 1 else trMd[1]+1;
def TrASC3 = if IsAscending(l, 3) && IsAscending(h, 3) then 100 else 0;
def TrASC4 = if IsAscending(l, 4) && IsAscending(h, 4) then 100 else 0;
def TrASC5 = if IsAscending(l, 5) && IsAscending(h, 5) then 100 else 0;
def TrASC6 = if IsAscending(l, 6) && IsAscending(h, 6) then 100 else 0;
def TrASC7 = if IsAscending(l, 7) && IsAscending(h, 7) then 100 else 0;
def TrASC8 = if IsAscending(l, 8) && IsAscending(h, 8) then 100 else 0;
def trASCALL = TrASC3 + TrASC4 + TrASC5 + TrASC6 + TrASC7 + TrASC8;
def isTrAscall_ = if(trASCALL>=500,1,0);
def isTrAscall1_ = if(trASCALL>=600,1,0);
def isTrAscall2_ = if(trASCALL<500,1,0);
def TrDSC3 = if IsDescending(l, 3) && IsDescending(h, 3) then 100 else 0;
def TrDSC4 = if IsDescending(l, 4) && IsDescending(h, 4) then 100 else 0;
def TrDSC5 = if IsDescending(l, 5) && IsDescending(h, 5) then 100 else 0;
def TrDSC6 = if IsDescending(l, 6) && IsDescending(h, 6) then 100 else 0;
def TrDSC7 = if IsDescending(l, 7) && IsDescending(h, 7) then 100 else 0;
def TrDSC8 = if IsDescending(l, 8) && IsDescending(h, 8) then 100 else 0;
def trdscALL = TrDSC3 + TrDSC4 + TrDSC5 + TrDSC6 + TrDSC7 + TrDSC8;
def istrdscALL_ = if(trdscALL>=500,1,0);
def istrdscALL1_ = if(trdscALL>=600,1,0);
def istrdscALL2_ = if(trdscALL<500,1,0);
def cAsc3 = if IsAscending(c, 2) then 100 else 0;
def cAsc4 = if IsAscending(c, 4) then 100 else 0;
def cAsc5 = if IsAscending(c, 5) then 100 else 0;
def cAsc6 = if IsAscending(c, 6) then 100 else 0;
def cAsc7 = if IsAscending(c, 7) then 100 else 0;
def cAsc8 = if IsAscending(c, 8) then 100 else 0;
def cAscALL = cAsc3 + cAsc4 + cAsc5 + cAsc6 + cAsc7 + cAsc8;
def cAscALL_ =if(cAscALL>=600,1,0 );
def cDsc3 = if IsDescending(c, 2) then 100 else 0;
def cDsc4 = if IsDescending(c, 4) then 100 else 0;
def cDsc5 = if IsDescending(c, 5) then 100 else 0;
def cDsc6 = if IsDescending(c, 6) then 100 else 0;
def cDsc7 = if IsDescending(c, 7) then 100 else 0;
def cDsc8 = if IsDescending(c, 8) then 100 else 0;
def cDscALL = cDsc3 + cDsc4 + cDsc5 + cDsc6 + cDsc7 + cDsc8;
def cDscALL_ =if(cDscALL>=600,1,0 );
def Trstate3 = if IsAscending(l, 3) && IsAscending(h, 3) then 100 else if IsDescending(l, 3) && IsDescending(h, 3) then -100 else Trstate3[1];
def Trstate4 = if IsAscending(l, 4) && IsAscending(h, 4) then 100 else if IsDescending(l, 4) && IsDescending(h, 4) then -100 else Trstate4[1];
def Trstate5 = if IsAscending(l, 5) && IsAscending(h, 5) then 100 else if IsDescending(l, 5) && IsDescending(h, 5) then -100 else Trstate5[1];
def Trstate6 = if IsAscending(l, 6) && IsAscending(h, 6) then 100 else if IsDescending(l, 6) && IsDescending(h, 6) then -100 else Trstate6[1];
def Trstate7 = if IsAscending(l, 7) && IsAscending(h, 7) then 100 else if IsDescending(l, 7) && IsDescending(h, 7) then -100 else Trstate7[1];
def Trstate8 = if IsAscending(l, 8) && IsAscending(h, 8) then 100 else if IsDescending(l, 8) && IsDescending(h, 8) then -100 else Trstate8[1];
Def AllState = if Trstate3==100 && Trstate4==100 && Trstate5==100 && Trstate6==100 && Trstate7==100 then 100
else if Trstate3==-100 && Trstate4==-100 && Trstate5==-100 && Trstate6==-100 && Trstate7==-100 then -100
else allstate[1];
# Trend Ehlers based GA
input period = 10;
def beta = (1 - Cos(2 * Double.Pi / (period))) / (Power(2, 1.0 / 4) - 1);
def alpha = (-beta + Sqrt(Power(beta, 2) + 2 * beta));
def filt = Power(alpha, 4) * c + 4 * (1 - alpha) * filt[1] - 6 * Power(1 - alpha, 2) * filt[2] + 4 * Power(1 - alpha, 3) * filt[3] - Power(1 - alpha, 4) * filt[4];
def isfilt = filt;
def tickS = if !IsNaN(TickSize()) then TickSize() else .01;
def Pricescale = if no then isfilt * tickS / tickS else isfilt;
input nx = 5;
def mx = fold mi = 0 to nx
with s
do s + GetValue(Sum(Pricescale[1] / (Pricescale[3] / Pricescale[2]), nx) / nx, mi) / nx;
def statex;
if (Crosses(Pricescale, mx , CrossingDirection.ABOVE)) {
statex = 100;
} else if (Crosses(Pricescale, mx , CrossingDirection.BELOW)) {
statex = -100;
} else {
statex = statex[1];
}
def GrPvState = if AllState == statex && statex == 100 then 100 else if AllState == statex && statex == -100 then -100 else GrPvState[1];
def htr = If(GrPvState == -100 && GrPvState [1] == 100, 1, 0);
def ltr = If(GrPvState == 100 && GrPvState [1] == -100, 1, 0);
def lowv = If(htr , low, If(low < lowv[1], low, lowv[1]));
def lwbn = if htr or lowv != lowv[1] then bn else lwbn[1];
def highv = If (ltr, high, If(high > highv[1], high, highv[1]));
def hwbn = if ltr or highv != highv[1] then bn else hwbn[1];
def PLow = If( bn == lwbn, 1, Double.NaN);
def Phigh = If(bn == hwbn , 1, Double.NaN);
def phlstate = if !isnan(Phigh) then 100 else if !isnan(PLow) then -100 else 0;
def hlstate = if xhh then 100 else if xll then -100 else 0;
def hlscnt = if hlstate==hlstate[1] then hlscnt[1]+1 else 0;
#def (hlstate==100 or phlstate==100)
#def (hlstate==-100 or phlstate==-100)
def cBullish;
def cBearish;
if (trChcnt[1]>=3 && (trChannel==0 or trChannel==100) && trChannel[1]==-100 && ((hlstate==100 or phlstate==100) or BodyMid<slm[1]) && R>=.50){
cBullish = 100;
cBearish = 0;
} else if (trChcnt[1]>=3 && (trChannel==0 or trChannel==-100) && trChannel[1]==100 && ((hlstate==-100 or phlstate==-100) or BodyMid>shm[1]))&& R>=.50{
cBullish = 0;
cBearish = -100;
##
} else if (trDcnt[1]>=3 && trDelta==100 && trDelta[1]==-100 && ((hlstate==100 or phlstate==100) or BodyMid<slm[1])&& R>=.50){
cBullish = 200;
cBearish = 0;
} else if (trDcnt[1]>=3&& trDelta==-100 && trDelta[1]==100 && ((hlstate==-100 or phlstate==-100) or BodyMid>shm[1])&& R>=.50){
cBullish = 0;
cBearish = -200;
##
} else if (trMcnt[1]>=2 && (trMd==0 or trMd==100) && trMd[1]==-100 && ((hlstate==-100 or phlstate==-100) or BodyMid<slm[1])&& R>=.50){
cBullish = 300;
cBearish = 0;
} else if (trMcnt[1]>=2 && (trMd==0 or trMd==-100) && trMd[1]==100 && ((hlstate==-100 or phlstate==-100) or BodyMid>shm[1])&& R>=.50){
cBullish = 0;
cBearish = -300;
} else if (istrdscALL2_&& istrdscALL_[1] && (xLL[1] or xLL or BodyMid<slm[1])){
cBullish = 400;
cBearish = 0;
} else if (isTrAscall2_ && isTrAscall_[1] && (xhh or xHH[1] or (hlstate==-100 or phlstate==-100) or BodyMid>shm[1])&& R>=.50){
cBullish = 0;
cBearish = -400;
} else if (!hlstate&& hlstate[1]==100 && hlscnt [1]>=2 && GrPvState==100 && (hlstate==100 or phlstate==-100) && R>=.50){
cBullish = 500;
cBearish = 0;
} else if (!hlstate&& hlstate[1]==-100 && hlscnt[1]>=2 && GrPvState==-100 && (hlstate==-100 or phlstate==-100)&& R>=.50 ){
cBullish = 0;
cBearish = -500;
#} else if (!hlstate && hlstate[1]==100 && !phlstate && phlstate[1]==100 or (hlstate==100 or phlstate==100) ){
#cBullish = 600;
#cBearish = 0;
#} else if (!hlstate && hlstate[1]==-100 && !phlstate && phlstate[1]==-100 or (hlstate==-100 or phlstate==-100) ){
#cBullish = 0;
#cBearish = -600;
} else{
cBullish =0;
cBearish =0;
}
plot cBullish1 = if cBullish && !cbullish[1] then low else double.nan;
plot cBearish1= if cBearish && !cBearish[1]then low else double.nan;;
cBullish1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
cBullish1.SetDefaultColor(Color.GREEN);
cBullish1.SetLineWeight(3);
cBearish1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
cBearish1.SetDefaultColor(Color.RED);
cBearish1.SetLineWeight(3);
def id =
if cBullish1==100 then 100
else if cBearish1==-100 then -100
else if cBullish1==200 then 200
else if cBearish1==-200 then -200
else if cBullish1==300 then 300
else if cBearish1==-300 then -300
else if cBullish1==400 then 400
else if cBearish1==-400 then -400
else 0;
AddChartBubble(1 && (cBullish1 or cBearish1), if cBullish then l else h, if cBullish then cBullish else cbearish, Color.WHITE);
# ─────────────────────────────────────────────
# │ MarketFragments.com | DNA & Market │
# │ info@marketfragments.com │
# │ www.marketfragments.com │
# ──────────────────────────────────────────────
# Time →
# │
# █ █ █│ █
# █ █ █ │ █ █
# █ █ █ │ █ █ █ ╭─╮
# █ █ █ │ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ ╰─────╯
# ──────┴──────────────────────────────────────────────────────────────
# T1 T2 T3 T4 T5 T6
#
# Test Move % after signal
script pTest {
input Signal = close;
input Length = 5; # how to test after signal
input type = yes; # for bear moves selecet "no"
def h = high;
def l = low;
def bn = BarNumber();
def Sig;
def sigbn;
def sbn;
def isSignal;
if (!isSignal[1] && bn > 1 && !IsNaN(Signal) && IsNaN(Signal[1])) {
Sig = 1;
sigbn = If(Sig && !Sig[1], bn, sigbn[1]);
sbn = If(bn == sigbn, bn, 0);
isSignal = if bn == 1 then 0 else
if sbn && !isSignal[1] then 1 else
if bn >= (sigbn + Length) && isSignal[1] then 0 else isSignal[1];
} else {
Sig = 0;
sigbn = If(Sig && !Sig[1], bn, sigbn[1]);
sbn = If(bn == sigbn, bn, 0);
isSignal = if bn == 1 then 0 else
if sbn && !isSignal[1] then 1 else
if bn >= (sigbn + Length) && isSignal[1] then 0 else isSignal[1];
}
def start = If(isSignal && !isSignal[1], 1, 0);
def end = If(!isSignal && isSignal[1], 1, 0);
def sigSum = If(!isSignal && isSignal[1], sigSum[1] + 1, sigSum[1]);
def stV = if isSignal && !isSignal[1] then close else stV[1];
def xh = if start[1] then h else if h > xh[1] then h else xh[1];
def xl = if start[1] then l else if l < xl[1] then l else xl[1];
def sH = if end then If(type, xh - stV, xh - stV) else sH[1];
def sl = if end then If(type, stV - xl, stV - xl) else sl[1];
def hSum = CompoundValue(1, if bn == 1 then 0 else if end then hSum[1] + sH else hSum[1], 0);
def LSum = CompoundValue(1, if bn == 1 then 0 else if end then LSum[1] + sl else LSum[1], 0);
def hr =hSum / sigSum;
def lr = LSum / sigSum;
def hlrsum = hr+lr;
def id = if type then hr else lr ;
plot dif = if type then hr/(hr+lr) else lr/(hr+lr) ;
}
Input Showtest = yes;
Input tlength1 = 5; # how to test after signal
Input tlength2 = 10; # how to test after signal
Input tlength3 =20; # how to test after signal
Input type = yes; # for bear moves selecet "yes"
def isbuy = cBullish1;
def issell =cBearish1;
#### length 1
# Bull
def busum1 = pTest(isbuy, tlength1,type).sigSum;
def budiff1 = pTest( isbuy, tlength1,type);
def buUp1 = pTest(isbuy, tlength1,type).id;
def buDn1 = pTest(isbuy, tlength1,!type).id;
# BEar
def besum1 = pTest( issell,tlength1,!type).sigsum;
def bediff1 = pTest( issell,tlength1,!type);
def beUp1 = pTest( issell,tlength1,type).id;
def beDn1 = pTest( issell,tlength1,!type).id;
#### length 2
# Bull
def busum2 = pTest(isbuy, tlength2,type).sigsum;
def budiff2 = pTest(isbuy, tlength2,type);
def buUp2 = pTest(isbuy, tlength2,type).id;
def buDn2 = pTest(isbuy, tlength2,!type).id;
# bear
def besum2 = pTest(issell,tlength2,!type).sigsum;
def bediff2 = pTest(issell,tlength2,!type);
def beUp2 = pTest(issell,tlength2,type).id;
def beDn2 = pTest(issell,tlength2,!type).id;
#### length 3
# Bull
def busum3 = pTest(isbuy, tlength3,type).sigsum;
def budiff3 = pTest(isbuy, tlength3,type);
def buUp3 = pTest(isbuy, tlength3,type).id;
def buDn3 = pTest(isbuy, tlength3,!type).id;
# bear
def besum3 = pTest(issell,tlength3,!type).sigsum;
def bediff3= pTest(issell,tlength3,!type);
def beUp3= pTest(issell,tlength3,type).id;
def beDn3 = pTest(issell,tlength3,!type).id;
addlabel( Showtest,"Bull_Future Bars (" + tlength1+ ") Signals ("+busum1 + ") AvHigh : " +buUp1+ " AvLow : " + buDn1 + " / : " + aspercent( budiff1),
if budiff1>=.50 then color.green else color.white);
addlabel( Showtest,"Bull_Future Bars (" + tlength2+ ") Signals ("+busum2 + ") AvHigh : " +buUp2+ " AvLow : " + buDn2 + " / : " + aspercent( budiff2),
if budiff2>=.50 then color.green else color.white);
addlabel( Showtest,"Bull_Future Bars (" + tlength3+ ") Signals ("+busum3 + ") AvHigh : " +buUp3+ " AvLow : " + buDn3 + " / : " + aspercent( budiff3),
if budiff3>=.50 then color.green else color.white);
addlabel( Showtest,"Bear_Future Bars (" + tlength1+ ") Signals ("+besum1 + ") AvHigh : " +beUp1+ " AvLow : " + beDn1 + " / : " + aspercent( bediff1),
if bediff1>=.50 then color.green else color.white);
addlabel( Showtest,"Bear_Future Bars (" + tlength2+ ") Signals ("+besum2 + ") AvHigh : " +beUp2+ " AvLow : " + beDn2 + " / : " + aspercent( bediff2),
if bediff2>=.50 then color.green else color.white);
addlabel( Showtest,"Bear_Future Bars (" + tlength3+ ") Signals ("+besum3 + ") AvHigh : " +beUp3+ " AvLow : " + beDn3 + " / : " + aspercent( bediff3),
if bediff3>=.50 then color.green else color.white);

