View Full Version : Trailing Stop Formula
Michael
18th June 2003, 03:08 AM
Could you please give me some guidance with a Trailing Stop formula? I find that the manual doesn't make it clear enough (for me), and I get too many error messages when trying to apply it.
I have a working system with a different type of stop, and have no problem with that. Now I am looking for specifically a 1.5*ATR(10) stop, using the Low for a Long stop and the High for a Short stop.
David Samborsky
18th June 2003, 12:44 PM
Hello Michael
Could you please post your formula so we can scrutinize it and provide some feedback.
Michael
19th June 2003, 02:49 AM
Here's what I've come up with so far:
(Entry Trigger, etc)
LongEntryPrice:=OPEN;
ExtFml( "TradeSim.TrailingStop",
Trigger,
Long,
1.5*ATR(10),
High,
Low);
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",1,1,1995);
ExtFml("TradeSim.EnableDelayOfEntryByOneBar");
ExtFml("TradeSim.RecordTrades","xxx",Long,
LongEntryTrigger,
LongEntryPrice,
DON'T KNOW HOW TO WRITE LONG EXIT,
START);
Michael
David Samborsky
19th June 2003, 03:10 AM
The first problem is you need to assign something to your entry trigger and exit price. See the following example.
Period:=10;
ARC:=1.5;
Volatility:=ARC*ATR(Period);
InitialStop:=0; { leave zero if not used }
LongEntryTrigger=??
LongEntryPrice=Open;
LongExitPrice=??;
LongExitTrigger:=ExtFml( "TradeSim.TrailingStop",
TRIGGER,
LONG,
Volatility,
CLOSE,
LOW);
ExtFml( "TradeSim.Initialize"); { Initialize internal variables }
ExtFml("TradeSim.SetStartRecordDate",1,1,1995);
ExtFml("TradeSim.EnableDelayOfEntryByOneBar");
ExtFml( "TradeSim.RecordTrades",
"your file name",
LONG,
LongEntryTrigger,
LongEntryPrice,
InitialStop,
LongExitTrigger,
LongExitPrice,
START);
Michael
19th June 2003, 05:13 AM
This is a big help, thank you David. There's just one bit remaining, and that is the LongExitPrice. I want it to Exit as it crosses the Trailing Stop - that is $0.01 below the Long Trailing Stop. Would you use a Cross formula here, and if so how do you represent the Trailing Stop Value? Also if the Open is Less ie has gapped overnight, then Exit on Open.
This is the formula I've been using for a Cross of the Lowest Value of 5 days, which presumably could be suitably modified?
LongExitPrice:=If(O<Ref(LLV(L,5),-1),O,Ref(LLV(L,5),-1));
David Samborsky
20th June 2003, 01:55 AM
You could add the following.
LongExitPrice:=ExtFml( "TradeSim.TrailingStop",
BAND,
LONG,
Volatility,
CLOSE,
LOW);
However becareful that your exit price does not fall outside the high low price range of the day of exit otherwise the trade will be rejected. May need to add some extra conditioning to the exit price.
Michael
22nd June 2003, 08:00 AM
I'm still not succeeding with this. I've combined the above into the following and get the message "No valid trading records in database".
Any more assistance that you are able to provide would be much appreciated.
(LongEntryTrigger) specified
Period:=10;
ARC:=1.5;
Volatility:=ARC*ATR(Period);
InitialStop:=0;
LongEntryPrice:=OPEN;
LongExitTrigger:=-ExtFml( "TradeSim.TrailingStop",
TRIGGER,
LONG,
Volatility,
CLOSE,
LOW);
LongExitPrice:=ExtFml( "TradeSim.TrailingStop",
BAND,
LONG,
Volatility,
CLOSE,
LOW);
ExtFml( "TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",1,1,1995);
ExtFml("TradeSim.EnableDelayOfEntryByOneBar");
ExtFml( "TradeSim.RecordTrades",
"name",
LONG,
LongEntryTrigger,
LongEntryPrice,
InitialStop,
LongExitTrigger,
LongExitPrice,
START);
krishnan
23rd June 2003, 12:54 AM
Hi Michael,
an example given. Change it to your need and try.
Regards
Krishnan
EntryPrice :=O;
EntryTrigger:=(YOUR CHOICE);
Volatility:=2*ATR(14);
ExitTrigger:=ExtFml( "TradeSim.TrailingStop",
TRIGGER,
LONG,
Volatility,
HIGH,
LOW);
ExitPrice := C;
InitialStop :=O-2*ATR(14);
NewEntryPrice :=O;
NewEntryTrigger :=Ref(EntryTrigger,-1) and(other codition);
ExtFml( "TradeSim.Initialize"); { Initialize internal variables }
ExtFml( "TradeSim.EnableProtectiveStop",0);
ExtFml( "TradeSim.RecordTrades",
"TRAILING STOP ExtFml ", { Trade Data Filename }
LONG, { Trade Position Type }
NewEntryTrigger, { Entry Trigger }
NewEntryPrice, { Entry Price }
InitialStop, { Initial Stop }
ExitTrigger, { Exit Trigger }
ExitPrice, { Exit Price }
START); { Trade Recorder Control }
David Samborsky
23rd June 2003, 01:32 AM
Hello Michael
In your expression for LongExitTrigger delete the minus sign in from of the call to the ExtFml.
CanAm
4th August 2003, 02:10 AM
Hi David
Won't the formulae
LongExitTrigger:=-ExtFml( "TradeSim.TrailingStop",
TRIGGER,
LONG,
Volatility,
CLOSE,
LOW);
Set teh trailing stop 2*ATR(14) below the close rather than the high which I think is what he was trying to acheive?
I think he was trying to get it to exit if the day traded < the CLose(his stop value) rather than <= close. My understanding is that this is not possible?
Cheers
Seth
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.