Alert Problem

 

hi

I'm trying to make a simple ea but i have some problems

i want to make an ea with rsi and stochastic; when both indicatros cross 30 level i want  a alram (the same when they cross level 70)

i make this, and id dosen't work

double     SignalBuffer[];
double     MainBuffer [];
int        PrevSignal;
int OnInit()
  {
//---
#define SIGNAL_BAR 1
   
   if(PrevSignal <= 0)
      {
        if(MainBuffer[SIGNAL_BAR] - 30.0 > 0 && 
           30.0 - MainBuffer[SIGNAL_BAR+1] >= 0)
          {
            PrevSignal = 1;
            Alert( iRSI(NULL,0,3,PRICE_CLOSE,0), "BUY");
          }
      }
    if(PrevSignal >= 0)
      {
        if(70.0 - MainBuffer[SIGNAL_BAR] > 0 && 
           MainBuffer[SIGNAL_BAR+1] - 70.0 >= 0)
          {
            PrevSignal = -1;
            Alert(iRSI(NULL,0,3,PRICE_CLOSE,0), "SELL");
          }
      }
      return(0);
  }

 i searched on this formu and on google, but i can't fix the problem

i also read this https://www.mql5.com/en/articles/1448 and other pages  

 

thanks 

 
looper:i make this, and id dosen't work
  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. There are no mind readers here.
  2. double     MainBuffer [];
    int OnInit(){
    :        if(MainBuffer[SIGNAL_BAR] - 30.0 > 0 && 
    If you looked in the log file you would see the "array exceeded" message. Of course it doesn't work. MainBuffer has no size but you try access element 1.
 

i try to fix it, 

extern int RSIPeriod=3;
extern int ApplyTo=0;
extern int OverBought=70;
extern int OverSold=30;
double RSIBuffer[];
double RSIOBBuffer[];
double RSIOSBuffer[];

int start()
  {
   int i;
   RSIBuffer[i]=iRSI(NULL,0,RSIPeriod,ApplyTo,i);
   RSIOBBuffer[i]=OverBought;
   RSIOSBuffer[i]=OverSold;
   i--;
  
      
        if(RSIBuffer[1]<OverBought && RSIBuffer[0]>=OverBought)
          {
           Alert("RSI = "+ RSIBuffer[i]+ ", Sell.");
          }
      
   
      
        if(RSIBuffer[1]>OverSold && RSIBuffer[0]<=OverSold)
          {
            
            Alert("RSI = "+ RSIBuffer[i]+ ", Buy.");
          }
      
      return(0);
    }

 neither this code works

 
looper: i try to fix it, 
double RSIBuffer[];
int start(){
   int i;
   RSIBuffer[i]=iRSI(...);

 neither this code works

  1. WHRoeder: Of course it doesn't work. MainBuffer has no size but you try access element 1.
  2. Exactly where did you resize your array? RSIBuffer has no size but you AGAIN try access a random element (i has no value.)
 

thanks, i fix partly the problem

now the alam works only one time,

after i put on the cross it work one time and then stop working

if i change timeframe it works one more time and then stop

alarm rings only once

 

this is the new code


extern int OverBought=70;
extern int OverSold=30;


int OnInit()
  {
   int        PrevSignal;
   double RSI_0 = iRSI(NULL,0,3,PRICE_CLOSE,0);
   double RSI_1 = iRSI(NULL,0,14,PRICE_CLOSE,1);

   
   if (PrevSignal <= 0)
   {
      
        if(RSI_0 > OverBought && RSI_1 < OverBought)
          {
            PrevSignal = 1;
            Alert("SELL");
          }
      }
    
      if(PrevSignal >= 0)
      {
         if(RSI_0<OverSold && RSI_1 > OverSold)
          {
            PrevSignal = -1;
            Alert("BUY");
          }
          }
      
      return(0);
    }