In MetaEditor use the Styler to format your code so that you can see more easily where you are missing braces and brackets.
- Tools→Styler (Ctrl+,)
Also, when you place the cursor just to the right of a starting brace/bracket or just to the left of an ending one, the editor highlights it and the corresponding one. That will help identify if it's the incorrect one.
You have in fact several errors in your code, not just an unbalanced brace.
EDIT: Next time, don't write such a long title. Put it in the post description text and use a short summary title instead.
// include the file Trade.mqh #include<Trade\Trade.mqh> // Create an instance of Ctrade CTrade trade; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { // Get the Ask price double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); // get the account balance double Balance=AccountInfoDouble(ACCOUNT_BALANCE); // get the account equity double Equity=AccountInfoDouble(ACCOUNT_EQUITY); // if equity and balance are equal if(Equity==Balance) { // buy stop, 100 microlots, 100 points above Ask, no SL, // 30 points TP, no expiration, no date, no comment trade.BuyStop(0.10,Ask+100*_Point,_Symbol,0,Ask+300*_Point,ORDER_TIME_GTC,0,0); } //{ // Get the Ask price Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); // get the account balance Balance=AccountInfoDouble(ACCOUNT_BALANCE); // get the account equity Equity=AccountInfoDouble(ACCOUNT_EQUITY); // if equity and balance are equal if(Equity==Balance) { // sell stop, 100 microlots, 100 points below Ask, no SL, // 300 points TP, no expiration, no date, no comment trade.SellStop(0.10,Ask+100*_Point,_Symbol,0,Ask+300*_Point,ORDER_TIME_GTC,0,0); } // Call the Trailing Stop Module CheckTrailingStop(Ask); } // End of thr OnTick function void CheckTrailingStop(double Ask) { //set the desired Stop Loss to 10 points double SL=NormalizeDouble(Ask-10*_Point,_Digits); //check all open positions for the current symbol for(int i=PositionsTotal()-1; i>0; i--) // count all currency pair positions { string symbol=PositionGetSymbol(i); //get position symbol if(_Symbol==symbol) // if chart symbol equals position symbol { //Get the ticket number ulong PositionTicket=PositionGetInteger(POSITION_TICKET); // get the current Stop Loss double CurrentStopLoss=PositionGetDouble(POSITION_SL); //If current Stop Loss is below 200 points from Ask Price if(CurrentStopLoss<SL) { // Modify the Stop Loss by 20 Points trade.PositionModify(PositionTicket,(CurrentStopLoss+20*_Point),0); } } /// End symbol if loop } // End for loop } // End Trailing Stop function
Account_BALANCE
is wrong It should be
// get the account balance Balance=AccountInfoDouble(ACCOUNT_BALANCE); // get the account equity Equity=AccountInfoDouble(ACCOUNT_EQUITY);
{ // Get the Ask price ⋮ if (Equity==Balance) { // sell stop, 100 microlots, 100 points below Ask, no SL, // 300 points TP, no expiration, no date, no comment trade.SellStop(0.10,Ask+100*_Point,_Symbol,0,Ask+300*_Point,ORDER_TIME_GTC,0,0); } // Call the Trailing Stop Module CheckTrailingStop(Ask); } // End of thr OnTick function
That bracket is NOT the end of OnTick function. It is the end of the open bracket.
Hi all, I coded a simple buy stop and sell stop with a trailing stop but keep getting '}' unexpected end of program and '{' unbalanced parentheses. I've attached the code above. Thank you in advance.
Can anyone help?
<Title edited by moderator>
In MetaEditor use the Styler to format your code so that you can see more easily where you are missing braces and brackets.
- Tools→Styler (Ctrl+,)
Also, when you place the cursor just to the right of a starting brace/bracket or just to the left of an ending one, the editor highlights it and the corresponding one. That will help identify if it's the incorrect one.
You have in fact several errors in your code, not just an unbalanced brace.
EDIT: Next time, don't write such a long title. Put it in the post description text and use a short summary title instead.
In MetaEditor use the Styler to format your code so that you can see more easily where you are missing braces and brackets.
- Tools→Styler (Ctrl+,)
Also, when you place the cursor just to the right of a starting brace/bracket or just to the left of an ending one, the editor highlights it and the corresponding one. That will help identify if it's the incorrect one.
You have in fact several errors in your code, not just an unbalanced brace.
EDIT: Next time, don't write such a long title. Put it in the post description text and use a short summary title instead.
- 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 all, I coded a simple buy stop and sell stop with a trailing stop but keep getting '}' unexpected end of program and '{' unbalanced parentheses. I've attached the code above. Thank you in advance.
Can anyone help?
<Title edited by moderator>