Add simple filter to alert

 

Hi everyone, I would like to add a level filter to an indicator for mt5. It is a RVI alert and I just want to add a simple level filter (send alert when rvi cross above/below certain levels).


Here the code:

//Check if it is a trade Signla 0 - Neutral, 1 - Buy, -1 - Sell
ENUM_TRADE_SIGNAL IsSignal(int i){
   int j=i+Shift;
   if(AlertSignal==RVI_ZERO_CROSS){
      if(BufferMain[j+1]<0 && BufferMain[j]>0) return SIGNAL_BUY;
      if(BufferMain[j+1]>0 && BufferMain[j]<0) return SIGNAL_SELL;
   }
   if(AlertSignal==RVI_MAIN_SIGNAL_CROSS){
      if(BufferMain[j+1]<BufferSignal[j+1] && BufferMain[j]>BufferSignal[j]) return SIGNAL_BUY;
      if(BufferMain[j+1]>BufferSignal[j+1] && BufferMain[j]<BufferSignal[j]) return SIGNAL_SELL;
   }

   return SIGNAL_NEUTRAL;
}

I am using the RVI_MAIN_SIGNAL_CROSS, not the first one, and I tried to add this:

   if(AlertSignal==RVI_MAIN_SIGNAL_CROSS){
      if(BufferMain[j+1]<BufferSignal[j+1]<-0.40 && BufferMain[j]>BufferSignal[j]<-0.40) return SIGNAL_BUY;
      if(BufferMain[j+1]>BufferSignal[j+1]>0.40 && BufferMain[j]<BufferSignal[j]>0.40) return SIGNAL_SELL;

But it doesn't work.


How should I add those levels?


Thank you

 
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. 2004
              When asking about code

  2. if(BufferMain[j+1]<BufferSignal[j+1]<-0.40

    This is meaningless. True = non-zero and false = zero so you get:

    if( 3 < 2 < 1 )
    if( false < 1 )
    if(     0 < 1 )
    if(     true  )
    if( 3 > 2 > 1 )
    iftrue > 1 )
    if(     1 > 1 )
    if(     false )
    
  3. If you want the alert when the main crosses your level, go back to the original code and replace Signal with your level,
 

I'm sorry William. Coding is not my world.


- This indicator already send an alert when RVI Signal cross RVI Main (as I understand this rule is set here at RVI_MAIN_SIGNAL_CROSS);

- If you open RVI you see that those 2 line oscillate in a range. What I would like is just to add level filter: if I set level to 0.10 and -0.10 then the crossing of the 2 lines must occur above or below this level to activate the alert.If the cross occur (for example) @ 0.056 then nothing happen.


When I say "doesn't work" I mean that I still receive all alert from any level after my modify. 


I hope this sound more clear now.

Thank you

Reason: