Calculate
What is it?
The Calculate
method is one of the core functions used in a custom indicator. It’s responsible for calculating the logic of your indicator for each bar (candle) on the chart.
This function runs automatically on each price update (tick) and recalculates values for the given bar.
How It Works
index
— This parameter tells you which bar you’re working with.index = 0
→ the latest bar (rightmost on the chart).index = 1
→ the previous bar, and so on.
The method runs once per tick (price change) and calculates the indicator value only for the specified bar.
Example Explained
What This Code Does
Checks if there are enough bars to calculate the moving average. (We need
Period
number of candles; otherwise, we skip.)Calculates a Moving Average value using
GetMA()
.Stores the result in the
SMA
buffer, which is used for drawing on the chart.Applies a vertical shift (
VShift
) and stores the result in a second buffer (SSMA
).
In Short
This method is where you put your main logic.
It runs automatically for each bar.
You should use it to calculate and store indicator values.
Buffers like
SMA
andSSMA
are how your indicator shows up visually on the chart.
Last updated