Hi Everybody,
I have a simple breakout strategy that I am trying to code in PRT, but I’m struggling a bit with the ATR-stop loss and the position sizing (also uses ATR). I haven’t even attempted the position size part yet, as the system is closing orders at strange times…
Here is the code and attached is a photo of the rules.
Hope you can help me!
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
//variables
positionsize=2
fastMA=50
slowMA=100
DonchOpen=50
// Conditions to enter long positions
C1 = close > Highest[DonchOpen](high[1])
indicator1 = ExponentialAverage[fastMA](close)
indicator2 = ExponentialAverage[slowMA](close)
C2 = (indicator1 > indicator2)
if C1 and C2 then
BUY positionsize PERPOINT AT MARKET
endif
// Conditions to exit long positions
highpoint=max(tradeprice,Highest[DonchOpen](high[1]))
atr = averagetruerange[100]*3
SL1 = highpoint - atr
if longonmarket then
sell at SL1 stop
endif
// Conditions to enter short positions
C4 = close < lowest[DonchOpen](low[1])
indicator1 = ExponentialAverage[fastMA](close)
indicator2 = ExponentialAverage[slowMA](close)
c5 = (indicator1 < indicator2)
if c4 and c5 then
sellshort positionsize PERPOINT AT MARKET
endif
// Conditions to exit short positions
lowpoint=min(tradeprice,lowest[DonchOpen](low[1]))
atr = averagetruerange[100]*3
SL2 = lowpoint + atr
if shortonmarket then
sell at SL2 stop
endif
DANYParticipant
Senior
Just with a bit of late, sorry 😐
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
//variables
positionsize=2
fastMA=ExponentialAverage[50](close)
slowMA=ExponentialAverage[100](close)
AVGTRLong=averagetruerange[100]
DonchOpen=50
// Conditions to enter long positions
LGC1 = close > Highest[DonchOpen](high[1])
LGC2 = (fastMA > slowMA)
if Not LongOnMarket AND (LGC1 and LGC2) then
BUY positionsize CONTRACT AT MARKET
LGatr = AVGTRLong*3
endif
// Conditions to exit long positions
if longonmarket then
LGsl = tradeprice - LGatr
//Graph tradeprice as "tradeprace"
//Graph LGatr as "LGatr"
//Graph LGsl as "LGsl"
sell at LGsl stop
endif
// Conditions to enter short positions
SHC1 = close < lowest[DonchOpen](low[1])
SHC2 = (fastMA < slowMA)
if Not ShortOnMarket AND SHC1 and SHC2 then
sellshort positionsize CONTRACT AT MARKET
SHatr = AVGTRLong*3
endif
// Conditions to exit short positions
if shortonmarket then
SHsl = tradeprice + SHatr
Graph tradeprice as "tradeprace"
Graph SHatr as "SHatr"
Graph SHsl as "SHsl"
exitshort at SHsl stop
endif