It would be nice, if the HTML Help File would mention the OrderClose statement and its expression in MQL5
with a short examble.
Article "Moving from MQL4" did not mention that the OrderClose Statement is no longer possible.
It's not possible to close an Order in MT5 since Orders become (or add/subtract to) Positions. There's a CTrade::PositionClose() funtion in Include/Trade/Trade.mqh
Here speaks the master of the universe, the Terminator of the MQL5 language, the horror of every MQL-Programmer:
Now I know how it runs:
#include <Trade/Trade.mqh>
CTrade *abcdef = new CTrade;
abcdef.PositionClose("EURUSD",0.00005); // Symbol, Deviation
What all of you are talking about?
How to clearly use/substitute the old OrderClosePrice() in the new MQL5 language?
How to get the mq4 old OrderClosePrice in mq5??
I can get the OrderOpenPrice by OrderGetDouble(ORDER_PRICE_OPEN) / 0.0001
but not the order close price.
Some help?
- www.mql5.com
How to get the mq4 old OrderClosePrice in mq5??
I can get the OrderOpenPrice by OrderGetDouble(ORDER_PRICE_OPEN) / 0.0001
but not the order close price.
Some help?
As I understand orders only have open price. This is because of the MT-5 trading sequence. Trade Request to a an Order to a Deal to a Position. Deals of IN direction have open price. Deals of OUT direction have a close price. If you are looking for price when a Position is closed or price at closing of partial position volume or looking for potential closing price of an open Position will make a difference in code needed.
For full position close price: (these code segments need fine tuning and have not bee tested. Hope they work OK)
double LastClosePrice() // find price of last Deal OUT of last closed position { uint total=0; long ticket; string symbol; double LCprice=0; if(!PositionSelect(_Symbol)) // no open position for symbol { HistorySelect(0,TimeCurrent()); total=HistoryDealsTotal(); for(uint i=1;i <total; i++) { ticket=HistoryDealGetTicket(i); symbol=HistoryDealGetString(ticket,DEAL_SYMBOL); if( symbol==_Symbol && HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT) { LCprice=HistoryDealGetDouble(ticket,DEAL_PRICE); } } } return(LCprice); }
For close price of partial position closing.
double LastPartialClosePrice() // price of last Deal OUT of open position. { uint total=0; long ticket; double LPCprice=0; long pos_id; if(PositionSelect(_Symbol)) // continue if open position for symbol { pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER); HistorySelectByPosition(pos_id); total=HistoryDealsTotal(); for(uint i=1;i <total; i++) { ticket=HistoryDealGetTicket(i); if(HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT) { LPCprice=HistoryDealGetDouble(ticket,DEAL_PRICE); } } } return(LPCprice); }
For potential closing price for open position.
double PotentialClosePrice() // potential closing price of current open position { double PCprice=0; if(PositionSelect(_Symbol)) // continue if current open position { if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { PCprice=SymbolInfoDouble(_Symbol,SYMBOL_BID); } if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { PCprice=SymbolInfoDouble(_Symbol,SYMBOL_ASK); } } return(PCprice); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It would be nice, if the HTML Help File would mention the OrderClose statement and its expression in MQL5
with a short examble.
Article "Moving from MQL4" did not mention that the OrderClose Statement is no longer possible.