Download MetaTrader 5

Help to correct errors when compiling

To add comments, please log in or register
Alexandr Saprykin
7296
Alexandr Saprykin  
int OnInit()
  {
   double LotSize(string symbol,datetime tbar)
     {
      double size;
      string BQ,currency=AccountCurrency();
      switch(MarketInfo(symbol,MODE_PROFITCALCMODE))
        {
         case 0:
           {
            int sbar=iBarShift(symbol,0,tbar);
            size=MarketInfo(symbol,MODE_LOTSIZE);
            if(StringSubstr(symbol,3,3)=="USD") break;
            if(StringSubstr(symbol,0,3)=="USD") size=size/iClose(symbol,0,sbar);
            else
              {
               BQ=StringSubstr(symbol,0,3)+"USD";
               if(iClose(BQ,0,0)==0) BQ="USD"+StringSubstr(symbol,0,3);
               if(iClose(BQ,0,0)==0) break;
               int BQbar=iBarShift(BQ,0,tbar);
               if(StringSubstr(BQ,0,3)=="USD") size=size/iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
               else size=size*iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
              }
           }
         break;
         case 1: size=MarketInfo(symbol,MODE_LOTSIZE); break;
         case 2: size=MarketInfo(symbol,MODE_TICKVALUE)/MarketInfo(symbol,MODE_TICKSIZE);
        }
      if(currency!="USD")
        {
         BQ=currency+"USD";
         if(iClose(BQ,0,0)==0)
           {
            BQ="USD"+currency;
            size*=iClose(BQ,0,iBarShift(BQ,0,tbar));
           }
         else size/=iClose(BQ,0,iBarShift(BQ,0,tbar));
        }
      return(size);
     }

 

 When compiling two errors:  I do not think what is wrong and how to fix it. Tell me please.

Marco vd Heijden
Moderator
5172
Marco vd Heijden  
your code is broken press Ctrl + , and follow the brackets.
Alexandr Saprykin
7296
Alexandr Saprykin  
Marco vd Heijden:
your code is broken press Ctrl + , and follow the brackets.

Where code is broken? I'm asking you to help fix bugs.

//+------------------------------------------------------------------+
//|                                                   Break Even.mq4 |
//|                                                 Copyright 2016,  |
//|                                         https://www.mql5.com/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, "
#property link      "https://www.mql5.com/ru/"
#property version   "1.00"
#property strict
#property indicator_chart_window   
#property indicator_buffers 1
#property indicator_plots   1
//--- plot BreakEven
#property indicator_label1  "BreakEven"    
#property indicator_type1   DRAW_LINE     
#property indicator_color1  clrGold       
#property indicator_style1  STYLE_SOLID  
#property indicator_width1  1
//--- indicator buffers
double         BreakEvenBuffer[];
//+------------------------------------------------------------------+
//| We expect to break even                                          |
//+------------------------------------------------------------------+
int OnInit()
  {
   double LotSize(string symbol,datetime tbar)
     {
      double size;
      string BQ,currency=AccountCurrency();
      switch(MarketInfo(symbol,MODE_PROFITCALCMODE))
        {
         case 0:
           {
            int sbar=iBarShift(symbol,0,tbar);
            size=MarketInfo(symbol,MODE_LOTSIZE);
            if(StringSubstr(symbol,3,3)=="USD") break;
            if(StringSubstr(symbol,0,3)=="USD") size=size/iClose(symbol,0,sbar);
            else
              {
               BQ=StringSubstr(symbol,0,3)+"USD";
               if(iClose(BQ,0,0)==0) BQ="USD"+StringSubstr(symbol,0,3);
               if(iClose(BQ,0,0)==0) break;
               int BQbar=iBarShift(BQ,0,tbar);
               if(StringSubstr(BQ,0,3)=="USD") size=size/iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
               else size=size*iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
              }
           }
         break;
         case 1: size=MarketInfo(symbol,MODE_LOTSIZE); break;
         case 2: size=MarketInfo(symbol,MODE_TICKVALUE)/MarketInfo(symbol,MODE_TICKSIZE);
        }
      if(currency!="USD")
        {
         BQ=currency+"USD";
         if(iClose(BQ,0,0)==0)
           {
            BQ="USD"+currency;
            size*=iClose(BQ,0,iBarShift(BQ,0,tbar));
           }
         else size/=iClose(BQ,0,iBarShift(BQ,0,tbar));
        }
      return(size);
     }
//--- indicator buffers mapping
   SetIndexBuffer(0,BreakEvenBuffer);

//---
   return(INIT_SUCCEEDED);
  }
Marco vd Heijden
Moderator
5172
Marco vd Heijden  

it tells you where to look


Alexandr Saprykin
7296
Alexandr Saprykin  
Marco vd Heijden:

it tells you where to look


I know where to look. I do not understand how to correct the mistake, so asked for help.
Daniela Bluemel
721
Daniela Bluemel  

you can't write a function in a function.

LotSize() is in OnInit() 


rest of code looks very strange but i'm not sure if it is wrong...for example after case 0: i think there can not be a "{"

or for example if ended with ";" and then else (not sure if it is wrong but i don't know it this way)

Sergey Genikhov
1680
Sergey Genikhov  

There is error, that you define function LotSize not in global scope.

Put it outside of OnInit()

Then modify OnInit

int OnInit()
  {
    ??= LotSize(symbol,tbar);
     
//--- indicator buffers mapping
   SetIndexBuffer(0,BreakEvenBuffer);

//---
   return(INIT_SUCCEEDED);
  }
To add comments, please log in or register