by Nikolay.Gekht » Tue Apr 20, 2010 9:29 pm
PPMA is standard indicator and is available always.
However, you can calculate PPMA faster than create an indicator instance.
Just declare your indicator required source as Bar
(indicator:requiredSource(core.Bar); in the Init() function),
and then use the following to calculate PPMA(N) value for bar i:
ppma = core.avg(source.typical, core.rangeTo(i, N);
Please, do not forget that ppma cannot be calculate for the first N bars of the chart.
So, the correct way is:
1) declare global variable first:
local first;
2) in the Prepare function calculate the value of this variable as the first available period of the source plus N, where N is parameter of the PPMA
first = source:first() + N;
3) In the Update function skip calculate until the bar number is less than first
if period >= first then
... calculate here
end