Wilson Wong: I have no doubt i have messed up some key elements in the code.
if(i==rates_total-periodAMA-nfast) AMA0=close[i+1]; signal=MathAbs(close[i]-close[i+periodAMA]);
You are accessing the array as-series, but you didn't set it that way.
Note
To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
with the modified code
#property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 3 //--- plot kAMAbuffer #property indicator_label1 "kAMAbuffer" #property indicator_type1 DRAW_LINE #property indicator_color1 clrYellow #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot kAMAupsig #property indicator_label2 "kAMAupsig" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrLime #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot kAMAdownsig #property indicator_label3 "kAMAdownsig" #property indicator_type3 DRAW_ARROW #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- input parameters input int periodAMA=9; input int nfast=2; input int nslow=30; input double G=2.0; input double dK=2.0; double slowSC,fastSC; double myPoint; //--- indicator buffers double kAMAbuffer[]; double kAMAupsig[]; double kAMAdownsig[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,kAMAbuffer,INDICATOR_DATA); SetIndexBuffer(1,kAMAupsig,INDICATOR_DATA); SetIndexBuffer(2,kAMAdownsig,INDICATOR_DATA); ArraySetAsSeries(kAMAbuffer,true); ArraySetAsSeries(kAMAupsig,true); ArraySetAsSeries(kAMAdownsig,true); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(0,DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(0,PLOT_SHOW_DATA,true); PlotIndexSetInteger(1,PLOT_ARROW,159); PlotIndexSetInteger(2,PLOT_ARROW,159); myPoint = SetPoint(); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- int begin=!prev_calculated?rates_total-periodAMA-nfast-1:rates_total-prev_calculated; int i = begin; double noise=0.000000001,AMA,AMA0,signal,ER; double dSC,ERSC,SSC,ddK; slowSC=(2.0 /(nslow+1)); fastSC=(2.0 /(nfast+1)); ArraySetAsSeries(close,true); i = rates_total-periodAMA-nfast; AMA0 = close[i+1]; //--- main cycle for(i=begin; i>=0 && !IsStopped(); i--) { if(i==rates_total-periodAMA-nfast) AMA0=close[i+1]; signal=MathAbs(close[i]-close[i+periodAMA]); noise=0.000000001; for(int j=0;j<periodAMA;j++) { noise=noise+MathAbs(close[i+j]-close[i+j+1]); }; ER =signal/noise; dSC=(fastSC-slowSC); ERSC=ER*dSC; SSC=ERSC+slowSC; AMA=AMA0+(MathPow(SSC,G)*(close[i]-AMA0)); kAMAbuffer[i]=AMA; ddK=(AMA-AMA0); if ((MathAbs(ddK)) > (dK*myPoint) && (ddK > 0)) kAMAupsig[i] =AMA; else kAMAupsig[i]=0; if ((MathAbs(ddK)) > (dK*myPoint) && (ddK < 0)) kAMAdownsig[i]=AMA; else kAMAdownsig[i]=0; AMA0=AMA; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ double SetPoint() { double mPoint; if (_Digits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); }
I am getting this unexpected downward plunging line of the indicator when there's a new bar appearing and the same goes when running it on tester.
https://charts.mql5.com/31/896/eurusd-d1-metaquotes-software-corp-2.png
Any advice?
did you find the answer of your question? do you have the solution now?

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
MQL4 code:
my try on MQL5 porting of the above code:
but the end result of the indicator on chart appeared very different. I have no doubt i have messed up some key elements in the code. Any help appreciated.