PDA

View Full Version : Trailing stop not working properly


kozerog
4th August 2006, 02:10 AM
Please help

Hi, I have the following code and my trailing stops are not being executed properly.

It seems that the reference for the trailing stops, (which is based on close)
is taken even prior to the EntryTrig (which I don't want to happen)

I want the trailing stop to be computed after the last trade is exited and the new trade is entered.

Please take a look


F2:=ValueWhen(1,L>Ref(L,-2) AND Ref(L,-1)>Ref(L,-2) AND Ref(L,-3)>Ref(L,-2) AND Ref(L,-4)>Ref(L,-2),Ref(L,-2));


EntryTrig:=Cross(F2,L) AND H>f2; {no gaps}
EntryPrice:=C;

Stop:=ExtFml("tradesim.trailingstop",
band,
short,
c*0.1 {10% trailing stop},
C,
H);

stop1:=Ref(stop, -1); {prev stop applies today}
stop2:=Cross(H, stop1); {trigger}

InitialStops:= entryprice*1.1;
ExitPrice:=If(stop2, If(O>stop1, O, stop1), If(O>initialstops, O, initialstops));

ExtFml("Tradesim.initialize");
ExtFml("Tradesim.setstartrecorddate",1,1,1995);
ExtFml("Tradesim.setstoprecorddate",1,3,2000);
ExtFml("tradesim.enableprotectivestop",1);
ExtFml("TradeSim.SetExitTriggerDelay",1);


ExtFml( "TradeSim.RecordTrades",
"01_FRACTAL",
short,
EntryTrig,
EntryPrice,
InitialStops,
stop2,
Exitprice,
START);

Jose
5th August 2006, 04:38 AM
A few potential problems with that code:

1) Trailing stop is in Short mode - perhaps it should be Long;

2) Trailing stop is not being triggered by entry signals - try something like this:


F2:=ValueWhen(1,
L>Ref(L,-2)
AND Ref(L,-1)>Ref(L,-2)
AND Ref(L,-3)>Ref(L,-2)
AND Ref(L,-4)>Ref(L,-2),
Ref(L,-2));

EntryTrig:=Cross(F2,L) AND H>f2;

StopLong:=ExtFml("AdvancedStop.StopLong",
EntryTrig,C*.9,0,C*.9,0,0,0,0)

Adv Stop dll available from:
http://www.tradernexus.com/advancedstop/advancedstop.html


3) Always plot components of your signals as indicators on/below a chart - so that they can be visually verified prior to running the exploration. Doing it the blind way (Exploration code only) usually hides unseen code problems.


jose '-)