Can anyone tell me why my indicator doesn't work properly
We don't know what it's trying to do. Maybe explain what you're trying to achieve/expecting vs what you got.
ubzen:
We don't know what it's trying to do. Maybe explain what you're trying to achieve/expecting vs what you got.
We don't know what it's trying to do. Maybe explain what you're trying to achieve/expecting vs what you got.
It's a Variable Moving Average (AKA VIDYA) Indicator using a CMO Indicator I downloaded. The indicator works in charts when I select it, but when I try to use the indicator in backtesting the values that are returned at any point in time are not the same as what is shown in the charts. There seems to be some sort of 'shift lower' (e.g. all values are say 100 pips down) when I run it through the backtester and I can't figure out why.
double vi = MathAbs(iCustom(NULL,0,"CMO",true,volatilityPeriod,0,0)) / 100; double vma = sc * vi * Close[i] + (1 - sc * vi) * VMA[i+1];
- vi should be changing, probably
double vi = MathAbs(iCustom(NULL,0,"CMO",true,volatilityPeriod,0,i)) / 100;
- Don't calculate ema's like that, prone to round off errors increasing
vma[i] = vma[i+1] + sc * (vi * Close[i] - vma[i+1]);
U da man!!
I've changed the code to:
while (i > 0) { // Smoothing constant double sc = 2.0 /(period + 1); // Volatility index double vi = MathAbs(iCustom(NULL,0,"CMO",true,volatilityPeriod,0,0)) / 100; VMA[i] = VMA[i+1] + sc * (vi * (Close[i] - VMA[i+1])); i--; }
And now it seems to be working as expected.
Thanks.
I'm trying to write an indicator. It kind of works but in backtesting the values returned don't match what's shown in the chart.
Where am I going wrong?
Here's the code: