Download MetaTrader 5
To add comments, please log in or register
Develop applications to order. Make profit using Freelance service!
Piotr
1258
Piotr 2013.04.18 19:06 

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,

whroeder1
13644
whroeder1 2013.04.18 20:14  
Get the RSI values into an array, use iMAonArray to get the MA of the RSI, find the cross.
Piotr
1258
Piotr 2013.04.19 08:48  

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



Tjipke de Vries
6282
Tjipke de Vries 2013.04.19 09:59  
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]

whroeder1
13644
whroeder1 2013.04.19 12:58  
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;
Piotr
1258
Piotr 2013.04.24 09:52  
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);
}
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.04.24 10:03  
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."

Piotr
1258
Piotr 2013.04.24 10:37  
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);
      }



Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.04.24 10:46  
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.
/
To add comments, please log in or register