I use an ATR for my stop loss. The problem is that the stop loss is recalculated after every bar.
I would like to have a fixed ATR stop loss based on the ATR value when the trade is initiated and which will remain fixed until the trade end.
The current code is like this (simplified code) :
Code: Select all
inputs:
ATRLengthS (5),
NumATRsS (5);
variables:
var1( 0 );
condition3 = marketposition=0 and .... ;
if condition3 then
Buy ( "BBStochLE" ) next bar at market ;
condition4 = marketposition=0 and ..... ;
if condition4 then
sellshort ( "BBStochDLX" ) next bar at market ;
condition5 = marketposition=1 and ..... ;
if condition5 then
sell( "BBStochSE" ) next bar at market ;
condition6 = marketposition=-1 and ..... ;
if condition6 then
buytocover ( "BBStochSX" ) next bar at market ;
SetStopLoss( AvgTrueRange( ATRLengthS * NumATRsS )) ;
Can someone helps me to code it?