'}' - unexpected end of program test.mq5 164 1 and '{' - unbalanced parentheses test.mq5 41 1 - page 2

 
Icham Aidibe:

The parenthesis are correctly opened at line 41 and close at line 164, but there, you are confused : 

HI Icham, 

Great help, thank you very much.

Great you pointed out the mistake,as i am new to MQL, this will help me learn and code in a much proper way.

thank very much

 
spike thunder:

HI Icham, 

Great help, thank you very much.

Great you pointed out the mistake,as i am new to MQL, this will help me learn and code in a much proper way.

thank very much

you welcome, that's how one learn  👍 

MQL looks like the C++ so ....

if(condition) { function(); }
else { otherfunction(); }

for(int x=0;x<size;x++) { function(); }

... is a must-know.
 
Icham Aidibe:

you welcome, that's how one learn  👍 

MQL looks like the C++ so ....

... is a must-know.

thank you

 
Vladimir Karputov:

First, please correct your code - move the creation of the indicator handle to OnInit (please start reading the Documentation - there are lots of examples there). After that show your code. And only then can I watch.

Sure, am already working on this and looking forward to learn some other things also.

Thank you

 

I did some cleaning for you with my little knowledge. It is running on strategy tester.

//+------------------------------------------------------------------+
//|                                                       test.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include<Trade\Trade.mqh>
CTrade trade;

//--- input parameters
input int      iMA = 21;
input int      TakeProfit = 250;
input int      SL = 250;
input int      TrailingStop = 10;
int movingAverageDefinition;
bool bullish;
bool bearish;
//+------------------------------------------------------------------+
//|                                                       test.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include<Trade\Trade.mqh>
CTrade trade;

//--- input parameters
input int      iMA = 21;
input int      TakeProfit = 50;
input int      SL = 1000;
input int      TrailingStop = 10;
int movingAverageDefinition;
bool bullish;
bool bearish;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
movingAverageDefinition = iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE);

bullish = iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0);
bearish = iClose(_Symbol,PERIOD_CURRENT,0) <  iOpen(_Symbol,PERIOD_CURRENT,0);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {


  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()

  {
//------------(line 41)


   double myMovingAverageArray[];
   
   ArraySetAsSeries(myMovingAverageArray,true);
   CopyBuffer(movingAverageDefinition,0,0,21,myMovingAverageArray);
   double myMovingAverageValue=myMovingAverageArray[0];
   
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

      // ----------------buy------------------------------------
      if(PositionsTotal()<4)
      {
      if(iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0) > (myMovingAverageArray[0]))
        {
         trade.Buy(0.10,NULL,Ask,(Ask-1000*_Point),(Ask+1000*_Point),NULL);
         //CheckTrailingStop();
        }
                   // return(false);

         //--------------------sell------------------------------------
           if(iClose(_Symbol,PERIOD_CURRENT,0) < iOpen(_Symbol,PERIOD_CURRENT,0) < (myMovingAverageArray[0]))

           {
            trade.Sell(0.10,NULL,Bid,(Bid+1000*_Point),(Bid-1000*_Point),NULL);
            // CheckTrailingStop();
              //return(false);

              }
            }
     } //------------------------------ (line 164
//+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ int OnInit()   { //--- movingAverageDefinition = iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE); bullish = iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0); bearish = iClose(_Symbol,PERIOD_CURRENT,0) <  iOpen(_Symbol,PERIOD_CURRENT,0); //---    return(INIT_SUCCEEDED);   } //+------------------------------------------------------------------+ //| Expert deinitialization function                                 | //+------------------------------------------------------------------+ void OnDeinit(const int reason)   {   } //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ void OnTick()   { //------------(line 41)    double myMovingAverageArray[];       ArraySetAsSeries(myMovingAverageArray,true);    CopyBuffer(movingAverageDefinition,0,0,21,myMovingAverageArray);    double myMovingAverageValue=myMovingAverageArray[0];       double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);    double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);       // ----------------buy------------------------------------       if(iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0) > (myMovingAverageArray[0]))         {          trade.Buy(0.10,NULL,Ask,(Ask-1000*_Point),0,NULL);          //CheckTrailingStop();         }                    // return(false);          //--------------------sell------------------------------------            if(iClose(_Symbol,PERIOD_CURRENT,0) < iOpen(_Symbol,PERIOD_CURRENT,0) < (myMovingAverageArray[0]))            {             trade.Sell(0.10,NULL,Bid,(Bid+1000*_Point),0,NULL);             // CheckTrailingStop();               //return(false);               }      } //------------------------------ (line 164
 
Gerald Masese:

I did some cleaning for you with my little knowledge. It is running on strategy tester.

hello Gerald,

Great thanks for your kindness and great help. I have also try it on strategy tester, indeed this is working great. 

Thank you very much

 
bullish = iClose(_Symbol,PERIOD_CURRENT,0) > iOpen(_Symbol,PERIOD_CURRENT,0);
bearish = iClose(_Symbol,PERIOD_CURRENT,0) <  iOpen(_Symbol,PERIOD_CURRENT,0);

Don't try to use any price or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 

Hello guys, plz can someone help with this two  errors and one wornings 

 error 1:  '{' - unbalanced parentheses

  void OnTick() {


Error 2: 

'}' - unexpected end of program

// Close all open trades

    CloseAll();

}



Warnings :

truncation of constant value

Best regards ):



Files:
 
Faycal Zaidi #: s, plz can someone help with this two  errors and one wornings
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    Always post all relevant code (using Code button) or attach the source file.
  2. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

 
Hello team, I urgently need your help for this problem which I am sure is very small for you, so please solve it for me, it’s nice!