Problems with my EA - HELP ME PLEASE!!

 

Hi, I´m creating my strategy EA, and I can´t configure fine, error 131 and 4107 jumps and  I don´t know what I did wrong. 

Please help me, this is my first EA...

The code is the next:

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

//|                                                      PRIMERO.mq4 |

//|                               Copyright 2022, MQL5 |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2022, Investment Vivendi"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

//--- input parameters

input double      lots = 0.2;

input double      StopLoss = 100;

input double      TakeProfit = 100;

input double      SMA = 0;

input double      SMMA = 0;


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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   


   

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

  }

  

bool compra(){


   double SMA = iMA(NULL,PERIOD_M5,50,0,MODE_SMA,PRICE_CLOSE,0);     //Media Movil Simple de 50 periodos

   double SMMA = iMA(NULL,PERIOD_M5,200,0,MODE_SMMA,PRICE_CLOSE,0);  //Media Movil Suavizada de 200 periodos

   

      if(Close[1] < SMA && SMA < SMMA){

         return true; 

         } else{

            return false;

            }

      

   }

   

 /*

 Arriba para compra: Si el precio es MENOR que la Media Movil simple, y ademas la Media Movil simple es MENOR a 

 la Media Movil suavizada, entonces COMPRO

 */

   

bool venta(){


   double SMA = iMA(Symbol(),PERIOD_M5,50,0,MODE_SMA,PRICE_CLOSE,0);     //Media Movil Simple de 50 periodos

   double SMMA = iMA(Symbol(),PERIOD_M5,200,0,MODE_SMMA,PRICE_CLOSE,0);  //Media Movil Suavizada de 200 periodos

   

      if(Close[1] > SMA && SMA > SMMA){

         return true; 

         } else{

            return false;

            }

      

   }

   

/*

 Arriba para venta: Si el precio es MAYOR que la Media Movil simple, y ademas la Media Movil simple es MAYOR a 

 la Media Movil suavizada, entonces VENDO

 */

 

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

        

      if(compra()== true) {

      int largo = OrderSend(NULL,OP_BUY,NormalizeDouble(lots,4),Ask,0,

      Close[1]-(StopLoss*Point),Close[1]+(TakeProfit*Point),NULL,0,0,clrGreen); 

      

   }


      if(venta()== true) {

      int corto = OrderSend(NULL,OP_SELL,NormalizeDouble(lots,4),Bid,0,

      Close[1]-(StopLoss*Point),Close[1]+(TakeProfit*Point),NULL,0,0,clrRed); 

      

   }

   

  }

  

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


Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.06.12
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

Start by properly inserting your code with the "</>" icon or Alt+S. Don't just copy/paste as normal text. It is difficult to read.

Also read the MQL4 documentation on error 131 and 4107, given that you are posting MQL4 code.

Runtime Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
Runtime Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Runtime Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
 

Sorry, I didn't know how they were placed!

Now I make it more readable!

I have read the errors and tried many ways to correct them as they appear on the web, but none has been useful to me, since when correcting an error, then the other throws me

 
//+------------------------------------------------------------------+
//|                                                      PRIMERO.mq4 |
//|                               Copyright 2022, Investment Vivendi |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Investment Vivendi"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
input double      lots = 0.2;
input double      StopLoss = 10;
input double      TakeProfit = 10;
input double      SMA = 0;
input double      SMMA = 0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
  
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
  
bool compra(){

   double SMA = iMA(NULL,PERIOD_M5,50,0,MODE_SMA,PRICE_CLOSE,0);     //Media Movil Simple de 50 periodos
   double SMMA = iMA(NULL,PERIOD_M5,200,0,MODE_SMMA,PRICE_CLOSE,0);  //Media Movil Suavizada de 200 periodos
   
      if(Close[1] < SMA && SMA < SMMA){
         return true; 
         } else{
            return false;
            }
      
   }
   
 /*
 Arriba para compra: Si el precio es MENOR que la Media Movil simple, y ademas la Media Movil simple es MENOR a 
 la Media Movil suavizada, entonces COMPRO
 */
   
bool venta(){

   double SMA = iMA(Symbol(),PERIOD_M5,50,0,MODE_SMA,PRICE_CLOSE,0);     //Media Movil Simple de 50 periodos
   double SMMA = iMA(Symbol(),PERIOD_M5,200,0,MODE_SMMA,PRICE_CLOSE,0);  //Media Movil Suavizada de 200 periodos
   
      if(Close[1] > SMA && SMA > SMMA){
         return true; 
         } else{
            return false;
            }
      
   }
   
/*
 Arriba para venta: Si el precio es MAYOR que la Media Movil simple, y ademas la Media Movil simple es MAYOR a 
 la Media Movil suavizada, entonces VENDO
 */
 
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
        
      if(compra()== true) {
      int largo = OrderSend(NULL,OP_BUY,NormalizeDouble(lots,4),Ask,0,
      Close[1]-(StopLoss*Point),Close[1]+(TakeProfit*Point),NULL,0,0,clrGreen); 
      
   }

      if(venta()== true) {
      int corto = OrderSend(NULL,OP_SELL,NormalizeDouble(lots,4),Bid,0,
      Close[1]-(StopLoss*Point),Close[1]+(TakeProfit*Point),NULL,0,0,clrRed); 
      
   }
   
  }
  
//+------------------------------------------------------------------+
 
  1. You where asked to use the code button. You should have edited your (original) post, not reposted! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Your code
          if(Close[1] < SMA && SMA < SMMA){
             return true; 
             } else{
                return false;
                }
    Simplified
          return Close[1] < SMA && SMA < SMMA;
              Increase Order after stoploss - MQL4 programming forum #1.3 (2017)

  3.       int largo = OrderSend(NULL,OP_BUY,NormalizeDouble(lots,4),Ask,0,
          Close[1]-(StopLoss*Point),Close[1]+(TakeProfit*Point),NULL,0,0,clrGreen); 

    Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
    5. Cloud Protector Bug? - MQL4 programming forum (2020)