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

 
Artyom Trishkin:

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

o. I didn't know it can be used like that.

I thought OrderClosePrice() can only be taken from a closed position.

the help doesn't say anything about it)
 
igrok333:
o. I didn't know it could be used like that.

I thought OrderClosePrice() could only be taken from a closed transaction.

there's nothing about it in the help)

Undocumented feature. But there are some conventions. I don't remember which ones at the moment. You need to ask Alexey @Alexey Viktorov - he wrote about them recently.

 
Artyom Trishkin:

An undocumented possibility. But there are some conventions there. I can't remember which ones at the moment. Ask Alexey @Alexey Viktorov - he wrote about them recently.

What about this code?

Isn't the variable initiated by zero immediately?

 void zakritj_vse_sdelki()
 {
 bool pr;
 for (int i=OrdersTotal()-1; i>=0; i--)       
   {                                        
   if(OrderSelect(i,SELECT_BY_POS)==true)
      {   
         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:
What about this code?

The variable is not immediately initialized with zero?

Do not rely on the defaults. It is better to be concerned with its value when declaring a local variable: bool pr=false;

In general, of course, it is unnecessary to set it there. It is sufficient to check what the function returns:

if(!OrderClose()) Print("Bummer");

 

How do I know the Fibonacci fan price of a previous candle? MQL5
ObjectGetValueByTime() does not work, it returns 0, then high, then low candle

 

@ArtyomTrishkin

Good afternoon. Please help. tell me what's wrong with my indicator. I do not understand why it does not draw anything at all.

https://www.mql5.com/ru/forum/224805#comment_6372281

Files:
indicator.ZIP  21 kb
probability.zip  50 kb
 
Artyom Trishkin:

This is an undocumented feature. But there are some conventions. I don't remember which ones at the moment. I need to ask Alexey @Alexey Viktorov - he wrote about them recently.

It was such a long time ago... but still managed to find it. Renat explains in clear terms why it is undesirable. But in my opinion, it is not that bad. The problem may occur when we get a requote at order closing. If we set the Ask or Bid price in the request, we can always refresh the price and try again. And in the case of specifying the close price OrderClosePrice(), we will have to select the order repeatedly in order to refresh the order data.

Conclusion: If you can't, but really need to, you can.

Применение функция OrderClosePrice() к открытым ордерам
Применение функция OrderClosePrice() к открытым ордерам
  • 2006.09.11
  • www.mql5.com
Вопрос к разработчикам: Корректно ли использование данной конструкции: OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,CLR_NONE) Проверка...
 

Please advise! I read data from a CSV file, including a column with a price with a place separator "." (1.22426) via FileReadString(handle), then via StrToDouble function, everything is OK. But there is a column with the price also, but it is already delimited by "," (1,22426) and StrToDouble fails to read it. What to do, if there is no possibility to change comma to dot in CSV itself ?

 
WinProject:

Please advise! I read data from a CSV file, including a column with a price with a place separator "." (1.22426) via FileReadString(handle), then via StrToDouble function, everything is OK. But there is a column with price that is already separated by "," (1,22426) and StrToDouble fails to read it. What can I do if I can't change comma to a dot in CSV ?


FileReadString


and then you can change it from a comma to a dot:


StringReplace

Replaces all found substring in string with given sequence of characters.

intStringReplace(
string&str,//pattern in which the substitution will be performed.
const stringfind,// sought substring
const string replacement// substring to be substituted
);

 
Vladislav Andruschenko:

FileReadString


and then you can change from a comma to a full stop:


StringReplace

Replaces all found substring in the string with a given sequence of characters.

intStringReplace(
string&str,// string to be replaced
const stringfind,// sought substring
const string replacement// substring to be substituted
);


Thank you!) , variable Cena=FileReadString(handle); I insert into function Separator=StringReplace(Sepa,",","."); it writes error "implicit conversion from number to string" -

doesn't want to read value with separator "," (1,22426) as a string, and StringReplace doesn't work. Or am I doing it wrong?

Reason: