My problem is here http://imagicon.info/howto/mql5%20slow%20test%20ama.htm
All standard indicators run very fast in visual testing mode,
but my converted from mql4 to mql5 ama custom indicator is very slow during visual testing even if I use 1 minute input not ticks
What to do?
I haven't study the entire code, but I guess this is the problem
if (cbars>0) cbars--; pos=periodAMA+2; //<<-- pos is always equal to periodAMA+2 AMA0=close[pos-1]; while (pos<rates_total) //<<-- on every tick, the indicator have to re-calculate all over again { ... pos ++; }
I gonna delete your video link later, I hope you don't mind.
I will try to help you soon as I get into the TRAIN :) Like phi.nuts said the problem is likely in the loop.
Br, Candles
I will try to help you soon as I get into the TRAIN :) Like phi.nuts said the problem is likely in the loop.
Br, Candles
I think I got it to work faster now. The below code seems ok:
If it does not work or has bugs report to me, thx :)
Br, Candles
//+------------------------------------------------------------------+ //| AMA.mq5 | //| Converted from AMA.mq4 ("Copyright © 2004, by konKop,wellx") | //| | //+------------------------------------------------------------------+ //#property copyright "Copyright 2013, eurgbp" //#property link "https://www.mql5.com/en/forum/10942" #property version "1.00" //+------------------------------------------------------------------+ //| AMA.mq5 | //| rewritten by Candles | //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, Candles" #property link "https://www.mql5.com/en/forum/10942#comment_442248" #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Sienna #property indicator_type1 DRAW_LINE #property indicator_width1 2 #property indicator_color2 DeepSkyBlue #property indicator_type2 DRAW_ARROW #property indicator_color3 Gold #property indicator_type3 DRAW_ARROW //---- input parameters input int periodAMA=20; input int nfast=3; input int nslow=30; input double G=2.0; input double dK=2.0; //---- buffers double kAMAbuffer[]; double kAMAupsig[]; double kAMAdownsig[]; //+------------------------------------------------------------------+ int cbars=0,prevbars=0,prevtime=0; double slowSC,fastSC; #property indicator_plots 3 //--- indicator buffers //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- indicator buffers mapping SetIndexBuffer(0,kAMAbuffer,INDICATOR_DATA); SetIndexBuffer(1,kAMAupsig,INDICATOR_DATA); SetIndexBuffer(2,kAMAdownsig,INDICATOR_DATA); PlotIndexSetInteger(1,PLOT_ARROW,159); PlotIndexSetInteger(2,PLOT_ARROW,159); //--- return(0); } //+------------------------------------------------------------------+ //| 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 i,pos=0; double noise=0.000000001,AMA,AMA0,signal,ER; double dSC,ERSC,SSC,ddK; //if (prevbars==rates_total) return (0); //---- TODO: add your code here slowSC=(2.0 /(nslow+1)); fastSC=(2.0 /(nfast+1)); //cbars=IndicatorCounted(prev_calculated); if(prev_calculated>0) cbars=prev_calculated-1; if(prev_calculated==0) cbars=0; cbars=0; //Print(cbars); if(rates_total<=(periodAMA+2)) return(0); //---- check for possible errors if(cbars<0) return(-1); //---- last counted bar will be recounted if(cbars>0) cbars--; pos=periodAMA+2; AMA0=close[pos-1]; if(rates_total>prev_calculated) { while(pos<rates_total) { if(pos==periodAMA-2) AMA0=close[pos-1]; signal=MathAbs (close[pos]-close[pos-periodAMA]); noise=0.000000001; for(i=0; i< periodAMA; i++) { noise=noise+MathAbs(close[pos-i]-close[pos-i-1]); } ER =signal/noise; dSC=(fastSC-slowSC); ERSC=ER*dSC; SSC=ERSC+slowSC; AMA=AMA0+(MathPow (SSC, G)*(close[pos]-AMA0)); kAMAbuffer[pos]=AMA; ddK=(AMA-AMA0); if((MathAbs(ddK))>(dK*_Point) && (ddK>0)) kAMAupsig[pos]=AMA; else kAMAupsig[pos]=0; if((MathAbs(ddK))>(dK*_Point) &&(ddK<0)) kAMAdownsig[pos]=AMA; else kAMAdownsig[pos]=0; AMA0=AMA; pos++; } } prevbars=rates_total; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| TradeTransaction function | //+------------------------------------------------------------------+ void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { //--- } //+------------------------------------------------------------------+
You know guys, there's AMA in MetaEditor. All we have to do is add a dots in it.
;D
You know guys, there's AMA in MetaEditor. All we have to do is add a dots in it.
;D
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
My problem is <video link deleted>
All standard indicators run very fast in visual testing mode,
but my converted from mql4 to mql5 ama custom indicator is very slow during visual testing even if I use 1 minute input not ticks
What to do?