PDA

View Full Version : shrinking trailing stops


arpad_37
11th July 2006, 04:17 AM
Hi, I am trying to implement an R based shrinking trailing stop loss rule as per the code below. It essenmtially works that you set a large initial stop but once the trade starts to be profitable - defined by the high R value, you shrink the trailing stop.
This seems to work with others' tradesim but not with mine(??). I do not understand how that is possible.
Can someone help please?

Regards,
Arpad

Period1:=50;
Period2:=20;
Period3:=50;
Period4:=20;

EntryTrigger:= Ref(Cross(CLOSE, Ref(HHV(CLOSE,Period1),-1)),-1);
EntryPrice:= OPEN;
InitialStop:=LLV(CLOSE,Period2);

a:=(C-EntryPrice)/(EntryPrice-InitialStop);

ExitTrigger:=
If(a>3,C<Ref(LLV(C,5),-1),If(a>2 AND a<=3,C<Ref(LLV(C,10),-1),If(a>1 AND a<=2,C<Ref(LLV(C,20),-1),C<Ref(LLV(C,30),-1))));

ExitPrice:=OPEN;

ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.RecordTrades",
"FOREX_shrinking_exit_long",
LONG,
EntryTrigger,
EntryPrice,
InitialStop,
ExitTrigger,
ExitPrice,
START);

Jose
12th July 2006, 01:06 AM
Your best option is to plot your code as an indicator below a MetaStock chart, and see what works/doesn't, and what you can do to make it work for you.


Period1&#58;=50;
Period2&#58;=20;
Period3&#58;=50;
Period4&#58;=20;

EntryTrigger&#58;=
Ref&#40;Cross&#40;C,Ref&#40;HHV&#40;C,Period1&#41;,-1&#41;&#41;,-1&#41;;
EntryPrice&#58;=OPEN;
InitialStop&#58;=LLV&#40;C,Period2&#41;;

a&#58;=&#40;C-EntryPrice&#41;/Max&#40;EntryPrice-InitialStop,.00001&#41;;

ExitTrigger&#58;=
If&#40;a>3,C<Ref&#40;LLV&#40;C,5&#41;,-1&#41;,
If&#40;a>2 AND a<=3,C<Ref&#40;LLV&#40;C,10&#41;,-1&#41;,
If&#40;a>1 AND a<=2,C<Ref&#40;LLV&#40;C,20&#41;,-1&#41;,
C<Ref&#40;LLV&#40;C,30&#41;,-1&#41;&#41;&#41;&#41;;

EntryTrigger-ExitTrigger




jose '-)