1

i am getting a study error : Objects positioned using xloc.bar_index cannot be drawn further than 500 bars into the future. I have no idea where to even begin to fix this. Some help from experts here would be very helpful.

indicator('MTF Engulfing Candles', overlay=true, max_boxes_count=500, max_lines_count=500)

tf = input.timeframe("240", "Timeframe", options=["60","240","480","720","W","M"])

O1 = request.security(syminfo.tickerid, tf, open[1])
H1 = request.security(syminfo.tickerid, tf, high[1])        
L1 = request.security(syminfo.tickerid, tf, low[1])          
C1 = request.security(syminfo.tickerid, tf, close[1])

O2 = request.security(syminfo.tickerid, tf, open[2])
H2 = request.security(syminfo.tickerid, tf, high[2])        
L2 = request.security(syminfo.tickerid, tf, low[2])          
C2 = request.security(syminfo.tickerid, tf, close[2])

barIndex = request.security(syminfo.tickerid, tf, bar_index)
barIndexMinus2 = request.security(syminfo.tickerid, tf, bar_index-2)

// FUNCTIONS
bullE()=>
    r = C2 < O2 and C1 > O1 and C1 > H2 ? 1 : 0
    
bearE()=>
    r = C2 > O2 and C1 < O1 and C1 < L2 ? 1 : 0

if bullE()
    box.new(left=barIndexMinus2, right=barIndex, top=H1 ,bottom=math.min(L2,L1), border_color = color.new(color.black,65), bgcolor = color.new(#66bb6a,75))
    
if bearE()
    box.new(left=barIndexMinus2, right=barIndex, top=math.max(H2,H1) ,bottom=L2, border_color = color.new(color.black,65), bgcolor = color.new(#ffa726, 75))
Shikhar
  • 13
  • 3

2 Answers2

1

You are requesting bar_index from other timeframes, and you use this as left and right parameters of the box.new(). The problem is, this difference might be quite a lot depending on the timeframe you are on.

For example, on BINANCE:BTCUSDT, 1h, current bar_index is 23426. barIndex and barIndexMinus2 are 11051 and 11049 respectively.

You see, if you use those variables as left and right arguments of your box.new() call, it will cause this issue. Because the distance between the current bar index and your variables are more than 500.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • you have any workaround in mind ? – Shikhar Sep 04 '22 at 13:26
  • It depends on what you want to do? Why are you using `bar_index` from other timeframes? – vitruvius Sep 04 '22 at 14:07
  • well i had an idea to be aware of htf engulfing candles while taking trades on ltf charts. i have seen some indicators do this, but sadly their code is not open to view, so i have no idea how they did it. – Shikhar Sep 04 '22 at 14:27
0

i solved it by using bar_time instead of bar_index.

Shikhar
  • 13
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 16 '22 at 05:57