Hello MQL4 Community. Can you please assist me with the expert advisor code above. I am fairly new to coding so your support will be highly appreciated.
Run your code with the styler. Then you would see that the last posted close bracket belongs to if statement after the OrderSelect. Missing one for the for, if OrdersTotal, and TrailOrder.
Thank you very much William Roeder.
If you don't mind me asking for more support. I would like to ask you and anyone in the Mql4 Community for assistance with my day of week conditions in MQL4. I want to add this condition check as follows.
I did my code research and managed to find the weekday limits from:
"https://www.earnforex.com/guides/optimizing-metatrader-expert-advisor-trade-certain-days-week/"
//+--------------------------------------------------------------------------------------------
if(Hour() == StartHour) // Check if((DayOfWeek()==0 && Sunday==true and 1 through 7.
{
comment = GetDateAndTime();
Code conditions:
I set asexternbool (Global Var)
inputbool Sunday = true;
inputbool Monday = true;
inputbool Tuesday = true;
inputbool Wednesday = true;
inputbool Thursday = true;
inputbool Friday = true;
inputbool Saturday = true;
Optimize based on day of week
if (((TimeDayOfWeek(TimeCurrent()) == 0) && (Sunday)) ||
((TimeDayOfWeek(TimeCurrent()) == 1) && (Monday)) ||
((TimeDayOfWeek(TimeCurrent()) == 2) && (Tuesday)) ||
((TimeDayOfWeek(TimeCurrent()) == 3) && (Wednesday)) ||
((TimeDayOfWeek(TimeCurrent()) == 4) && (Thursday)) ||
((TimeDayOfWeek(TimeCurrent()) == 5) && (Friday)) ||
((TimeDayOfWeek(TimeCurrent()) == 6) && (Saturday)))
{
Entry();
}
Mql4 Date condition:
MqlDateTime dt;
TimeToStruct(TimeCurrent(), dt);
Time position and condition:
if (((dt.day_of_week == 0) && (Sunday)) ||
((dt.day_of_week == 1) && (Monday)) ||
((dt.day_of_week == 2) && (Tuesday)) ||
((dt.day_of_week == 3) && (Wednesday)) ||
((dt.day_of_week == 4) && (Thursday)) ||
((dt.day_of_week == 5) && (Friday)) ||
((dt.day_of_week == 6) && (Saturday)))
{
Entry();
}
//+--------------------------------------------------------------------------------------------
MQL5: linguagem de estratégias de negociação inseridas no Terminal do Cliente MetaTrader 5. A linguagem permite escrever seus próprios sistemas automáticos de negócios, indicadores técnicos, scripts e bibliotecas de funções
'unbalanced parenthese' and 'unexpected end of program' on mql5
this is the code:
// Include necessary libraries#include <Trade\Trade.mqh>
#include <Indicators\Trend.mqh>
// Indicator parametersinputintPeriod = 100;
// Trading variablesdouble Trend;
int ticket;
bool tradeOpened = false;
double StopLoss = 30.0;
double TakeProfit = 50.0;
int MagicNumber = 12345;
// Calculate the moving average on each tickvoidOnTick()
{
// Get the current timedatetime time = TimeCurrent();
Copy code
// Calculate the moving average
Trend = iTrend(NULL, 0, Period, MA_METHOD_EMA, PRICE_CLOSE, 0);
// Check if it's between 7:00 and 9:00 New York timeif (time >= TimeCurrent() - (GetTimeZone() * 60) + TimeHour(7) &&
time <= TimeCurrent() - (GetTimeZone() * 60) + TimeHour(9))
{
// Check if a trade is already openif (!tradeOpened)
{
// Check if the price is above the moving averageif (Ask > Trend)
{
// Open a buy trade
ticket = OrderSend(NULL, ORDER_TYPE_BUY, 1.0, Ask, 10, Ask - StopLoss * Point, Ask + TakeProfit * Point, "My trade", MagicNumber, 0, Green);
// Check if the trade was successfulif (ticket > 0)
{
tradeOpened = true;
}
}
// Check if the price is below the moving averageelseif (Ask < Trend)
{
// Open a sell trade
ticket = OrderSend(NULL, ORDER_TYPE_SELL, 1.0, Ask, 10, Ask + StopLoss * Point, Ask - TakeProfit * Point, "My trade", MagicNumber, 0, Red);
// Check if the trade was successfulif (ticket > 0)
{
tradeOpened = true;
}
}
}
}
// Check if it's after 9:00 New York timeelseif (time > TimeCurrent() - (GetTimeZone() * 60) + TimeHour(9))
{
// Check if a trade is openif (tradeOpened)
{
// Close the tradeif (OrderClose(ticket, 1.0, Ask, 10))
{
tradeOpened = false;
}
}
}
TimeHour takes a datetime and returns the hour. Seven (7) is not a dattime.
ticket = OrderSend(NULL, ORDER_TYPE_SELL, 1.0, Ask, 10, Ask + StopLoss * Point, Ask - TakeProfit * Point, "My trade", MagicNumber, 0, Red);
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, MarketInfodoes not, OrderSenddoes 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.
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. UsingAsk±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread. MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Amine Asaad #: 'unbalanced parenthese' and 'unexpected end of program' on mql5 this is the code:
You posted in the MQL4 section but mention MQL5 — which is it — MQL4 or MQL5?
Except for the include, your code is mostly MQL4 (trade functions), not MQL5.
It is important that you learn to style your code properly and not have so much empty space. Use the built-in code styler in MetaEditor to help you with this.
Pride in making your code look "beautiful" helps to be able to read it more easily and find errors in your code and logic ...
// Include necessary libraries// #include <Trade\Trade.mqh> // <- This is only available in MQL5#include <Indicators\Trend.mqh>
// Indicator parametersinputintPeriod = 100;
// Trading variablesdouble Trend;
int ticket;
bool tradeOpened = false;
double StopLoss = 30.0;
double TakeProfit = 50.0;
int MagicNumber = 12345;
// Calculate the moving average on each tickvoidOnTick()
{
// Get the current timedatetime time = TimeCurrent();
// Copy code // <- This should be a comment and not code// Calculate the moving average
Trend = iTrend(NULL, 0, Period, MA_METHOD_EMA, PRICE_CLOSE, 0);
// Check if it's between 7:00 and 9:00 New York timeif (time >= TimeCurrent() - (GetTimeZone() * 60) + TimeHour(7) &&
time <= TimeCurrent() - (GetTimeZone() * 60) + TimeHour(9))
{
// Check if a trade is already openif (!tradeOpened)
{
// Check if the price is above the moving averageif (Ask > Trend)
{
// Open a buy trade
ticket = OrderSend(NULL, ORDER_TYPE_BUY, 1.0, Ask, 10, Ask - StopLoss * Point, Ask + TakeProfit * Point, "My trade", MagicNumber, 0, Green);
// Check if the trade was successfulif (ticket > 0)
{
tradeOpened = true;
}
}
else// Check if the price is below the moving averageif (Ask < Trend)
{
// Open a sell trade
ticket = OrderSend(NULL, ORDER_TYPE_SELL, 1.0, Ask, 10, Ask + StopLoss * Point, Ask - TakeProfit * Point, "My trade", MagicNumber, 0, Red);
// Check if the trade was successfulif (ticket > 0)
{
tradeOpened = true;
}
}
}
}
else// Check if it's after 9:00 New York timeif (time > TimeCurrent() - (GetTimeZone() * 60) + TimeHour(9))
{
// Check if a trade is openif (tradeOpened)
{
// Close the tradeif (OrderClose(ticket, 1.0, Ask, 10))
{
tradeOpened = false;
}
}
}
}// <- Missing closing brace for OnTick function
However, now that the missing brace has been fixed, you now have to fix all the other errors ...
Code Error generated by the coded copied into MQL4 editor are as follows..;' - unexpected end of program & unbalanced parentheses - Kindly see assist in fixing this errors - See detail source code below:
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thank you :) Had do adjust two other things aswell and got it to run without any errors :)
HELLO im having the same issue , unexpected end of programm and this same parenthesis problem
if openParenthese conditions closeParenthese
Don't post pictures of code, they are too hard to read.
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor
'unbalanced parenthese' and 'unexpected end of program' on mql5
this is the code:
Please note that the line ... " #include <Trade\Trade.mqh> " is for MQL5 not MQL4.
Do you know how to code in MQL4?
Also, please edit your post (don't create a new one) and post your code properly ...
TimeHour takes a datetime and returns the hour. Seven (7) is not a dattime.
Be careful with NULL.
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
You posted in the MQL4 section but mention MQL5 — which is it — MQL4 or MQL5?
Except for the include, your code is mostly MQL4 (trade functions), not MQL5.
It is important that you learn to style your code properly and not have so much empty space. Use the built-in code styler in MetaEditor to help you with this.
Pride in making your code look "beautiful" helps to be able to read it more easily and find errors in your code and logic ...
However, now that the missing brace has been fixed, you now have to fix all the other errors ...
Code Error generated by the coded copied into MQL4 editor are as follows..;' - unexpected end of program & unbalanced parentheses - Kindly see assist in fixing this errors - See detail source code below:
<Incorrectly posted code deleted>