-
Code it correctly. Did you show your code and specify what line the error is on? Or do you expect us to download compile and fix your numerous errors?
-
Print("EDGE Alert+"+Symbol()+TimeCurrent()); } { if(sim[1] = "EURGBP"; strength[4]=strength[5]) Signal=Signal_Buy; if(sim[2] ="EURJPY"; strength[4]=strength[5]) Signal=Signal_Buy;
That's not a comparison inside the if - it's an assignment of "EURGBP" to sim[1]. Etc. - The format of an if statement is not “if(condition; statement)”. It's "if(condition) statement;”
' if (example[0]>12 && b!=5) {}'
or
'if (c==45) b=45+z;'
';' not available!!!
hello, good morning, a query gives me this error in my expert advisor code, it's a prototype and its operation is simple, I just want to experiment, but I can't make it compile because of this error: '{' - function definition unexpected Primitive 2.mq5 32 1 annex code:
<Incorrectly posted code deleted>
-
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 -
void OnTick() { // Calcula las MAs double ma1_val = iMA(NULL, TimeFrame, ma1, 0, MODE_SMA, PRICE_CLOSE); double ma2_val = iMA(NULL, TimeFrame, ma2, 0, MODE_SMA, PRICE_CLOSE); double ma3_val = iMA(NULL, TimeFrame, ma3, 0, MODE_SMA, PRICE_CLOSE); } <<<<<<<<<<<<<<<< This terminates OnTick { <<<<<<<<<<<<<<<< This begins code not in a function. // Muestra las MAs en el gráfico handle1 = iMAOnArray(handle1, 0, ma1_val, ma1, 0, MODE_SMA, PRICE_CLOSE, BLUE);
William Roeder #
I'm going to attach it in a better way, I'm sorry, it's the first time doing this type of query
//+------------------------------------------------------------------+ //| Primitivo 2.mq5 | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "M" #property version "1.00" #property strict #include <Trade/Trade.mqh> #include <Graph/Graph.mqh> // gestion de riesgo input double TakeProfit = 1.5; // Take Profit en dólares input double StopLoss = 0.50; // Stop Loss en dólares input ENUM_TIMEFRAMES TimeFrame = PERIOD_M5; // Marco temporal de 5 minutos int ma1 = 5; // Período de la Media Móvil 1 (5 periodos) int ma2 = 20; // Período de la Media Móvil 2 (20 periodos) int ma3 = 200; // Período de la Media Móvil 3 (200 periodos) int handle1, handle2, handle3; // Identificadores de las MAs int handle4, handle5; // Identificadores de las restricciones // Define el número máximo de operaciones diarias int max_daily_trades = 30; int trades_today = 0; // Define el número máximo de operaciones con take profit int max_take_profit_trades = 30; int take_profit_trades = 0; // Define el número máximo de operaciones con stop loss int max_stop_loss_trades_24h = 10; int max_stop_loss_trades_48h = 25; int stop_loss_trades_24h = 0; int stop_loss_trades_48h = 0; void OnTick() { // Verificar si se ha alcanzado el número máximo de operaciones diarias if (trades_today >= max_daily_trades) { // Detener el bot durante 24 horas Sleep(24*60*60*1000); trades_today = 0; take_profit_trades = 0; stop_loss_trades_24h = 0; stop_loss_trades_48h = 0; } // Verificar si se ha alcanzado el número máximo de operaciones con take profit if (take_profit_trades >= max_take_profit_trades) { // Cerrar todas las operaciones abiertas for (int i = 0; i < OrdersTotal(); i++) OrderClose(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)); take_profit_trades = 0; } // Verificar si se ha alcanzado el número máximo de operaciones con stop loss en 24 horas if (stop_loss_trades_24h >= max_stop_loss_trades_24h) { // Detener el bot durante 24 horas Sleep(24*60*60*1000); stop_loss_trades_24h = 0; } { // Verificar si se ha alcanzado el número máximo de operaciones con stop loss en 48 horas if (stop_loss_trades_48h >= max_stop_loss_trades_48h) } { // Obtener el próximo lunes datetime nextMonday = NextMonday(); int diff = nextMonday - TimeCurrent(); // Detener el bot hasta el próximo lunes Sleep(diff); stop_loss_trades_48h = 0; } // Aumentar el contador de operaciones diarias trades_today++; // Si la operacion se cierra con take profit if (OrderProfit() > 0) { take_profit_trades++; } // Si la operacion se cierra con stop loss if (OrderProfit() < 0) { stop_loss_trades_24h++; stop_loss_trades_48h++; } // Función principal void OnTick() { // Calcula las MAs double ma1_val = iMA(NULL, TimeFrame, ma1, 0, MODE_SMA, PRICE_CLOSE); double ma2_val = iMA(NULL, TimeFrame, ma2, 0, MODE_SMA, PRICE_CLOSE); double ma3_val = iMA(NULL, TimeFrame, ma3, 0, MODE_SMA, PRICE_CLOSE); // Muestra las MAs en el gráfico handle1 = iMAOnArray(handle1, 0, ma1_val, ma1, 0, MODE_SMA, PRICE_CLOSE, BLUE); handle2 = iMAOnArray(handle2, 0, ma2_val, ma2, 0, MODE_SMA, PRICE_CLOSE, YELLOW); handle3 = iMAOnArray(handle3, 0, ma3_val, ma3, 0, MODE_SMA, PRICE_CLOSE, WHITE); // Modifica el color de las velas alcistas y bajistas SetCandleColor(GREEN, RED); // Modifica el color del fondo del gráfico SetChartBkColor(BLACK); // Restricciones para no abrir operaciones if (ma3_val > iClose(NULL, TimeFrame, 1)) // Restricciones para no abrir operaciones if (ma3_val > iClose(NULL, TimeFrame, 1)) handle4 = DrawLine(handle4, 0, ma3_val, TimeFrame, iClose(NULL, TimeFrame, 1), TimeFrame, "Follow MA200", RED); else if (ma3_val < iClose(NULL, TimeFrame, 1)) handle5 = DrawLine(handle5, 0, ma3_val, TimeFrame, iClose(NULL, TimeFrame, 1), TimeFrame, "Follow MA200", RED); // Si no se cumple ninguna de las restricciones, se abren operaciones if (ma3_val != iClose(NULL, TimeFrame, 1)) // Si la Media Móvil 1 cruza de abajo hacia arriba la Media Móvil 2, se abre una operación larga if (ma1_val > ma2_val && ma1_val < ma2_val) Buy(Symbol(), 0.01, Ask, StopLoss, TakeProfit, "My EA"); // Si la Media Móvil 1 cruza de arriba hacia abajo la Media Móvil 2, se abre una operación corta if (ma1_val < ma2_val && ma1_val > ma2_val) Sell(Symbol(), 0.01, Bid, StopLoss, TakeProfit, "My EA"); // Define los periodos de la Media Móvil int ma_periods = 200; // Define el precio de cierre double ma_val = iMA(NULL, TimeFrame, ma_periods, 0, MODE_SMA, PRICE_CLOSE); // Verificar si la tendencia está por encima de la Media Móvil de 200 periodos if (Close[0] > ma_val) // Apertura solo de operaciones de compra (largo) if (ma1_val > ma2_val && ma1_val < ma2_val) Buy(Symbol(), 0.01, Ask, StopLoss, TakeProfit, "My EA"); // Verificar si la tendencia está por debajo de la Media Móvil de 200 periodos else if (Close[0] < ma_val) // Apertura solo de operaciones de venta (corto) if (ma1_val < ma2_val && ma1_val > ma2_val) Sell(Symbol(), 0.01, Bid, StopLoss, TakeProfit, "My EA"); // Si la tendencia no está ni por encima ni por debajo de la Media Móvil de 200 periodos else // No abrir operaciones //Define los pares de divisas string symbol_list[] = {"EURUSD", "GBPUSD", "USDCHF", "USDJPY", "USDCAD"}; //define el lotaje de operacion double lot_size = 0.01; //Función para abrir una orden void openOrder(int type, double lots) for(int i=0;i<ArraySize(symbol_list);i++) if(symbol() == symbol_list[i]) OrderSend(symbol_list[i], type, lots, Ask, 3, 0, 0, "My EA", 0, 0, clrNONE); }
-
void OnTick() { // Calcula las MAs double ma1_val = iMA(NULL, TimeFrame, ma1, 0, MODE_SMA, PRICE_CLOSE); double ma2_val = iMA(NULL, TimeFrame, ma2, 0, MODE_SMA, PRICE_CLOSE); double ma3_val = iMA(NULL, TimeFrame, ma3, 0, MODE_SMA, PRICE_CLOSE);
MT5 code. Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010) -
OrderSend(symbol_list[i], type, lots, Ask, 3, 0, 0, "My EA", 0, 0, clrNONE);
MT4 code.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am consistently getting the above error message. When I do not include the '{' I get multitudes of error messages saying if expressions not allowed on a global scope
Is there any solution to this?