title: How to fix history vs realtime data issue with security function in tradingview backtesting
body: <p>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:</p>
  
  <pre><code>// 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)
  </code></pre>
  
  <p>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!</p>
  
  <p>Already tried tradingview solution and also switched between barmerge on and off.</p>
  
  <pre><code>  //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)
  </code></pre>
  
  <p>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</p>