rebParticipant
Master
Hi
I’m a bit confused because I tried to code a simple idea :
If price reaches S4 day (normal PP), I buy
Here is the code:
DEFPARAM CumulateOrders = False
ONCE TradeToday = 0
IF Date <> Date[1] THEN
TradeToday = 0
ENDIF
// Autoriser les nouvelles entrées sauf après 17h30 le vendredi
AutorisationEntree = 1
IF DayOfWeek = 5 AND Time >= 173000 THEN
AutorisationEntree = 0
ELSIF Time <= 020000 then
AutorisationEntree = 0
ENDIF
TimeFrame(Daily)
PP = (High[1] + Low[1] + Close[1]) / 3
S3 = Low[1] – 2*(High[1] – PP)
S4 = Low[1] – 3*(High[1] – PP)
S5 = Low[1] – 4*(High[1] – PP)
TimeFrame(Default)
IF NOT LongOnMarket AND TradeToday = 0 AND AutorisationEntree = 1 AND Low <= S4 THEN
BUY 1 CONTRACT AT S4 LIMIT
ENDIF
IF LongOnMarket THEN
TradeToday = 1
SELL AT S5 STOP
SELL AT S3 LIMIT
ENDIF
In using the backtest function, I notice some trades which shouldn’t exist
Here are 4 examples of trades taken in “the middle of nowhere” compared with the levels given by PRT
In total , the backtest has 11 trades in 2026, visual observation has only 5
Is there an issue with my PP, S4 calculation compared with the platform ?
Thanks in advance,
Reb
PS: subsidiary question how to code a stop limit order (ordre à plage de déclenchement) ?
Your daily timeframe declaration has no ‘updateonclose’.
Therefore each read of the code in the inferior timeframe takes the high/ low values of the current day, while it should be from the previous day.
Hi,
To check your PP S4 calculations, you can add at the end of the backtest:
graphonprice PP as “PP”
graphonprice S4 as “S4”
Discrepencies displayed will give you clues. Considering all the examples you gave are on a monday, and considering the time conditions you are using would imply you are probably using IG and its 24h cfd assets, including a little sunday night data, the most likely cause (or at least one of the causes in case it doesn’t solve everything) would be that your monday pivot calculation is based on sunday data, where the platform displays on monday pivots based on friday data.
If what you see thanks to the added “graphonprice” lines shows that’s the case, then you can try to replace this:
TimeFrame(Daily)
PP = (High[1] + Low[1] + Close[1]) / 3
S3 = Low[1] – 2*(High[1] – PP)
S4 = Low[1] – 3*(High[1] – PP)
S5 = Low[1] – 4*(High[1] – PP)
with this:
TimeFrame(Daily)
if opendayofweek>1 then
PP = (High[1] + Low[1] + Close[1]) / 3
S3 = Low[1] - 2*(High[1] - PP)
S4 = Low[1] - 3*(High[1] - PP)
S5 = Low[1] - 4*(High[1] - PP)
else
PP = (High[2] + Low[2] + Close[2]) / 3
S3 = Low[2] - 2*(High[2] - PP)
S4 = Low[2] - 3*(High[2] - PP)
S5 = Low[2] - 4*(High[2] - PP)
endif
and then, check again thanks to the graphonprice lines if it got rid of pivot calculations discrepencies between code and platform.
I don’t think it’s an updateonclose case on this one, because although it was written without updateonclose, the HLC data used in calculation in the timeframe(daily) bloc were all with [1] so previous day data indeed. Yes it could have been written with updateonclose (and then, without the [1]), but it wouldn’t solve the monday issue with the “sunday instead of friday” data.
rebParticipant
Master
Well done, I forgot those sunday data