MQL5 : gg trend bar with iMA.

 

Hello,
I am trying to do a remake of the famous gg trend bar in MQL5.
I failed for now, because the parameters for iMA are not the same anymore.

I tried to understand with the documentation, but with no success.
If i could not do it, i have to redo my own moving average with array (not ideal and loss of time)

Can you help me very please.

for(i=0;i<NumberOfPairs;i++)
    {
      for(j=0;j<tfnumber;j++)
      {
        cl0_prc=iClose(Pairs[i],tframe[j],0);
        moving_avg=iMA(Pairs[i],tframe[j],sma_fast_period,MA_shift,MODE_SMA,PRICE_CLOSE);

        // mql4 was --->
	moving_avg=iMA(Pairs[i],tframe[j],sma_fast_period,MA_shift,MODE_SMA,PRICE_CLOSE,shift);

        //+--- Trd
        if      (cl0_prc>moving_avg) // up
        {
            Valu_Trd[i][j]=1;
        }
        else if (cl0_prc<moving_avg) // down
        {
            Valu_Trd[i][j]=-1;
        }
        else Valu_Trd[i][j]=0; // range
      }
    }
 
Email Temporaire:I am trying to do a remake of the famous gg trend bar in MQL5. I failed for now, because the parameters for iMA are not the same anymore. I tried to understand with the documentation, but with no success. If i could not do it, i have to redo my own moving average with array (not ideal and loss of time).

In MQL5 you can't use iMA() directly. You first need to obtain a handle in OnInit() and then use CopyBuffer() to get the value. Please read the documentation for an example.

 
Yes, i already see your theorical explaination in some others posts, and I read the documentation; but i need more help, as i am not so skilled in coding.
If you can help more...
Thanks
 
Email Temporaire #: Yes, i already see your theorical explaination in some others posts, and I read the documentation; but i need more help, as i am not so skilled in coding. If you can help more...

Read this thread from start to end ... iMa in to Expert advisor whit shift MQL5

 
Thank you.
 
Email Temporaire #: Thank you.
You are welcome!
 
Fernando Carreiro #:
You are welcome!

Thank you VERY much.
I succeed after a whole day.

for(i=0;i<NumberOfPairs;i++)
    {
      for(j=0;j<tfnumber;j++)
      {
        cl0_prc=iClose(Pairs[i],tframe[j],0);
        
        //+--- test iMA
        sma_fast_handle = iMA(Pairs[i],tframe[j],sma_fast_period,shift,MODE_SMA,PRICE_CLOSE);
        ArraySetAsSeries(sma_fast_to_copy,true);
        CopyBuffer(sma_fast_handle,0,0,1,sma_fast_to_copy);
        sma_fast=sma_fast_to_copy[0];

        //+--- Trd
        if      (cl0_prc>sma_fast) // up
        {
            Valu_Trd[i][j]=1;
        }
        else if (cl0_prc<sma_fast) // down
        {
            Valu_Trd[i][j]=-1;
        }
        else Valu_Trd[i][j]=0; // range
      }
    }
Reason: