Hi! Can anybody help my understand why my system gets stopped when a order is opened? The system says the stop loss i set to far away from the price and then the position is closed and the system stopped. Im not sure why the system just don’t set the stop acccording to the ATR stetting. I run it on a demo account on IG.
This is my code:
//-------------------------------------------------------------------------
// Main code : Reversal/stochastic/heikni
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = False
sto = stochastic[8,3](close)
ATRValue = AverageTrueRange[14](close)
ema200 = ExponentialAverage[200](close)
c1 = close[1]<open[1] and close>open
c2 = close>open[1]
c3 = lowest[3](low)<lowest[50](low)[1] or lowest[3](low)<lowest[50](low)[2] or lowest[3](low)<lowest[50](low)[3]
c4 = sto<20 and close > ema200 // Tillagt krav om EMA200 för lång position
longCondition = c1 and c2 and c3 and c4
c5 = close[1]>open[1] and close<open
c6 = close<open[1]
c7 = highest[3](high)>highest[50](high)[1] or highest[3](high)>highest[50](high)[2] or highest[3](high)>highest[50](high)[3]
c8 = sto>80 and close < ema200 // Tillagt krav om EMA200 för kort position
shortCondition = c5 and c6 and c7 and c8
contractSize = 1
// Hantera Heikin Ashi
haClose = (open + high + low + close) / 4
haOpen = (open[1] + close[1]) / 2
haHigh = max(high, max(haClose, haOpen))
haLow = min(low, min(haClose, haOpen))
if barindex > 1 then
if longCondition and haClose > haOpen then
buy contractSize contract at market
set stop ploss lowest[3](low) - 1.75 * ATRValue
set target pprofit 5 * ATRValue
elsif shortCondition and haClose < haOpen then
sellshort contractSize contract at market
set stop ploss highest[3](high) + 1.75 * ATRValue
set target pprofit 5 * ATRValue
endif
endif
Hi,
at first glance you used a stop instruction expecting a distance in points from the position price, but instead of using it with a distance, you used it with a price level (which would be a much bigger number and explain the message too far away from price). So, either you may replace your lowest[3](low)-1.75*atrvalue with the distance from position price, or you may use a different stop instruction expecting a price level (set stop price).
https://www.prorealcode.com/documentation/ploss-2/
PRICE
As Noobywan explained, you should use SET STOP PRICE, which is used to set a stoploss at a specific price.
Also, you set the target profit in points with a value in price, you should use SET TARGET PROFIT instead (which is used to set a target in price distance unit).
set stop price lowest[3](low) - 1.75 * ATRValue
set target profit 5 * ATRValue