Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 266

 
danil77783:

Artyom good afternoon. My name is Daniel. My question is the following one. I have written my Expert Advisor in MQL4, to be more precise, rewritten from the video tutorial. Apparently there are some errors in it, but it will not compile well.

The compiler will display the errors specifying the line and position in the line. Please refer to them

Insert the text of the program using the SRC button above the text of your message - look, it is better!

//+------------------------------------------------------------------+
//|                                                        test7.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

You could also attach a file - then it would look in the MetaEditor immediately

 
LRA:

The compiler will generate errors indicating the line and position in the line. Refer to them

Insert the text of the program using the SRC button above the text of your message - look, it's better!!!

You could also attach a file - then it would look in MetaEditor immediately


Sorry for the incorrect behavior, I stand corrected, I give you my word :) I'm exhausted absolutely....

//+------------------------------------------------------------------+
//|                                                        test7.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//-------------------------------------------------------------------
extern double lots            = 0.1;
extern int    TakeProfit      = 300;
extern int    StopLoss        = 50;
extern int    Magic           = 777; 
extern int    Slippage        = 3;
//-------------------------------------------------------------------
extern string TMA             = "Параметры индикатора TMA";
extern string TimeFrame       = "current time frame";
extern int    HalfLength      = 56;
extern int    Price           = PRICE_CLOSE;
extern double ATRMultiplier   = 2.0;
extern int    ATRPeriod       = 100;
extern bool   Interpolate     = true;
//-------------------------------------------------------------------
double PriceHigh, PriceLow, SL ,TP;
int ticet;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   if (Digits == 3 || Digits == 5);
   {
       TakeProfit *=10;
       StopLoss   *=10;
       Slippage   *=10;
   }  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);  
    PriceLow  = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);  
    
    if (CountSell() == 0 && Bid >= PriceHigh)
    {
      tik et = OrderSend(Symbol(), OP_SELL, lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);  
      if (tiket > 0)
      {
          SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
          TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
          
          if (OrderSelect(ticet, SELECT_BY_TICKET)) 
              OrderModify(tiket, OrderOpenPrice(), SL, TP, 0);
        }
    }
  }
//--------------------------------------------------------------------------------------------
 if (CountBuy() == 0 && Ask <= PriceLow)
    {
      tiket = OrderSend(Symbol(), OP_BUY, lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);  
      if (tiket > 0)
      {
          TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
          SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
          
          if (OrderSelect(ticet, SELECT_BY_TICKET)) 
              OrderModify(tiket, OrderOpenPrice(), SL, TP, 0);
        }
    }
//+------------------------------------------------------------------+
int CountSell() 
  {
    int count = 0;
    for (int trade = OrdersTotal()-1; trade>=0; trade--)
    {
       if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber) == Magic && OrderType() == OP_SELL)
             count++;
       }   
    }
    return(count);
  }
//-----------------------------------------------------------------------------------------------  
  int CountBuy() 
  {
    int count = 0;

    for (int trade = OrdersTotal()-1; trade>=0; trade--)
    {
       if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber) == Magic && OrderType() == OP_BUY)
             count++;
       }   
    }
    return(count);
  }

I have marked lines with errors, file..... attached, please take a look, thank you in advance!

 
 
danil77783:

I apologize for the incorrect behavior, I will correct myself, I give you my word :) I'm completely exhausted ....

I have marked lines with errors, I have attached file....., please look it up, thanks in advance!

Is it so hard to see that ticet and tiket are different variables?

And you cannot see closing parenthesis without opening parenthesis too?

 
Thanks so much for your help!!! .... Fixed all the errors with one I can't figure out. I'm asking for your help. Where did I mess up again?
 
danil77783:
Thanks so much for your help!!! .... Fixed all the errors with one I can't figure out. I'm asking for your help. Where did I mess up again?
You have this block out of the body of the OnTick function, remove one curly bracket.
 
Alekseu Fedotov:
You have this block out of the body of the OnTick function, remove one bracket.

And then there will be one bracket missing.

The bracket above the selected line must be moved down, before the minus line.

}
//+------------------------------------------------------------------+
 
Alexey Viktorov:

And then there will be one bracket missing.

The bracket above the highlighted line must be moved down before the minus line.

Oh, yes, you should.

 

Everything!!! .... Thank you very much. Compiled it. It works!

 
danil77783: Everything!!! .... Thank you very much. Compiled it. It works!

What's the payoff? Also this piece here with the empty function can be discarded. Try it...

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   
  }
Reason: