(MQL4) How to code previous or first indicator data?

 

Hi,

I have opened chart and under the bars there is RSI indicator and Moving Average indicator on RSI (not on the bars) as first or previous indicator data.

Question: Can I code the moment when the line of Moving Average cut RSI line or vice versa?

Rgds,

 
Get the RSI values into an array, use iMAonArray to get the MA of the RSI, find the cross.
 

Can I please any MQL SYNTAX example according to following image?



 
WHRoeder:
Get the RSI values into an array, use iMAonArray to get the MA of the RSI, find the cross.
   int i;
   int limit;
   int counted_bars=IndicatorCounted();
   
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
 
   //--- main loops 1 and 2
   for(i=0; i < limit; i++)
      {
        RSIBuffer[i]=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,i);
      }
  
   for(i=0; i < limit; i++)
      {
        MAofRSIBuffer[i]=iMAOnArray(RSIBuffer,0,MAofRSI,0,MA_method,i);
      }
 

search for cross means RSIBuffer[i+1]>MAofRSIBuffer[i+1] and RSIBuffer[i]<MAofRSIBuffer[i]

or    RSIBuffer[i+1]<MAofRSIBuffer[i+1] and RSIBuffer[i]>MAofRSIBuffer[i]

 
deVries:

search for cross means RSIBuffer[i+1]>MAofRSIBuffer[i+1] and RSIBuffer[i]<MAofRSIBuffer[i]

or    RSIBuffer[i+1]<MAofRSIBuffer[i+1] and RSIBuffer[i]>MAofRSIBuffer[i]

or

(RSIBuffer[i+1] - MAofRSIBuffer[i+1]) * (RSIBuffer[i] - MAofRSIBuffer[i]) < 0

or

bool wasAbove = RSIBuffer[i+1] > MAofRSIBuffer[i+1],
      isAbove = RSIBuffer[i]   > MAofRSIBuffer[i],
     isCross  = isAbove != wasAbove;
 
deVries:

search for cross means RSIBuffer[i+1]>MAofRSIBuffer[i+1] and RSIBuffer[i]<MAofRSIBuffer[i]

or    RSIBuffer[i+1]<MAofRSIBuffer[i+1] and RSIBuffer[i]>MAofRSIBuffer[i]


It doesn't work ! In my EA I have created the following function to check MA on RSI ARRAY. But I have only SELL signal.

Following there is my code. What I made wrong?


int CheckMaOnRsi()
{
   int i;
   int limit;
   int counted_bars=IndicatorCounted();
   double RSIBuffer[], MAofRSIBuffer[];   
   
   /* check for possible errors */
   if(counted_bars<0) return(-1);
   
   /* last counted bar will be recounted */
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
 
   /* main loops 1 and 2 */
   for(i=0; i < limit; i++)
      {
        RSIBuffer[i]=iRSI(Symbol(),0,ARRAY_RSI_PERIOD,ARRAY_RSI_PRICE,i);
        MAofRSIBuffer[i]=iMAOnArray(RSIBuffer,0,ARRAY_MA_PERIOD,0,ARRAY_MA_METHOD,i);
        if ((RSIBuffer[i+1] - MAofRSIBuffer[i+1]) * (RSIBuffer[i] - MAofRSIBuffer[i]) < 0) {return(-1);}
        if ((RSIBuffer[i+1] - MAofRSIBuffer[i+1]) * (RSIBuffer[i] - MAofRSIBuffer[i]) > 0) {return(1);}
        
        /*
        
        // OR
        
        if (RSIBuffer[i+1]>MAofRSIBuffer[i+1] && RSIBuffer[i]<MAofRSIBuffer[i]) {return(-1);}
        if (RSIBuffer[i+1]<MAofRSIBuffer[i+1] && RSIBuffer[i]>MAofRSIBuffer[i]) {return(1);}
        */
      }
   

return(0);
}
 
puncher:

It doesn't work ! In my EA I have created the following function to check MA on RSI ARRAY. But I have only SELL signal.

Following there is my code. What I made wrong?


You cannot use Indicator code in an EA.  for example,  IndicatorCounted(),  from here:  https://docs.mql4.com/customind

 "These functions cannot be used in experts and scripts."

 
RaptorUK:


You cannot use Indicator code in an EA.  for example,  IndicatorCounted(),  from here:  https://docs.mql4.com/customind

 "These functions cannot be used in experts and scripts."


Hi RaptorUK, Should I create the separate indicator with the following code? And after create indicator should I use iCustom() funtion in order to use it in my EA ?


  int i;
   int limit;
   int counted_bars=IndicatorCounted();
   
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
 
   //--- main loops 1 and 2
   for(i=0; i < limit; i++)
      {
        RSIBuffer[i]=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,i);
      }
  
   for(i=0; i < limit; i++)
      {
        MAofRSIBuffer[i]=iMAOnArray(RSIBuffer,0,MAofRSI,0,MA_method,i);
      }



 
puncher:

Hi RaptorUK, Should I create the separate indicator with the following code? And after create indicator should I use iCustom() funtion in order to use it in my EA ?

That would probably be the simplest way.
Reason: