I need help from a developer on the error am facing on this EA to run

 
//+------------------------------------------------------------------+
//|                                                          RIS.mq4 |
//|                                                         SUREPIPS |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "SUREPIPS"
#property link      ""
#property version   "1.00"
#property strict

// RSI Levels are from 0-100, select levells for overbought and oversold 
// and the inputs to RSI
input int                     inpRSIprice        = 2;                 // RSI Periods
input ENUM_APPLIED_PRICE      inRSIprice         = PRICE_CLOSE;       //RSI Applied Price

// The levels
input double inpoversoldlevel  = 20.0;      //oversold level
input double inpoverboughlevel = 80.0;       //overbough level   

//Take profit and stop loss as exit criteria for each trade
//A Simple way to exit 
// input double InpTakeProfit       = 0.02;     //Take Profit in currency value
// input double intoploss           = 0.01;     // Stop loss in currency value 

//
// stardand inputs- you should have something like this in every EA
//
input double Inpordersise     = 0.01;                 // order size start small
input string InpTradeComment  = "suurepips";          // Trade comment for information on 
input int    InpMagicNumber   = 829700;              // magic number identifies these trade   

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
   // Event handler called when the expert is restarted-could be for many reasons

   ENUM_INIT_RETCODE result  =  INIT_SUCCEEDED;
   
   result=heckinput();
   if (result!=INIT_SUCCEEDED)      return(result);   //exit if inputs were bad 
  
  // there may be other things to do here, but not in this axample 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+


void OnTick(){
// Even handler called for any price event, price change, new trde, may thing

static bool oversold = false
static bool overbought = false 

if (!NewBar())return;  // only trade on a new bar 

//
// perform anycalculations and analysis here
// Bar 0 is currently open, bar 1 is the most recent closed bar and bar 2 is the bar before the 
 double rsi = iRSI(Symbol(), period, InpRSI periods, InpRSIprice, 1); 
 
 // get the direction of the last bar . This will just give a positive number
 // for up and a negative number for down 
 double direction = iclose(symbol(), period(), 1)-iopen(symbol(), period(), 1);  

// if rsi has crossed the midpoint then clear any old flages
if (rsi>50){ 
   oversold =false;
   } else
   if (rsi<50){ 
   overbought=false;  
   }
   
   // next check if the flags should be set 
   // note not just assignment that comparism to the , value 
   //this keeps any flags alreday set intact
   if (rsi> inpoverboughlevel) overbought = true; 
   if (rsi< inpoversoldlevel) oversold = true; 

// now if there is a flag set and the bar moved in the right dirction make a trade
// trade rule are
// Buy if 
// Oversold is true 
// rsi is greater than oversold (has come out of oversold range)
// last bar wasan up bar 
// sell if 
// overbouht is true
// rsi is lower than overbought (has come out of overbought range)
// last bar was a down bar
   int ticket = 0; 
   if (oversold && (rsi>inpoversoldlevel)&& (dirction>0)){ 
   ticket = orderopen (ORDER_TYPE_BUY, InpStopLoss, InpTakeProfits); 
   oversold = false;  // reset 
   } else 
   if (overbought && (rsi<inpoverboughlevel) && (direction<0)) { 
   ticket = orderopen (ORDER_TYPE_SELL, InpStoploss, InpTakeProfit);
   overbought = false; 
   } 
    
 return;    

//+------------------------------------------------------------------+

ENUM_INIT_RETCODE CheckInput (){

 // put some code here to check any input rueles 
 // I am just going tosay periods must be positve 
  if (InpRSIperiods<=0) return (INIT_PARAMETERS_INCORRECT);  
  
  return (INIT_SUCCEEDED); 
  
}

//
Simple funtion to open a new order
//
int orderopen (ENUM_ORDER_TYPE, Double stoploss, double takeprofit) { 

int      ticket 
double   openprice 
double   stoploss price
double   takeprofit price 

//
// calculate the openprice, take profit and stop losss price based on the order type 
//
if (ordertype==ORDER_TYPE_BUY){ 
 openprice = normalizedouble (symbolonfor,(Symbol(), SYMBOL_ASK), digits()); 
 // ternary operation, becuase it make things long neat 
 // same as saying 
 if (stoplosssprice==0.0){
 // stoplossprice ==0.0
 } else 
 // stioplossprice= normalise double ( openprice-stoploss, digits ()); 
 // }  
 stopLossPrice = (stopLoss==0.0) ? 0.0 : NormalizeDouble (openPrice-stopLoss, Digits()); 
 takProfit     = (takeProfit==0.0) ? 0.0 : NormalizeDouble (openPrice+takeProfit, Digits());
 } else if (orderType== ORDER_TYPE_SELL){ 
 openPrice=NormalizeDouble (symbolinfodouble)(symbol(), SYMBOL_BID), Digits());
 stopLossPrice=(stopLoss==0.0)? 0.0 : NormalizeDouble (openPrice+StopLoss, Digits()); 
 takeProfitPrice=(takeprofit==0.0)?0.0: NormalizeDouble (openprice-takeProfit, Digits());  
 } else{  
 // This function only works with type Buy or Sell
 return (-1); 
 }
 
 Ticket = ordersend (symbol(), orderType, Inpodersize, openprice, 0, stoplossprice, takeprofitprice, intradecomment, inpmaginumber); 
 
 //check return code here if needed
 
 return (ticket); 
 
 }  
 
//
// true/fals Has bar changed 
//
 bool newbar() {
 
 datetime            currentTime = iTime(Symbol(),Period(),0); //get the opening time of the bar 0
 static datetime     periodTime  = currentTime; // initialised to prevent trading on the first bar after  
 bool                result      = (currentTime!=priorTime); // time has changed
 priorTime                       = currentTime; // reset for next time 
 return (result);  
 '}'
 
 
 
  1. Please use the styler in the Editor (Tooly => Styler or Ctrl ,) to 'beautify' your code :)

  2. If your code compiles correctly but does not do what you expect use the debugger:
    https://www.metatrader5.com/en/metaeditor/help/development/debug
    https://www.mql5.com/en/articles/654
    https://www.mql5.com/en/articles/35
    https://www.mql5.com/en/articles/2041
    https://www.mql5.com/en/articles/272
    https://www.mql5.com/en/articles/150

    It is the fastest and easiest way and you learn a lot!!

Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 
//+------------------------------------------------------------------+
//|                                                          RIS.mq4 |
//|                                                         SUREPIPS |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "SUREPIPS"
#property link      ""
#property version   "1.00"
#property strict

// RSI Levels are from 0-100, select levells for overbought and oversold 
// and the inputs to RSI
input int                     inpRSIprice        = 2;                 // RSI Periods
input ENUM_APPLIED_PRICE      inRSIprice         = PRICE_CLOSE;       //RSI Applied Price

// The levels
input double inpoversoldlevel  = 20.0;      //oversold level
input double inpoverboughlevel = 80.0;       //overbough level   

//Take profit and stop loss as exit criteria for each trade
//A Simple way to exit 
// input double InpTakeProfit       = 0.02;     //Take Profit in currency value
// input double intoploss           = 0.01;     // Stop loss in currency value 

//
// stardand inputs- you should have something like this in every EA
//
input double Inpordersise     = 0.01;                 // order size start small
input string InpTradeComment  = "suurepips";          // Trade comment for information on 
input int    InpMagicNumber   = 829700;              // magic number identifies these trade   

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
   // Event handler called when the expert is restarted-could be for many reasons

   ENUM_INIT_RETCODE result  =  INIT_SUCCEEDED;
   
   result=heckinput();
   if (result!=INIT_SUCCEEDED)      return(result);   //exit if inputs were bad 
  
  // there may be other things to do here, but not in this axample 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+


void OnTick(){
// Even handler called for any price event, price change, new trde, may thing

static bool oversold = false
static bool overbought = false 

if (!NewBar())return;  // only trade on a new bar 

//
// perform anycalculations and analysis here
// Bar 0 is currently open, bar 1 is the most recent closed bar and bar 2 is the bar before the 
 double rsi = iRSI(Symbol(), period, InpRSI periods, InpRSIprice, 1); 
 
 // get the direction of the last bar . This will just give a positive number
 // for up and a negative number for down 
 double direction = iclose(symbol(), period(), 1)-iopen(symbol(), period(), 1);  

// if rsi has crossed the midpoint then clear any old flages
if (rsi>50){ 
   oversold =false;
   } else
   if (rsi<50){ 
   overbought=false;  
   }
   
   // next check if the flags should be set 
   // note not just assignment that comparism to the , value 
   //this keeps any flags alreday set intact
   if (rsi> inpoverboughlevel) overbought = true; 
   if (rsi< inpoversoldlevel) oversold = true; 

// now if there is a flag set and the bar moved in the right dirction make a trade
// trade rule are
// Buy if 
// Oversold is true 
// rsi is greater than oversold (has come out of oversold range)
// last bar wasan up bar 
// sell if 
// overbouht is true
// rsi is lower than overbought (has come out of overbought range)
// last bar was a down bar
   int ticket = 0; 
   if (oversold && (rsi>inpoversoldlevel)&& (dirction>0)){ 
   ticket = orderopen (ORDER_TYPE_BUY, InpStopLoss, InpTakeProfits); 
   oversold = false;  // reset 
   } else 
   if (overbought && (rsi<inpoverboughlevel) && (direction<0)) { 
   ticket = orderopen (ORDER_TYPE_SELL, InpStoploss, InpTakeProfit);
   overbought = false; 
   } 
    
 return;    

//+------------------------------------------------------------------+

ENUM_INIT_RETCODE CheckInput (){

 // put some code here to check any input rueles 
 // I am just going tosay periods must be positve 
  if (InpRSIperiods<=0) return (INIT_PARAMETERS_INCORRECT);  
  
  return (INIT_SUCCEEDED); 
  
}

//
Simple funtion to open a new order
//
int orderopen (ENUM_ORDER_TYPE, Double stoploss, double takeprofit) { 

int      ticket 
double   openprice 
double   stoploss price
double   takeprofit price 

//
// calculate the openprice, take profit and stop losss price based on the order type 
//
if (ordertype==ORDER_TYPE_BUY){ 
 openprice = normalizedouble (symbolonfor,(Symbol(), SYMBOL_ASK), digits()); 
 // ternary operation, becuase it make things long neat 
 // same as saying 
 if (stoplosssprice==0.0){
 // stoplossprice ==0.0
 } else 
 // stioplossprice= normalise double ( openprice-stoploss, digits ()); 
 // }  
 stopLossPrice = (stopLoss==0.0) ? 0.0 : NormalizeDouble (openPrice-stopLoss, Digits()); 
 takProfit     = (takeProfit==0.0) ? 0.0 : NormalizeDouble (openPrice+takeProfit, Digits());
 } else if (orderType== ORDER_TYPE_SELL){ 
 openPrice=NormalizeDouble (symbolinfodouble)(symbol(), SYMBOL_BID), Digits());
 stopLossPrice=(stopLoss==0.0)? 0.0 : NormalizeDouble (openPrice+StopLoss, Digits()); 
 takeProfitPrice=(takeprofit==0.0)?0.0: NormalizeDouble (openprice-takeProfit, Digits());  
 } else{  
 // This function only works with type Buy or Sell
 return (-1); 
 }
 
 Ticket = ordersend (symbol(), orderType, Inpodersize, openprice, 0, stoplossprice, takeprofitprice, intradecomment, inpmaginumber); 
 
 //check return code here if needed
 
 return (ticket); 
 
 }  
 
//
// true/fals Has bar changed 
//
 bool newbar() {
 
 datetime            currentTime = iTime(Symbol(),Period(),0); //get the opening time of the bar 0
 static datetime     periodTime  = currentTime; // initialised to prevent trading on the first bar after  
 bool                result      = (currentTime!=priorTime); // time has changed
 priorTime                       = currentTime; // reset for next time 
 return (result);  
 '}'
 
 

Yusuf Yahaya
 

Click on compile at the top of the metaeditor.   Show use the errors you are getting with you compile.


if it compiles with no errors.... then, What exactly is wrong with your EA?  What do you want it to do?  What is it actually doing?


Chris

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Why did you not state what your problem is? Are we supposed to guess? Help you with what? You haven't stated a problem.

  3. Do not post code that will not even compile.

    static bool oversold = false       
    static bool overbought = false     

    No terminating semicolons (throughout the code).

  4. Why did you post your code twice? Which are we supposed to be looking at. Delete one.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  5. Why are your variables static?
    What should the value(s) be if the two conditions are not true?

    Your code.
    if (rsi>50){ 
       oversold =false;
       } else
       if (rsi<50){ 
       overbought=false;  
       }
       if (rsi> inpoverboughlevel) overbought = true; 
       if (rsi< inpoversoldlevel) oversold = true; 
    Simplify
    bool oversold   = rsi <= MathMin(inpoversoldlevel,  50);
    bool overbought = rsi >= MathMax(inpoverboughlevel, 50);
    

Reason: