pine-scriptpine-script-v4

rsi value of ongoing week is missing in series


The pine script below will set a label over every weekly candle (if set to candle resolution weekly). The last week is missing. How could I add that current RSI weekly value? Any clue?

strategy("RSI Strategy", overlay=true, initial_capital = 1000, default_qty_value= 100, default_qty_type=strategy.percent_of_equity)
  

btcWeekly = security("BINANCE:BTCUSDT", "W", close) // 240 Minutes
rsi_w = rsi(btcWeekly, 14)

plotchar(rsi_w, "Weekly RSI Value", "", location = location.top)


label.new(bar_index, high, tostring(rsi_w, "#.#"), yloc = yloc.abovebar, color = color.red, style = label.style_label_down)

Solution

  • According to pinescript strategy execution model the strategies ignore the real-time bar and execute only on confirmed historical bars. To force the strategy to execute on real-time bar (current weekly candle in your example) add calc_on_every_tick argument as is shown in the example below:

    //@version=4
    strategy("RSI Strategy", overlay=true, initial_capital = 1000, default_qty_value= 100, default_qty_type=strategy.percent_of_equity, calc_on_every_tick = true)
    ...
    

    enter image description here enter image description here