Off-topic posts - page 94

 
Open a real account of metatrader 5
 
How can I start trading 
 
Hi guys , when I compile the error code , I always get the error : unexpected end of program. how can I fix it ? 
CTrade trade;
input ENUM_TIMEFRAMES tf = PERIOD_CURRENT;
input int periods = 20;
input double dev = 2.0;
input string expire = "03:00";
input ENUM_APPLIED_PRICE pr = PRICE_CLOSE;
int handlebb;
/// add values here
int OnInit()
  {
   handlebb = iBands(_Symbol,tf,periods,0,dev,pr);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {


  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   double bbupper[],bblower[],bbmiddle[];
   CopyBuffer(handlebb,BASE_LINE,1,2,bbmiddle);
   CopyBuffer(handlebb,UPPER_BAND,1,2,bbupper);
   CopyBuffer(handlebb,LOWER_BAND,1,2,bblower);
   double low1 = iLow(_Symbol,tf,0);
   double low2 = iLow(_Symbol,tf,1);
   double high1 = iHigh(_Symbol,tf,0);
   double high2 = iHigh(_Symbol,tf,1);
   double close1 = iClose(_Symbol,tf,0);
   double open1 = iOpen(_Symbol,tf,1);

   double low_index = iLowest(_Symbol,tf,MODE_LOW,10,0);
   double high_index = iHighest(_Symbol,tf,MODE_HIGH,10,0);
   double range = high1 - low1;
   double kt = high1 - (0.3 * range);
   double kt1 = low1 + (0.3 * range);

   double range_value = range  / 2;
   datetime exp = StringToTime(expire);
   if(close1 > open1 || close1 < open1) // bullish or bearish
     {
      double body = close1 > open1 ? close1 - open1 : open1 - close1; // bullish ? then body is that value

      if(low1 < low2 && high1 > high2) // engulfs
        {
         if(body > range_value) // not a weakie
           {
            if((low_index == 0  && at_zone(high1,low1)
           {
            if(at_bands(high1,low1,bbupper,bblower) == "buy")
                 {
                  trade.BuyStop(2.0,high1,_Symbol,low1,high1 + range * 1.2,ORDER_TIME_GTC,exp,"me");
                 }
                 }
               else
                  if(high_index == 0 && at_zone(high1,low1)
                 {
                  if(at_bands(high1,low1,bbupper,bblower) =="sell")
                       {
                        trade.SellStop(2.0,high1,_Symbol,low1,low - range * 1.2,ORDER_TIME_GTC,exp,"me");
                       }
                   }
                   }
                  }
                  }



                  

                  else
                     if((close1 >= kt && open1 >= kt) ||(close1 <= kt1 && open1 <= kt1)  // bullish or bearish kt
                    {
                     if(low_index == 0  && at_zone(high1,low1))
                          {
                           if(at_bands(high1,low1,bbupper,bblower) == "buy")
                             {
                              trade.BuyStop(2.0,high1,_Symbol,low1,high1 + range * 1.2,ORDER_TIME_GTC,exp,"me");

                             }
                          }
                        if(high_index = 0 && at_zone(high1,low1)
                       {
                        if(at_bands(high1,low1,bbupper,bblower) == "sell")
                             {
                              trade.SellStop(2.0,high1,_Symbol,low1,low - range * 1.2,ORDER_TIME_GTC,exp,"me");
                             }

                          }
}

                        //+------------------------------------------------------------------+

                        int at_zone(double high,double low)
                          {
                           int v = 0;
                           double zones [] = {123.400,83.444};
                           for(int i=0; i< ArraySize(zones); i++)
                             {
                              if(high > zones[i] && low < zones[i])   // INCLUDE THE PIPS FOR SLIPPAGE, as well as the indication values
                                {
                                 v +=1;
                                }
                             }
                           if(v == 1)
                             {
                              return v;
                             }
                           else
                              return 0;
                          }
                        string at_bands(double high, double low,double ub,double lb)
                          {
                           if((high >= lb && low <= lb) || high < lb)
                             {
                              return "buy";
                             }
                           else
                              if((high >= ub && low <= ub) || low > ub)
                                {
                                 return "sell";
                                }

                          }
                         
                        
 
Joao David Ngululia Buta #: Hi guys , when I compile the error code , I always get the error : unexpected end of program. how can I fix it ? 

Use MetaEditor's Styling function, to style code, so that you can see what the code is missing.

You have missing/unbalance parentheses "{ }" as well as several other coding errors.

Are you perhaps using ChatGPT?

 
Fernando Carreiro #:

Use MetaEditor's Styling function, to style code, so that you can see what the code is missing.

You have missing/unbalance parentheses "{ }" as well as several other coding errors.

Are you perhaps using ChatGPT?

No , I am not using chatgpt. I did style my code. which other several programming errors do you see?

 
@Joao David Ngululia Buta #:No , I am not using chatgpt. I did style my code. which other several programming errors do you see?

Before correcting parentheses ...

'CTrade' - unexpected token, probably type is missing?  test.mq5        6       1
'trade' - semicolon expected    test.mq5        6       8
'}' - unexpected end of program test.mq5        122     6
'{' - unbalanced parentheses    test.mq5        31      3
4 errors, 0 warnings            5       1

After adding closing paranthesis to OnTick() ...

'CTrade' - unexpected token, probably type is missing?  test.mq5        6       1
'trade' - semicolon expected    test.mq5        6       8
'if' - semicolon expected       test.mq5        58      13
'{' - expression expected       test.mq5        57      12
'{' - some operator expected    test.mq5        57      12
'bbupper' - parameter conversion not allowed    test.mq5        58      38
   string at_bands(double,double,double,double) test.mq5        112     11
implicit conversion from 'number' to 'string'   test.mq5        58      16
'==' - some operator expected   test.mq5        58      56
'(' - unbalanced left parenthesis       test.mq5        56      15
'trade' - undeclared identifier test.mq5        60      19
'if' - semicolon expected       test.mq5        66      16
'{' - expression expected       test.mq5        65      15
'{' - some operator expected    test.mq5        65      15
'(' - unbalanced left parenthesis       test.mq5        64      18
'bbupper' - parameter conversion not allowed    test.mq5        66      41
   string at_bands(double,double,double,double) test.mq5        112     11
implicit conversion from 'number' to 'string'   test.mq5        66      19
'trade' - undeclared identifier test.mq5        68      22
'}' - not all control paths return a value      test.mq5        123     6
16 errors, 2 warnings           17      3

After adding "#include <Trade\Trade.mqh>" to beginning of file ...

'if' - semicolon expected       test.mq5        59      13
'{' - expression expected       test.mq5        58      12
'{' - some operator expected    test.mq5        58      12
'bbupper' - parameter conversion not allowed    test.mq5        59      38
   string at_bands(double,double,double,double) test.mq5        113     11
implicit conversion from 'number' to 'string'   test.mq5        59      16
'==' - some operator expected   test.mq5        59      56
'(' - unbalanced left parenthesis       test.mq5        57      15
'if' - semicolon expected       test.mq5        67      16
'{' - expression expected       test.mq5        66      15
'{' - some operator expected    test.mq5        66      15
'(' - unbalanced left parenthesis       test.mq5        65      18
'bbupper' - parameter conversion not allowed    test.mq5        67      41
   string at_bands(double,double,double,double) test.mq5        113     11
implicit conversion from 'number' to 'string'   test.mq5        67      19
'low' - undeclared identifier   test.mq5        69      64
'}' - not all control paths return a value      test.mq5        124     6
13 errors, 2 warnings           14      3

You need to seriously analyse your code and fix all of these. There are still too many unbalanced parentheses.

#include <Trade\Trade.mqh>
CTrade trade;
input ENUM_TIMEFRAMES tf = PERIOD_CURRENT;
input int periods = 20;
input double dev = 2.0;
input string expire = "03:00";
input ENUM_APPLIED_PRICE pr = PRICE_CLOSE;
int handlebb;
/// add values here
//+------------------------------------------------------------------+
int OnInit()
  {
   handlebb = iBands(_Symbol, tf, periods, 0, dev, pr);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   double bbupper[], bblower[], bbmiddle[];
   CopyBuffer(handlebb, BASE_LINE, 1, 2, bbmiddle);
   CopyBuffer(handlebb, UPPER_BAND, 1, 2, bbupper);
   CopyBuffer(handlebb, LOWER_BAND, 1, 2, bblower);
   double low1 = iLow(_Symbol, tf, 0);
   double low2 = iLow(_Symbol, tf, 1);
   double high1 = iHigh(_Symbol, tf, 0);
   double high2 = iHigh(_Symbol, tf, 1);
   double close1 = iClose(_Symbol, tf, 0);
   double open1 = iOpen(_Symbol, tf, 1);
   double low_index = iLowest(_Symbol, tf, MODE_LOW, 10, 0);
   double high_index = iHighest(_Symbol, tf, MODE_HIGH, 10, 0);
   double range = high1 - low1;
   double kt = high1 - (0.3 * range);
   double kt1 = low1 + (0.3 * range);
   double range_value = range  / 2;
   datetime exp = StringToTime(expire);
   if(close1 > open1 || close1 < open1) // bullish or bearish
     {
      double body = close1 > open1 ? close1 - open1 : open1 - close1; // bullish ? then body is that value
      if(low1 < low2 && high1 > high2) // engulfs
        {
         if(body > range_value) // not a weakie
           {
            if((low_index == 0  && at_zone(high1, low1)
           {
            if(at_bands(high1, low1, bbupper, bblower) == "buy")
                 {
                  trade.BuyStop(2.0, high1, _Symbol, low1, high1 + range * 1.2, ORDER_TIME_GTC, exp, "me");
                 }
              }
            else
               if(high_index == 0 && at_zone(high1, low1)
              {
               if(at_bands(high1, low1, bbupper, bblower) == "sell")
                    {
                     trade.SellStop(2.0, high1, _Symbol, low1, low - range * 1.2, ORDER_TIME_GTC, exp, "me");
                    }
                 }
           }
        }
     }
   else
      if((close1 >= kt && open1 >= kt) || (close1 <= kt1 && open1 <= kt1) // bullish or bearish kt
     {
      if(low_index == 0  && at_zone(high1, low1))
           {
            if(at_bands(high1, low1, bbupper, bblower) == "buy")
              {
               trade.BuyStop(2.0, high1, _Symbol, low1, high1 + range * 1.2, ORDER_TIME_GTC, exp, "me");
              }
           }
         if(high_index = 0 && at_zone(high1, low1)
        {
         if(at_bands(high1, low1, bbupper, bblower) == "sell")
              {
               trade.SellStop(2.0, high1, _Symbol, low1, low - range * 1.2, ORDER_TIME_GTC, exp, "me");
              }
           }
        }
  }
//+------------------------------------------------------------------+
int at_zone(double high, double low)
  {
   int v = 0;
   double zones [] = {123.400, 83.444};
   for(int i = 0; i < ArraySize(zones); i++)
     {
      if(high > zones[i] && low < zones[i])   // INCLUDE THE PIPS FOR SLIPPAGE, as well as the indication values
        {
         v += 1;
        }
     }
   if(v == 1)
     {
      return v;
     }
   else
      return 0;
  }
//+------------------------------------------------------------------+
string at_bands(double high, double low, double ub, double lb)
  {
   if((high >= lb && low <= lb) || high < lb)
     {
      return "buy";
     }
   else
      if((high >= ub && low <= ub) || low > ub)
        {
         return "sell";
        }
  }
//+------------------------------------------------------------------+
 
Fernando Carreiro #:

Before correcting parentheses ...

After adding closing paranthesis to OnTick() ...

After adding "#include <Trade\Trade.mqh>" to beginning of file ...

You need to seriously analyse your code and fix all of these.

I just dont get it . I did put a semi colon at the end of the CTrade expression. and how did you get all these errors when you compiled ? I only got 2

 
Joao David Ngululia Buta #: I just dont get it . I did put a semi colon at the end of the CTrade expression. and how did you get all these errors when you compiled ? I only got 2
  1. You did not include the <Trade\Trade.mqh> file.
  2. You have too many unbalanced parenthesis.
  3. You need to break up your code into understandable and readable code logic blocks, so that you can pick on these problems.
 
I want to link my account with XM, please help
 

Hi guys , I just built my first EA using the trade class. The code compiles without errors but during the strategy testing in the strategy tester , the EA does not open any trades. In the journal tab , there are no error messages . Please help . Below is my code : 

...

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

...

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.