Questions from Beginners MQL5 MT5 MetaTrader 5 - page 967

 

How do I get the opening price of a bar right and if I fail to get the opening price to exit?

Sketched out a few options. But maybe there is a better and more correct code?

   if(iOpen(Symbol(),Period(),0)==0)
     {
      return;
     }
     {
      if(iOpen(Symbol(),Period(),0)!=0)
        {
         double   open=iOpen(Symbol(),Period(),0);
        }
     }
  if(iOpen(Symbol(),Period(),0)==0.0)
     {
      return;
     }
     {
      if(iOpen(Symbol(),Period(),0)!=0.0)
        {
         double   open=iOpen(Symbol(),Period(),0);
        }
     } 
  if(iOpen(Symbol(),Period(),0)==0 && iOpen(Symbol(),Period(),0)==0.0)
     {
      return;
     }
     {
      if(iOpen(Symbol(),Period(),0)!=0 && iOpen(Symbol(),Period(),0)!=0.0)
        {
         double   open=iOpen(Symbol(),Period(),0);
        }
     }     
 
ilvic:

How do I get the opening price of a bar right and if I fail to get the opening price to exit?

Sketched out a few options. But maybe there is a better and more correct code?

The iXXXX functions only make sense if you are running a one-time request, without loops and without calling any other iXXXX functions.

If you only need to get the opening price once, then seeiOpen's help:

Return value

*** 0 in case of error.

So you need to query the price and check if it is zero: if it is not zero then the price is received, if it is zero then it is an error.

double open=iOpen(Symbol(),Period(),0);
if(open==0.0)
   retutn;
 
Can you please tell me how to insert parameter 9 with a grid (#CL) so that the compiler won't generate an error?
enum Symboll_
  {
   AUDUSD=0,
   NZDUSD=1,
   USDCAD=2,
   USDCHF=3,
   USDJPY=4,
   EURJPY=5,
   EURUSD=6,
   GBPUSD=7,
   #CL   =8
  };
 
Vladimir Karputov:

The iXXXX functions only make sense if you are running a one-time request, without cycles and without calling any other iXXXX functions.

If you only need to get the opening price once, seeiOpen help:

Return value

*** 0 in case of error.

So you need to query the price and check that it is zero: if it is not zero then the price is received, if it is zero then it is an error.

Thank you. One more question. Should we use parentheses in this code or it makes no difference?

   double   open=iOpen(Symbol(),Period(),0);
   if(open==0.0)
     {
      return;
     }
 
xxz:
Can you please tell me how to insert the 9 parameter with a grid (#CL) so that the compiler doesn't generate an error?

Like this:

   enum MySymbol
     {
      symbol_0=0,// AUDUSD
      symbol_1=1,// NZDUSD
      symbol_2=2,// USDCAD
      symbol_3=3,// USDCHF
      symbol_4=4,// USDJPY
      symbol_5=5,// EURJPY
      symbol_6=6,// EURUSD
      symbol_7=7,// GBPUSD
      symbol_8=8,// #CL
     };
 
ilvic:

Thank you. One more question. Should brackets be used in this code or does it make no difference?

   double   open=iOpen(Symbol(),Period(),0);
   if(open==0.0)
      return;

It will do. Generally speaking, brackets are intended for a group of actions. If there is only one action, they are of no use.

int n;
double y;
if(бла-бла-бла)
         n = бла-бла;
else
  {
         n = бла-бла;
         y = бла;
  )
 
Vladimir Karputov:

There you go:

Thank you very much!

Because I tried it like this and it didn't work:

  enum  Symboll_
  {
   SIM_0,  //AUDUSD
   SIM_1,  //NZDUSD
   SIM_2,  //USDCAD
   SIM_3,  //USDCHF
   SIM_4,  //USDJPY
   SIM_5,  //EURJPY
   SIM_6,  //EURUSD
   SIM_7   //#CL
  };  
 
xxz:

Thank you very much!

Because I tried it like this and it didn't work:

Or like this:

   enum MySymbol
     {
      symbol_0=0,// AUDUSD
      symbol_1=1,// NZDUSD
      symbol_2=2,// USDCAD
      symbol_3=3,// USDCHF
      symbol_4=4,// USDJPY
      symbol_5=5,// EURJPY
      symbol_6=6,// EURUSD
      symbol_7=7,// GBPUSD
      symbol_8=8,// #CL
     };
   string my_symbol[9]=
     {
      "AUDUSD",
      "NZDUSD",
      "USDCAD",
      "USDCHF",
      "USDJPY",
      "EURJPY",
      "EURUSD",
      "GBPUSD",
      "#CL"
     };
 
Vladimir Karputov:

or this:

That's the one!

In those variants it came out either just a serial number orSIM_1,...etc.

 
When testing a multi-currency EA, there is a problem with the lot size. I have a fixed 0.03, but during the test the orders appear with the volume of 0.1. Immediately a failure appears on the chart. Is it just me?
Reason: