OnParamsChange
What is it?
The OnParamsChange method is called automatically when the user changes any parameter of your indicator β for example, the period, color, MA type, etc.
It allows you to respond to these changes and implement custom logic that should happen when parameters are modified.
Important: This method is NOT used for the actual parameter values to change β that happens internally. This method is only for custom logic that needs to be executed when parameters are changed.
Syntax
public OnParamsChange(): void {
// custom logic after parameter change
}When and Why to Use It
This method is called after the user updates the settings in the indicator panel, but before the indicator is recalculated.
Use OnParamsChange() When You Need To:
Recalculate internal values based on new parameter values
Adjust or re-create custom chart objects (lines, labels, etc.)
Update dependencies between parameters
Perform validation or parameter-based setup
Reset internal state that depends on parameters
Apply dynamic styling or configuration changes
Don't Use OnParamsChange() If:
You only need basic parameter changes (values update automatically)
You don't have any custom logic dependent on parameter changes
Your indicator works fine with just
Init()andCalculate()
What CAN Be Done in OnParamsChange
OnParamsChangeBuffer and Display Updates
Modify buffer properties (styles, labels, visibility)
Update buffer configuration based on parameter changes
Reconfigure drawing styles and colors
Adjust buffer drawing ranges with
SetIndexDrawBegin()
Chart Object Management
Create, modify, or remove custom chart objects
Update object positions based on parameter changes
Reconfigure object properties (colors, styles, positions)
Manage dynamic visual elements
Internal State Management
Reset calculation counters or accumulators
Update lookup tables or cached calculations
Reconfigure internal algorithms based on parameters
Initialize parameter-dependent variables
What CANNOT Be Done in OnParamsChange
OnParamsChangeβ Forbidden Operations
Heavy calculations or complex mathematical operations
Per-bar data processing (this should be in
Calculate())Modifying the actual parameter values (handled internally)
Creating new parameters (must be done in
Init())Changing buffer count with
IndicatorBuffers()(must be inInit())Loops through large datasets or historical data processing
β Wrong Approach
β
Correct Approach
Practical Examples
Example 1: Dynamic Buffer Styling
Example 2: Parameter Validation and Dependencies
Example 3: Chart Object Management
Best Practices
β
Do This
Keep it lightweight - only essential parameter-dependent logic
Use it for setup/configuration that depends on parameters
Reset internal state when parameters change
Update visual properties based on parameter values
Validate parameter combinations if needed
β Avoid This
Heavy computational work (belongs in
Calculate())Complex loops or data processing
Modifying parameter values
Creating new parameters or buffers (belongs in
Init())
When NOT to Implement OnParamsChange()
You can skip implementing this method if:
Your indicator only uses basic parameters for calculations
No custom logic is needed when parameters change
All parameter-dependent behavior happens in
Calculate()You don't have dynamic visual elements or chart objects
Key Rules Summary
OnParamsChange() is optional - only implement if you need custom logic
Keep it lightweight - no heavy calculations or data processing
Parameter values update automatically - this method is for additional logic only
Use it for configuration and setup that depends on parameter values
Cannot create new parameters or buffers - only modify existing ones
Runs before recalculation - perfect for resetting internal state
Great for dynamic visuals - updating styles, objects, and display properties
Pro Tip
Think of OnParamsChange() as your "parameter change reaction" method. It's the perfect place to update anything that depends on parameter values but doesn't belong in the per-bar Calculate() method. Keep it fast and focused on configuration rather than calculation.
Last updated