Skip to main content Skip to footer

Although variable declaration is not an action per se, it is considered an algo element because it can only be declared within the OnBarUpdate handler of a strategy in the Manual Strategy Builder (MSB).

Similarities and Differences with Input Parameters

 

While local variable declarations share similarities with input parameter declarations, there are key differences:

 

  1. Run-Time Calculation: A local variable's value can be dynamically calculated at run-time. For instance, a variable can be assigned a value derived from an indicator, the current price, another input parameter, a private member, or another variable.

  2. Scope: A local variable has a specific scope within the strategy. Any algo element higher up in the element tree cannot access this variable because it does not exist within their scope yet. This ensures that variables are only accessible within the context they are defined.

 

Assigning Values to Local Variables

 

When declaring a local variable, it must be assigned a value immediately. This value can be specified using the standard methods described in the "Operand Component" chapter. For example, a variable of type double could be declared to hold the last value of the Average True Range (ATR) indicator, multiplied by 2.

Conclusion

 

Local variable declarations are a critical part of the MSB, allowing for dynamic and context-specific calculations within a strategy. By enabling values to be calculated at run-time and maintaining specific scopes, local variables provide flexibility and precision in strategy development. This capability ensures that complex strategies can be efficiently organized and executed within the OnBarUpdate handler, enhancing the overall functionality and adaptability of trading strategies in FinStudio.

Cookies Notice

We use cookies to improve your experience, personalize content, and analyze our traffic. By clicking "Accept All Cookies," you agree to the storing of cookies on your device. You can manage your cookie preferences at any time by visiting our Cookie Settings.