How to use time_frame_gaps in strategy to get real-time indicator value when running strategy?

Viewed 16

I'm trying to use RVI(Relative Vigor Index) in my strategy,

indicator(title="Relative Vigor Index", shorttitle="RVGI", format=format.price, precision=4, timeframe="", timeframe_gaps=true)
len = input.int(10, title="Length", minval=1)
rvi = math.sum(ta.swma(close-open), len)/math.sum(ta.swma(high-low),len)
sig = ta.swma(rvi)
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(rvi, color=#008000, title="RVGI", offset = offset)
plot(sig, color=#FF0000, title="Signal", offset = offset)

however, The 'strategy' function does not have an argument with the name 'timeframe_gaps'

this will cause a problem which is the RVI can show latest value as Indicator at current kindle, but can only show the value 1 kindle back when using as strategy. or plot value after current kindle closes.

How can I get the current kindle of RVI in strategy mode?

1 Answers

By default strategies will be executed when a bar is closed. If you want your strategy to be executed with each tick, you need to set calc_on_every_tick property of your strategy() call to `true.

calc_on_every_tick (const bool) Specifies whether the strategy should be recalculated on each realtime tick. If true, when the strategy is running on a realtime bar, it will recalculate on each chart update. If false, the strategy only calculates when the realtime bar closes. The argument used does not affect strategy calculation on historical data. This setting can also be changed in the strategy's "Settings/Properties" tab. Optional. The default is false.

Related