Good Evening Maurizio,
I hope you can check my formulas out on the Swing Trading Indicator, I have taken your system test and made a Expert Advisor, Exploratio, and Indicator to complet the whole system.
Here are the formulas:
The trading rules are as follows:
1. A signal is valid if H>Mov(C,20,E) for longs and L<Mov(C,20,E) for shorts.
2. With a valid signal, place a stop order above/below the signal bar high/low with validity 2 days.
3. If entered a position, exists based on 3 rules: a) Initial stop loss of 12% from entry level, b) A sell signal (no validity rules applicable) and a low below the signal bar low (for longs; no 2 day time limit) and c) price below/above a fractal of level 1, i.e.
upF:=H<Ref(H,-1) AND Ref(H,-1)>Ref(H,-2); downF:=L>Ref(L,-1) AND Ref(L,-1)<Ref(L,-2); F1:=ValueWhen(1,upF,Ref(H,-1)); F2:=ValueWhen(1,downF,Ref(L,-1)).
Short side for System Tester, I have reproduced the close long code because in the meantime I have replaced the fractal of 1st order with the “3 day ringed high/low.
EXPERT ADVISOR
Trends:
Bullish:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
Bearish:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
EXPLORATION
Col A:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
Col B:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
Col C: Fml("s b")=1 AND Ref(Fml("s b"),-1)=0
Col D: Fml("s ss")=1 AND Ref(Fml("s ss"),-1)=0
Filter colA OR colB
Filter enabled Yes
Periodicity Daily
Records required 1000
INDICATOR
s b {swing buy}
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
s s {swing sell}
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
Expert Commentary
Highlights:
Buy Signal Color Green
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
bc AND Ref (BarsSince(bc)>BarsSince(sc),-1)
Sell Signal Color Red
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
sc AND Ref(BarsSince(bc)<BarsSince(sc),-1)
Expert Commentary
Symbols:
Buy Signal
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
bc AND Ref (BarsSince(bc)>BarsSince(sc),-1)
Sell Signal
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
sc AND Ref(BarsSince(bc)<BarsSince(sc),-1)
System Test:
buy order:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
setup:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1))) and H>Mov(C,20,E) ;
H>(Valuewhen(1,setup,H)+0.1) and BarsSince(setup)<=2;
order type - stop:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
upF:=H<Ref(H,-1) AND Ref(H,-1)>Ref(H,-2);
downF:=L>Ref(L,-1) AND Ref(L,-1)<Ref(L,-2);
F1:=ValueWhen(1,upF,Ref(H,-1));
F2:=ValueWhen(1,downF,Ref(L,-1));
setup:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L)) ;
If(ref(setup,-1),O,min(O,F2))
sell order
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedLow:=L>Ref(L,-3) AND Ref(L,-1)>Ref(L,-3) and Ref(L,-2)>Ref(L,-3) and Ref(L,-3)<Ref(L,-4);
isolatedlow:=ValueWhen(1,3DringedLow,Ref(L,-3));
L<isolatedlow OR (L<valuewhen(1,sc,L) and BarsSince(bc)>BarsSince(sc));
Stop price:
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H,Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedLow:=L>Ref(L,-3) AND Ref(L,-1)>Ref(L,-3) and Ref(L,-2)>Ref(L,-3) and Ref(L,-3)<Ref(L,-4);
isolatedlow:=ValueWhen(1,3DringedLow,Ref(L,-3));
if(L<L<isolatedlow,min(O,isolatedlow),min(O,valuewhen(1,sc,L)))
Sell Short
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
Alert(sc,2) AND L<ValueWhen(1,sc,L) AND ValueWhen(1,sc,L)>Mov(C,20,E);
Stop order
lb:=TroughBars(1,L,.1);hb:=PeakBars(1,H,.1); plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
min(O,ValueWhen(1,sc,L))
Buy to cover
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
H>isolatedHigh OR (H>valuewhen(1,bc,H) and BarsSince(bc)<BarsSince(sc));
Stop order
lb:=TroughBars(1,L,.1);
hb:=PeakBars(1,H,.1);
plot:=Zig(If(lb<hb, L, H ),1,%);
new:=PeakBars(1,plot,1)=0 OR TroughBars(1,plot,1)=0;
bc:=If(new,Cross(H, Peak(2,plot,1)),Cross(H, Peak(1,plot,1)));
sc:=If(new,Cross(Trough(2,plot,1),L),Cross(Trough(1,plot,1),L));
3DringedHigh:=H<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND Ref(H,-2)<Ref(H,-3) and Ref(H,-3)>Ref(H,-4);
isolatedHigh:=ValueWhen(1,3DringedHigh,Ref(H,-3));
If(H>isolatedHigh,max(O,isolatedHigh),max(O,valuewhen(1,bc,H)))
Maurizio, It looks to me that the 12% STOP LOSS is not there?
Please advise any changes and if the above formulas are correct.
Once again thank you very much for your support and advice.
Nasdaqtrader
Frank