Questions from Beginners MQL4 MT4 MetaTrader 4 - page 124

 
Игорь:
Hello !
Can you tell me how to repaint the bars without using templates in mt4 !??
Or how to apply a colour scheme !?
Context menu chart, properties, colours - have you tried that?
 
Ihor Herasko:

I'll simplify the answer a bit to avoid confusion. The (&) sign indicates that a function argument can change its value at runtime and will return to where the function was called from with a different value. In the case in question, the SaveOrder function can change the contents of the g_arrstBuyOrderInfo and g_arrstSellOrderInfo arrays, as well as the g_nBuyOrdersCnt and g_nSellOrdersCnt variables.

Thank you. It becomes a bit clearer. It's just not clear how all this can be found out without referring to the forum. I haven't found such explanations in the tutorials.

Please give me some more advice:

1) The compiler writes - 'g_nBuyOrdersCnt' - declaration without type ; 'g_nSellOrdersCnt' - declaration without type. Am I correct in assuming that g_nBuyOrdersCnt and g_nSellOrdersCnt should be declared globally to avoid an error by the compiler?

2) Compiler:'for' - expressions are not allowed on a global scope. It is not clear here.

3) In thevoid SaveOrderInfo(OrderInfo &arrstOrderInfo[], int &nOrdersCnt) function, the compiler writes: declaration of 'arrstOrderInfo' hides global declaration. see previous declaration of 'arrstOrderInfo'. It is not very clear either.

4) 'nOrderCnt' is an undeclared identifier. Why is it not declared anywhere?

And one last thing: I still don't understand where.n and.f come from and what they are.




 
Игорь:

Hello !

Can you tell me how to repaint the bars without using templates in mt4 !??

Or how to apply a colour scheme !??

If programmatically, see ChartSetInteger() and ChartGetInteger() functions.

 
novichok2018:

Thank you. It's starting to make a little more sense. It's just not clear how you can find out all this without referring to a forum. I couldn't find such explanations in the textbooks.

Please give me some more advice:

1) The compiler writes - 'g_nBuyOrdersCnt' - declaration without type ; 'g_nSellOrdersCnt' - declaration without type. Am I correct in assuming that g_nBuyOrdersCnt and g_nSellOrdersCnt should be declared globally to avoid an error by the compiler?

2) Compiler:'for' - expressions are not allowed on a global scope. It is not clear here.

3) In thevoid SaveOrderInfo(OrderInfo &arrstOrderInfo[], int &nOrdersCnt) function, the compiler writes: declaration of 'arrstOrderInfo' hides global declaration. see previous declaration of 'arrstOrderInfo'. It is not very clear either.

4) 'nOrderCnt' is an undeclared identifier. Why is it not declared anywhere?

Here's how it all should be in the code if you look at the code as a whole:

#property strict

input       int i_nMagicNumber = 12876;

#define  MAX_ORDERS_CNT   int(500)
struct OrderInfo
{
   int      nTicket;
   int      nType;
   double   fOpenPrice;
   double   fSL;
   double   fTP;
   datetime dtOpenTime;
};

int         g_nBuyOrdersCnt, 
            g_nSellOrdersCnt;

OrderInfo   g_arrstBuyOrderInfo[MAX_ORDERS_CNT], 
            g_arrstSellOrderInfo[MAX_ORDERS_CNT];

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Expert initialization function                                                                                                                                                                    |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int OnInit()
{
   return INIT_SUCCEEDED;
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Expert deinitialization function                                                                                                                                                                  |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Expert tick function                                                                                                                                                                              |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void OnTick()
{
    FindOrders();
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Fills the orders arrays                                                                                                                                                                           |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void FindOrders()
{
   g_nBuyOrdersCnt = 0;
   g_nSellOrdersCnt = 0;
   for (int i = OrdersTotal() - 1; i >= 0; --i)
   {
      if (!OrderSelect(i, SELECT_BY_POS))
         continue;
   
      if (OrderSymbol() != Symbol())   // Если нужны ордера только по текущему символу, к графику которого прикреплен советник
         continue;
   
      if (OrderMagicNumber() != i_nMagicNumber)  // Если имеется входной параметр советника i_nMagicNumber, в котором указан ID ордеров советника
         continue;
   
      if (OrderType() == OP_BUY)
         SaveOrderInfo(g_arrstBuyOrderInfo, g_nBuyOrdersCnt);
      if (OrderType() == OP_SELL)
         SaveOrderInfo(g_arrstSellOrderInfo, g_nSellOrdersCnt);
   }
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Saves one selected order in the specified array                                                                                                                                                   |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void SaveOrderInfo(OrderInfo &arrstOrderInfo[], int &nOrdersCnt)
{
   if (nOrdersCnt >= MAX_ORDERS_CNT)
      return;

   arrstOrderInfo[nOrdersCnt].nTicket = OrderTicket();
   arrstOrderInfo[nOrdersCnt].nType = OrderType();
   arrstOrderInfo[nOrdersCnt].fOpenPrice = OrderOpenPrice();
   arrstOrderInfo[nOrdersCnt].fSL = OrderStopLoss();
   arrstOrderInfo[nOrdersCnt].fTP = OrderTakeProfit();

   ++nOrdersCnt;
}
 
novichok2018:

One last thing: I still don't understand where.n and.f come from and what they are.

The "dot" operator indicates access to a member of a structure or class. In this case, it is a structure.

Letters n and f are a way of specifying the type of data stored in a variable. After all, with a huge number of variables, it is impossible to remember the type of each one. And if in a name of a variable there will be an indication of its type, necessity of remembering disappears by itself. n is a sign of an integer number (from Numeric), f is a real number (from float - floating point number). This way of writing variable names is called Hungarian notation.

 
Ihor Herasko:

The dot operator indicates access to a member of a structure or class. In this case, a structure.

The letters n and f are a way of specifying the type of data that is stored in a variable. After all, with a huge number of variables, it is impossible to remember the type of each one. And if in a name of a variable there will be an indication of its type, necessity of remembering disappears by itself. n is a sign of an integer number (from Numeric), f is a real number (from float - floating point number). This way of notation of variable names is called Hungarian notation.

There it is!!! Turns outg_ andg_n are not just some abbreviation, but prefixes saying that they are global and global integer variables!!! Ugh... And I couldn't figure out why these dashes in variable designations... How is it possible for a beginner, who is not familiar with such subtleties, to write code using arrays, structures, etc.? I thought my simple strategy could be written in simple language, without diving into the wilds.

Could you give me a link to a detailed (extended) tutorial on mcl4 to study alongside your advice?

And could you write the above code without using Hungarian notation for comparison? Are you sure the MT4 platform understands it clearly?


And a question about the code: what is thecontinue; for?

for (int i = OrdersTotal() - 1; i >= 0; --i)
   {
      if (!OrderSelect(i, SELECT_BY_POS))
         continue;
If an order is not selected in the first iteration, then it will not be selected in subsequent iterations and the cycle will continue indefinitely? Because the number of orders does not change. Wouldn't it be more correct tobreak with an error message?
 
STARIJ:
Context menu graphics, properties, colours - have you tried that?

Thanks I've already found it !!!

 
Ihor Herasko:

If programmatically, see ChartSetInteger() and ChartGetInteger() functions.

Thanks for finding it already with your help!!!

 
novichok2018:

There it is!!! Turns outg_ andg_n are not just some abbreviation, but prefixes that say they are global and global integer variables!!! Ugh... And I couldn't figure out why these dashes in variable designations... How is it possible for a beginner, who is not familiar with such subtleties, to write code using arrays, structures, etc.? I thought my simple strategy could be written in simple language, without diving into the wilds.

In order to do something, we have to delve into the subtleties. There is no other way.

Could you give me a link to a detailed (extended) tutorial on mcl4 to study alongside your advice?

I know only one textbook on MQL4 - that of Sergey Kovalev.

And could you write the above code without using Hungarian notation for comparison? Are you sure the MT4 platform understands it clearly?

Get used to a proper code formatting at once )) The Hungarian notation has been invented by fairly experienced programmers.

And a question about the code: what is thecontinue; for?

So, if an order is not selected in the first iteration, it will not be selected in the next ones and the loop will go on to infinity? Because the number of orders does not change. Wouldn't it be more correct tobreak with an error message?

If we failed to select one order, it does not mean that we will not be able to select the next order. Therefore it is reasonable to continue the loop.

Учебник по MQL4
Учебник по MQL4
  • book.mql4.com
В настоящее время персональный компьютер стал незаменимым помощником в жизни каждого человека. Благодаря развитию Интернета и увеличению мощности современных компьютеров открылись новые возможности во многих областях деятельности. Ещё десять лет назад торговля на финансовых рынках была доступна только банкам и узкому кругу специалистов. Сегодня...
 
Ihor Herasko:

Failure to select one order does not mean that the next order cannot be selected. Therefore, it is reasonable to continue the cycle.

And there is no need to display an error message? It would probably be useful to know why an order is not found and how to avoid it?