Hello
I’m not sure what I’m doing wrong, as I’m not getting the expected entry in trades with this platform. Below is part of a larger strategy, but I’ve trimmed the code to simplify troubleshooting. If you notice, when the price touches the short moving average during a downtrend, the trade is not executed as expected. Please see the attached file. This is just one example among many occurrences. The platform’s time is set to UTC+1. Asset is US Crude $10 in 4Hrs time fame. The strategy involves executing a sell entry position when the long moving average is above the short moving average, and the price touches the short moving average. This should be done with a fixed stop loss and profit target
defparam cumulateorders=false
//////////////////////////////////////////Short Position Condition///////////////////////////////////////////
MAS=ExponentialAverage[15](close)
MAL=ExponentialAverage[55](close)
IF MAS[1]<MAL[1] THEN
condition1Short=1
ELSE
condition1Short=0
ENDIF
IF ABS(High-MAS)<10*pipsize THEN
priceTouched1=1
ELSE
priceTouched1=0
ENDIF
//// Conditions to enter short positions
IF NOT ShortOnMarket AND condition1Short AND priceTouched1 THEN
SELLSHORT 1 CONTRACTS AT MARKET
SET STOP PLOSS 100*pipsize
SET TARGET PPROFIT 100*pipsize
ENDIF
Without seeing Cursor Details showing actual values how can we be sure ABS(High–MAS)<10*pipsize and is not > 10*pipsize on the bar inside the red ring?
@GraHal, correct me if I’m wrong, but in a backtesting environment, does the ProRealTime engine process data in CSV format, including open, close, high, and low prices, without executing trades minute by minute or tick by tick within the current candlestick?
Code on any / all Timeframes (TF) is read and executed at the end of each bar. Trades are opened / closed at the open of the next bar.
On a 4 Hour TF the conditions which exist at the end of 4 hours re HLOC are what would open / close a trade etc.
If you want minute by minute execution then you would need to use a 1 minute TF or multi-timeframe (4 hour and 1 min)
If above does not answer your question then please elaborate / ask again?