having a problem getting a crossover and crossbelow signal in my rsi ea

 
input ENUM_TIMEFRAMES RSItimeframe = PERIOD_CURRENT;
input int RSIPeriod = 4;
input double RSIHighLevel = 80;
input double RSILowLevel = 20;
input ENUM_APPLIED_PRICE RSIAppliedPrice = PRICE_CLOSE;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
input int Takeprofit = 500;
input int Stoploss = 250;
input double Lots = 0.01;
//+------------------------------------------------------------------+
//|// Global Variables//                                             |
//+------------------------------------------------------------------+
double RSICurrentMain = iRSI(NULL,RSItimeframe, RSIPeriod, RSIAppliedPrice, 1);
double RSIPreviousMain = iRSI(NULL, RSItimeframe, RSIPeriod, RSIAppliedPrice, 2);
double Takeprofitlevel = Ask + Takeprofit*Point;
double Stoplosslevel = Bid - Stoploss*Point;

void OnTick()

{
   
   if(RSICurrentMain < RSILowLevel && RSIPreviousMain > RSILowLevel)
      {
      
         int BuyID = OrderSend(NULL, OP_BUY, Lots, Ask, 10,Stoplosslevel, Takeprofitlevel);     
         
         
         if(BuyID > 0)
            {
               Print("Error sending # " + string (BuyID));
            }
         else
            {
               Print("Order sent successfully");
            }
            
      }
    else if (RSICurrentMain > RSIHighLevel && RSIPreviousMain < RSIHighLevel)
      {
      
         int SellID = OrderSend(NULL, OP_SELL, Lots, Bid, 10,Stoplosslevel, Takeprofitlevel);
         
         
         if(SellID > 0)
            {
               Print("Error sending # " + string (SellID));
            }
         else
            {
               Print("Order sent successfully");
            }
            
      }
    else
      {      
            
      }
      
}
//+------------------------------------------------------------------+
 
//+------------------------------------------------------------------+
//|// Global Variables//                                             |
//+------------------------------------------------------------------+
double RSICurrentMain = iRSI(NULL,RSItimeframe, RSIPeriod, RSIAppliedPrice, 1);
double RSIPreviousMain = iRSI(NULL, RSItimeframe, RSIPeriod, RSIAppliedPrice, 2);
double Takeprofitlevel = Ask + Takeprofit*Point;
double Stoplosslevel = Bid - Stoploss*Point;

These values will not be changed.

You need to set them in OnTick()

 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum #2 (2013)