This update of "Green/Red Bar Counts" indicator showcases the latest feature in Indie language 4.3, the indie.Var[T] container.
In this implementation:
Unlike using a single float or int, indie.Var is fully compatible with Indie’s series-based environment, where values update bar by bar. Plain variables would reset on each new bar calculation, causing them to lose their previous state. Moreover, indie.Var ensures that values persist correctly in both historical and real-time data. A simple local number variable would reset or lack the ability to update accurately in real-time, making it unsuitable for cumulative calculations. In contrast, indie.Var provides stable, consistent updates across all bars.
In cases where only the latest value is required without retaining historical data, you can convert code from indie.MutSeries to indie.Var by following these general rules:
1. Replace MutSeries.new() with Var.new():
my_var = Var[float].new(0) # instead of my_series = MutSeries[float].new(0)
2. Use .get() and .set() instead of indexing:
var_value = my_var.get() # instead of series_value = my_series[0]
my_var.set(new_value) # instead of my_series[0] = new_value
to activate earnings with sharing
Comments