Green/Red Bar Count - usage example of indie.Var[T]

loading

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:

  • State Tracking: The indie.Var[T] container counts consecutive green (up) or red (down) bars without retaining any history. indie.Var[T] is ideal here since it efficiently holds only the most recent value, unlike indie.MutSeries[T], which maintains a historical sequence of values.

Why Use indie.Var Instead of a Simple Float or Integer?

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.

Key Differences with the Previous Version: General Transformation from MutSeries to Var

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 

TA TakeProfit
TakeProfit
Updated Nov 13, 2024
education
indie
Share icon

to activate earnings with sharing

Comments

loading