Download MetaTrader 5
To add comments, please log in or register
Publish programs in Code Base. Improve your rating!
fxtrader_
247
fxtrader_ 2016.04.13 10:38 

Hi,

I would like to ask if there is any existing indicator or any way to find statistic Oscillators previous crossed.

More explanation in the attached image



whroeder1
13627
whroeder1 2016.04.13 12:35  
FxTrader_: I would like to ask if there is any existing indicator or any way to find statistic Oscillators previous crossed.
Look back bars and check
int find_XX_cross(int iBeg=0){
  for(;iBeg < Bars; ++iBeg){
     bool wasAbove = xx(..., FAST, iBeg+1) > xx(..., SLOW, iBeg+1);
     bool  isAbove = xx(..., FAST, iBeg)   > xx(..., SLOW, iBeg);
     bool hasCrossed = isAbove != wasAbove;
     if(hasCrossed) return iBeg;
  }
/////
int Last_Crossed = find_XX_cross();
int Prev_Cross[2];
Prev_Cross[0]    = find_XX_cross(Last_Crossed+1);
Prev_Cross[1]    = find_XX_cross(Prev_Cross[0]+1);
fxtrader_
247
fxtrader_ 2016.04.13 13:26  

Hi WHRoeder,

Thank you for your reply, I have to many error with the code, I'm new to mql and i couldn't solve it. Please help.


     int find_XX_cross(int iBeg=0)
      
     {
     for(iBeg < Bars; ++iBeg)
       {
        bool wasAbove = xx(iStochastic(NULL,0,15,5,5,MODE_SMA,0,MODE_MAIN,iBeg+1) > xx(iStochastic(NULL,0,15,5,5,MODE_SMA,0,MODE_SIGNAL,iBeg+1)));
        bool  isAbove = xx(iStochastic(NULL,0,15,5,5,MODE_SMA,0,MODE_MAIN,iBeg)   > xx(iStochastic(NULL,0,15,5,5,MODE_SMA,0,MODE_SIGNAL,iBeg)));
        
        bool hasCrossed = isAbove != wasAbove;
        if(hasCrossed) return iBeg;
       }
         /////
         int Last_Crossed = find_XX_cross();
         int Prev_Cross[2];
         Prev_Cross[0]    = find_XX_cross(Last_Crossed+1);
         Prev_Cross[1]    = find_XX_cross(Prev_Cross[0]+1);
     }



Alain Verleyen
Moderator
28627
Alain Verleyen 2016.04.13 14:23  
FxTrader_:

Hi WHRoeder,

Thank you for your reply, I have to many error with the code, I'm new to mql and i couldn't solve it. Please help.

:-D

WHRoeder provides you pseudo code, you need to think and apply it to your case.

whroeder1
13627
whroeder1 2016.04.13 20:26  
FxTrader_: statistic Oscillators previous crossed.

Did you specify what oscillator you're talking about? So of course I couldn't use specific code. So I wrote XX():

bool wasAbove = xx(..., FAST, iBeg+1) > xx(..., SLOW, iBeg+1);
bool  isAbove = xx(..., FAST, iBeg)   > xx(..., SLOW, iBeg);
You replaced FAST and SLOW, with MAIN and SIGNAL. why didn't you follow through and replace xx() with your oscillator also?
bool wasAbove = xx(iStochastic(NULL,0,15,5,5,MODE_SMA,0,MODE_MAIN,iBeg+1) > xx(iStochastic(NULL,0, 15, 5, 5, MODE_SMA, 0, MODE_SIGNAL, iBeg+1)));
bool  isAbove = xx(iStochastic(NULL,0,15,5,5,MODE_SMA,0,MODE_MAIN,iBeg)   > xx(iStochastic(NULL,0, 15, 5, 5, MODE_SMA, 0, MODE_SIGNAL, iBeg)));
/
To add comments, please log in or register