Custom indicator's moving-average calc degenerates to raw price (identity) for specific inputs, while an identical code pattern with different inputs works correctly
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have a custom indicator with a reusable CMA class ( Setup() + Compute() ) that computes one of 14 selectable moving-average types. Two different input-variable pairs feed separate instances of this exact same class/method:
Both pairs are declared the same way ( input E_MA_TYPE ...; input int ...; ), passed into Setup() identically, and computed via the identical Compute() method. The baseMAType / baseLength -fed instances always return the raw input price unchanged (i.e. the MA has zero smoothing — output == close[i] exactly, every bar), while the SSL2Type / len2 -fed instances compute correctly (verified: 166 bull / 134 bear state changes across 300 bars — clearly not degenerate).
This happens even using the compiled-in default values ( baseMAType=MAT_HMA default, baseLength=60 default) — not only when overriding via iCustom() . So it isn't specifically about parameter overrides; the base computation itself is broken for this one variable pair.
Minimal repro of the relevant code
Symptom, verified with independent cross-checks
What I've ruled out (all retested after each change, all still broken)
- iCustom argument count — tested 13, 15, 17, 19, 22 positional override arguments; failure is independent of count (a different, much simpler 0-plot/14-buffer indicator broke at just 13 args, while a more complex 8-plot/31-buffer indicator worked fine at 15 args in earlier testing — so it's not a fixed count threshold either).
- Argument position — added 11 dummy leading input int params before baseMAType / baseLength (both in the indicator's declaration and the caller's positional list) to push them later in the list; no change.
- Variable naming collision — renamed maType → baseMAType , len → baseLength throughout; grepped the (large, ~330KB) shared include library for any global-scope len / maType declaration or #define ; none found; rename made no difference.
- Enum type as first positional argument — explicitly cast to (int) for every enum-typed argument passed via iCustom(...) ; no change.
- Caller context — reproduced identically from both a Script ( OnStart ) and an EA ( OnInit / OnTick ); both fail the same way.
- indicator_plots 0 vs 1 — the indicator has #property indicator_plots 0 (all buffers INDICATOR_CALCULATIONS , called only via iCustom , never displayed). Adding a real plot for the affected buffer didn't fix the value bug, and additionally made that specific buffer unreadable via CopyBuffer ( error 4806 ) while the indicator was never actually shown on a chart subwindow — reverted.
- Confirmed via GetLastError() after every failing CopyBuffer / iCustom call — never non-zero except in the plots=1 experiment above.
Please help me!!!