View Full Version : ATR based Profit Stop
dilmun99
15th November 2004, 01:17 AM
Hi guys. I've been wanting to test various profit stops. The SetProfitStop function in TS only takes a constant entry (e.g. 5, for 5%). I want to model ATR based profit stops. I've been trying to use LastValue to change a variable entry into a constant, as in
ProfTgt:=LastValue(5*100*(ATR(20)/Mov(C,20,S)));
..........
ExtFml("TradeSim.SetProfitStop",ProfTgt);
This doesn't seem to work - when I look at the trades, every profitable entry is a Profit Stop, and the results barely change if I change the ATR multiple. I'm not sure whether this is an occasion when ValueWhen doesn't work, or whether you just can't do this in TS.
Any ideas?
Thanks
Andrew
Jose
15th November 2004, 03:05 AM
If by "profit stop" you mean a profit target, then it is basically an EntryPrice+Profit reference. It's best to use the Valuewhen() function for this purpose.
Here is an example:
{ System signals }
In:=Fml("001 system buy signals");
Out:=Fml("002 system sell signals");
{ User inputs }
multi:=Input("ATR multiplier",0,10,2);
pds:=Input("ATR periods",1,252,10);
delay:=Input("Entry and Exit delay",0,5,0);
plot:=Input("[1]ProfitExit, [2]ProfitStop",
1,2,1);
{ Clean signals }
Init:=Cum(In+Out>-1)=1;
flag:=BarsSince(Init OR In)
<BarsSince(Init OR Out)+(Cum(In)=1);
{ Reference EntryPrice }
entry:=flag AND Alert(flag=0,2);
profitStop:=
ValueWhen(1,entry,C+Mov(ATR(1),pds,E)*multi);
profitExit:=Cross(C,profitStop);
{ Plot ProfitExit in own window }
{ Plot ProfitStop on price chart }
If(plot=1,profitExit,profitStop)
jose '-)
dilmun99
15th November 2004, 01:09 PM
Thanks Jose
But what I'm hoping for is something where I can do this easily in TradeSim so I can minimize duplication (I have long and short positions in this system). In general (and maybe misguidedly) I try to have my base entries in a MS indicator and my stops and exits in TradeSim code in an Exploration. It seems to me that I should be able to do this using the SetProfitStop formula from TS, and simply use one line of additional code to change the variable data array into a constant (hence my suggested code). But it doesn't seem to be working. I'm not sure whether this is a MS code issue or a quirk of TS.
Regards
Andrew
dilmun99
18th November 2004, 12:30 PM
Hi
Is this a David question? It's simply whether there is a way to work around the SetProfitStop limitation of only accepting variable entry. Normally I use ValueWhen to do that kind of task for other MS functions. Does that not work in this case?
Thanks
Andrew
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.