AMA EMA Crossover sluggish

 

got new issue! sorry to keep asking for help but this one is just simply weird!


MA crossover wrote million times by everyone here...


here is my code but instead of MA crossover i use EMA & AMA cross over i tested as usual work very quick with MA crossover but as soon as i change it one of them to AMA it slow down 

and its not my system i have i7 32gb ram and while checking the process never went above 2% CPU

int OnStart()
  {
     
          
           int SymbTotal=SymbolsTotal(true)-1; // Total of Symbols in Stock

           double MA_Array[];          
           double AMA_Array[];
           
           for(int i = SymbTotal;i >= 0;i--)
           {
                  string SymbName = SymbolName(i,true); //Current Symbol Name

                  Comment("Stocks Counted:",(string)(SymbTotal-i),"/",(string)SymbTotal);
                
                  //MA Calculation                
                  ArraySetAsSeries(MA_Array,true);
                  int MA_Handle = iMA(SymbName,PERIOD_D1,21,0,MODE_EMA,PRICE_CLOSE);
                  CopyBuffer(MA_Handle,0,0,3,MA_Array);
                  //-----------------------------------------------------------------------
                  
           
                  //AMA Calculation
                  ArraySetAsSeries(AMA_Array,true);
                  int AMA_Handle = iAMA(SymbName,PERIOD_D1,10,2,30,0,PRICE_OPEN);
                  CopyBuffer(AMA_Handle,0,0,3,AMA_Array);
                  //-----------------------------------------------------------------------
                  
                  

               if (MA_Array[1]<AMA_Array[1] && MA_Array[0]>AMA_Array[0])
                  {
                      Print(TimeCurrent(),"Number:",(string)i," Name:",SymbName," LastPrice:",iClose(SymbName,PERIOD_D1,0));
                  }
                else
                {
                     Print("Time:",TimeCurrent(),"Counted:",(string)i,"No Crossover on:",SymbName);
                }
                
               // MEM Free
               ArrayFree(MA_Array);
               ArrayFree(AMA_Array);
 
           }
                               
           Comment("Job is Finished");

    return(INIT_SUCCEEDED);
  }

2020.04.14 01:20:55.027 Collector (AUDCAD,H1) Time:2020.04.13 23:50:54 Counted:71 No Cross over on:XAUUSD

2020.04.14 01:33:29.274 Collector (AUDCAD,H1) Time:2020.04.14 00:03:27 Counted:0 No Cross over on:EURUSD


13 minutes to calculate few pairs!

its even worse if use stocks instead of FX Pairs

as matter of collecting historical data i re ran it few times so it can collect whatever needed same result more or less

also Freeing array after each calculation that should be an issue too


so if anyone can me figure it out what's going on i appreciate it

tnX in advance


 
  • If you want to check D1 data, unless you have other good reasons to not do it, run your code on D1.
  • Most probably not related to the speed issue :

Your code is not good. Initializing an indicator handle and using CopyBuffer() on the next statement is likely to give bad results.

You NEED to check the return value of CopyBuffer().

  • Your way to check a crossover is also wrong. What will happen if the 2 values are equals ?
 
Alain Verleyen:
  • If you want to check D1 data, unless you have other good reasons to not do it, run your code on D1.
  • Most probably not related to the speed issue :

Your code is not good. Initializing an indicator handle and using CopyBuffer() on the next statement is likely to give bad results.

You NEED to check the return value of CopyBuffer().

  • Your way to check a crossover is also wrong. What will happen if the 2 values are equals ?

Thank you Alain,

oddly after i changed it to Shift 1, 13 minutes turn to 1 minute! in demo version 2380

thou in my rl broker version 2361 still slow


sorry about H1 thingy actual script as you see on the code is hardcoded script on PERIOD_D1

yeah in my actual code i grab err codes copybuffer return etc just remove them for simplicity sake here,

no error as far as i can see on copybuffer returns

as matter of crossover yeah just wanted not the touching 2 lines but actual crossover


wondering if that slowness is due 2361 or something like that i guess i have to wait till they update the version and recheck it


 
Amirfakhredin Ghanbari:

Thank you Alain,

oddly after i changed it to Shift 1, 13 minutes turn to 1 minute! in demo version 2380

thou in my rl broker version 2361 still slow


sorry about H1 thingy actual script as you see on the code is hardcoded script on PERIOD_D1

yeah in my actual code i grab err codes copybuffer return etc just remove them for simplicity sake here,

no error as far as i can see on copybuffer returns

as matter of crossover yeah just wanted not the touching 2 lines but actual crossover


wondering if that slowness is due 2361 or something like that i guess i have to wait till they update the version and recheck it


An other time post your actual code and don't waste people time.
 
Amirfakhredin Ghanbari:


Example: Bars after the last iMA crossing

How to start with MQL5
How to start with MQL5
  • 2020.04.09
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
Reason: