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

 
igrok333:

wrote this code.

the meta-editor mumbles.



Why does it mate?


#property strict

Is your pr initialized?

 
igrok333:

wrote this code.

the meta-editor mumbles.
Why does it mate?


#property strict

It clearly says that on line 553 it's possible to use a variable that has no value. Try to write bool pr=false; This will fool the compiler but you'd better check it properly. After all, if the order type is a pending order, you will still have pr without a value...

 
Roman Sharanov:

on the previous one, and what's here from mql4? the OnTick() function?

The question was addressed in the article about mql4 language, so I immediately noticed Time[0].

After a closer look, it becomes clear that it is a user-defined array.

And here is a comment from the documentation:

Note

The function uses synchronous calling - it means that the function waits for execution of all commands that were placed in the chart queue before it was called, so this function might be time-consuming. You should keep this in mind if you work with a large number of objects on the chart.

Since an object in one price coordinate can have several values, it is necessary to specify the line number. This function can be applied only to the following objects:

  • Trend line (OBJ_TREND)
  • Trend line by angle (OBJ_TRENDBYANGLE)
  • Gann Line (OBJ_GANNLINE)
  • Equidistant channel (OBJ_CHANNEL) - 2 lines
  • Linear regression channel (OBJ_REGRESSION) - 3 lines
  • Standard deviation channel (OBJ_STDDEVCHANNEL) - 3 lines
  • Line with arrow (OBJ_ARROWED_LINE)


 
Artyom Trishkin:

Is your pr initialised?

does it have to be initialized? i thought it was enough to declare it.
I thought it was initialized by zero when declared.
 
STARIJ:

It clearly says that in line 553 it is possible to use a variable which has no value. Try to write bool pr=false; This will fool the compiler, but it's better to check everything properly. After all, if the order type is a pending order, you will still have pr without value...

thanks for reminding me about the pending orders)



Is this the right way to do it?

 void zakritj_vse_sdelki()
 {
 bool pr;
 for (int i=OrdersTotal()-1; i>=0; i--)       
   {                                        
   if(OrderSelect(i,SELECT_BY_POS)==true)
      {  
         pr=false; 

         if (OrderType()==OP_BUY)    pr=OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), 30 );                              
         if (OrderType()==OP_SELL)   pr=OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 30 );
         
         if (pr==false) Print("закрытие ордера ", OrderSymbol() ," завершилось с ошибкой #",GetLastError());
         if (pr==true) Print("ордер ", OrderSymbol() , " ЗАКРЫТ");
       }
    }
  }  
 
igrok333:

thanks for reminding me about the pending orders)
is this the right way to do it?

if (pr==false) is equivalent to if (!pr)
if (pr==true) is equivalent to if (pr)

I use Alert instead of Print - it should appear right away without opening the journal. And there is no extra information

 
Вместо
if (OrderType()==OP_BUY)    pr=OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), 30 );
if (OrderType()==OP_SELL)   pr=OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 30 );
короче
if (OrderType()==OP_BUY)    pr=OrderClose(OrderTicket(), OrderLots(), Bid, 30 );
if (OrderType()==OP_SELL)   pr=OrderClose(OrderTicket(), OrderLots(), Ask, 30 );
или просто
pr=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 30 );


 
STARIJ:

if (pr==false) is equivalent to if (!pr)
if (pr==true) is equivalent to if (pr)

I use Alert instead of Print - it shows up instantly on the screen without opening the journal. And there is no extra information

I'm actually talking about placing pr in the code))
 
Дед пенсионер:
can we write OrderClosePrice() like this?

We get OrderClosePrice() after the transaction is closed.
 
igrok333:
Is it possible to write OrderClosePrice() like this?

We receive OrderClosePrice() after the trade is closed.

You can. But be careful. For an open position, it returns the closing price. Correspondingly: for Buy - Bid, for Sell - Ask

Reason: