I've encountered a puzzling issue with a PowerLanguage script for the SuperTrend indicator. The script involves a function 'SuperTrend_Cross_fn' which identifies crosses in the SuperTrend indicator and returns +1 for a cross-up and -1 for a cross-down.
When I manually sum the function calls over different ATRLength values, the results are as expected. For instance:
Code: Select all
CrossCounter = SuperTrend_Cross_fn(ATRLength, ATRMult, AFStep, MaxAF, LookbackPeriod) +
// ... additional calls with ATRLength+1, ATRLength+2, etc.
SuperTrend_Cross_fn(ATRLength+9, ATRMult, AFStep, MaxAF, LookbackPeriod);
Code: Select all
Vars: myvar1(0), CrossCounter(0);
For myvar1 = 0 to 9 begin
CrossCounter = CrossCounter + SuperTrend_Cross_fn(ATRLength + myvar1, ATRMult, AFStep, MaxAF, LookbackPeriod);
end;
I feel it can't be an issue with the function itself as the manual addition returns the correct output.
Has anyone experienced a similar issue or can offer insight into why the loop might not be working as intended? Any help or guidance would be greatly appreciated.