loop moving averge

 

Hello
I am a beginner in mql5 and I block on a piece of code ...
I am looking to loop on 2 moving averages to know a trend but the results are always zero. Can you tell me if my code is correct or not please



int i;
int TrendUp;
int TrendDown;
int TrendUpTest;
int TrendDownTest; 

for( i = 0; i <= (NomberPeriod+1); i++){
   
      if(SelectTypeTrend == 1){
         if( iMA(Currency, TimeFrame,mact_period,mact_shift,mact_Method,i) > iMA(Currency, TimeFrame,malt_period,malt_shift,malt_Method,i) ){
            TrendUpTest ++;
            if (TrendUpTest == NomberPeriod){
               TrendUp = 1;
               break;
            }else{
               TrendUp = 0;
            }
         }   
         if( iMA(Currency, TimeFrame,mact_period,mact_shift,mact_Method,i) < iMA(Currency, TimeFrame,malt_period,malt_shift,malt_Method,i) ){
            TrendDownTest++;
            if (TrendDownTest == NomberPeriod){
               TrendDown = 1;
               break;
            }else{
               TrendDown = 0;
            }      
         
         }
      }
}


 
no one to help me ....
 
JohnSmith77:

Hello
I am a beginner in mql5 and I block on a piece of code ...
I am looking to loop on 2 moving averages to know a trend but the results are always zero. Can you tell me if my code is correct or not please


Mql5 iMA() returns a handle, check out https://www.mql5.com/en/docs/indicators/ima.

Documentation on MQL5: Technical Indicators / iMA
Documentation on MQL5: Technical Indicators / iMA
  • www.mql5.com
//|                                                     Demo_iMA.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | "The method of creation of the handle is set through the 'type' parameter (function type...
 

no its not correct

you have to do the handle of indicator in OnInit and CopyBuffer in OnTick.

The values for MA will be written in an Array. this Array you have to define on Global space.

Even you have to set ArrayAsSerias in OnInit.


your Style if from MQL4, this not working on MQL5

 
Thanks, I'm going to watch this;)
Reason: