This is unnecessary.
//ArraySetAsSeries(aAD,true);
This has nothing to do with the question.
for(int i = start_Position; i < rates_total && !IsStopped(); i++) { //double priceClose = iClose(_Symbol,PERIOD_CURRENT,i); //double priceHigh = iHigh(_Symbol,PERIOD_CURRENT,i); //double priceLow = iLow(_Symbol,PERIOD_CURRENT,i); //long tickVolume = iVolume(_Symbol,PERIOD_CURRENT,i); // Calculate First A/D Value double sumAD = ((close[i] - low[i]) - (high[i] - close[i])); // Calculate Remaining A/D Values if((high[i] - low[i]) == 0) sumAD = 0.00; else sumAD = (sumAD / (high[i] - low[i])) * tick_volume[i]; if(i > 0) sumAD += aAD[i-1]; aAD[i] = sumAD; }
This is unnecessary.
This has nothing to do with the question.
Thanks Nagisa
removing ArraySetAsSeries ... solved the problem of upside down.
However if you notice both Dodger Blue (Technical Indicator MQL5) and GoldenRod (Custom Indicotor) are not showing consistent results!!!
The formulas for AD I took from some online indicator where the source code is available. I did not get why you have highlighted it.
My ultimate goal is to make an 10 Period Oscillator of A/D Indicator, same as the first indicator in this chart.
any suggestions would be highly appreciated.
double priceClose = iClose(_Symbol, PERIOD_CURRENT, i); double priceHigh = iHigh(_Symbol, PERIOD_CURRENT, i); double priceLow = iLow(_Symbol, PERIOD_CURRENT, i); long tickVolume = iVolume(_Symbol, PERIOD_CURRENT, i);
If you adopt this method to retrieve prices, the order of the data will be reversed.
That is, the latest value is when "i == 0", and the oldest data is when "i == rates_total - 1".
In this case, you need to use the same method as in MT4, as follows.
ArraySetAsSeries(aAD, true);
if(rates_total < 2) return(0); // Exit with Zero result int start_Position = rates_total - prev_calculated; if(start_Position == rates_total) start_Position = rates_total - 1; //+--------------------------------------------------------------------------------------------------------+ //| Accumulation / Distribution //+--------------------------------------------------------------------------------------------------------+ for(int i = start_Position; i >= 0 && !IsStopped(); i--) { double priceClose = iClose(_Symbol, PERIOD_CURRENT, i); double priceHigh = iHigh(_Symbol, PERIOD_CURRENT, i); double priceLow = iLow(_Symbol, PERIOD_CURRENT, i); long tickVolume = iVolume(_Symbol, PERIOD_CURRENT, i); // Calculate First A/D Value double sumAD = ((priceClose - priceLow) - (priceHigh - priceClose)); // Calculate Remaining A/D Values if((priceHigh - priceLow) == 0) sumAD = 0.00; else sumAD = (sumAD / (priceHigh - priceLow)) * tickVolume; if(i < rates_total - 1) sumAD += aAD[i + 1]; aAD[i] = sumAD; }
If you adopt this method to retrieve prices, the order of the data will be reversed.
That is, the latest value is when "i == 0", and the oldest data is when "i == rates_total - 1".
In this case, you need to use the same method as in MT4, as follows.
Thanks a lot Nagisa.
will look into it details and do the necessary corrections. However, I got the logic you have tried to explain.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Please help me identify the error why my custom indicator is displaying upside down. Dodger Blue line is original indicator and GoldenRod color my custom indicator in the attached screen shot.
Also, I have not set LEVEL anywhere in code, yet in chart it is displayed. May be that is causing the problem!!!