3

I'm really struggling using my indicator during backtesting because it plots the future daily highs and lows before it even reaches them. According to pine script, this should solve the problem:

// To avoid difference in the calculation on history/realtime you can request
// not the latest values and use merge strategy flags as follows:
s2=security(tickerid, "D", close[1], barmerge.gaps_off, barmerge.lookahead_on)

But I already did that and I get the same result. Does anybody have some experience with this type of issue? It would be greatly appreciated, thanks!

Already tried tradingview solution and also switched between barmerge on and off.

  //Intraday Highs and Lows
highestHigh = security(tickerid, "D", high[1],barmerge.gaps_off,barmerge.lookahead_on)
lowestLow   = security(tickerid, "D", low[1],barmerge.gaps_off, barmerge.lookahead_on)
//Intraday Highs and Lows Delayed
highestHighD = security(tickerid, "D",high[2],barmerge.gaps_off,barmerge.lookahead_on)
lowestLowD   = security(tickerid, "D", low[2],barmerge.gaps_off,barmerge.lookahead_on)
//4HR Highs and Lows Delayed
daily_high = security(tickerid, "240" , high[1],barmerge.gaps_off,barmerge.lookahead_on)
daily_low = security(tickerid, "240", low[1],barmerge.gaps_off,barmerge.lookahead_on)

According to trading view, the result should be fixed with the first code and my daily values would be automatically updated as the sessions go on without taking into account future values, but the actual result is just Intraday Highs and Lows being plotted automatically as soon as the session starts

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
  • Would be helpful if you mentioned the symbol/TF you are running the script on, as well as provide `plot()` calls you're using. The first example you show should work. This PineCoders [indicator](https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/) shows all combinations of `security()` calls plotted on the chart and may be helpful. – PineCoders-LucF Aug 20 '19 at 07:22
  • I don't know tradingview solution but this is a common issue when backtesting. Some backtesting offers the ability to execute a trade before a bar is finished. But this is not possible in real-time trading. As you will only get the Bar when it is finished. Try to use the previouse bar on your backtesting –  Aug 29 '19 at 11:37

0 Answers0