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.
- docs.mql4.com
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); } } //+------------------------------------------------------------------+
-
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 Your code if(Close[1] < SMA && SMA < SMMA){ return true; } else{ return false; }
Simplified return Close[1] < SMA && SMA < SMMA;
-
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.
- 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.
- 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.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- Cloud Protector Bug? - MQL4 programming forum (2020)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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);
}
}
//+------------------------------------------------------------------+