How to close an order

 

Hello, I need to close an open order (not a pending order, an order that is running). I have its Ticket number

Thanks

 
frankge973:

Hello, I need to close an open order (not a pending order, an order that is running). I have its Ticket number

Thanks

mql4 or mql5 ?
 

mql5 and I need to know also if an order has been closed automatically due to stop loss how to know it that is to say how to check in history if an order has been closed due to stop loss reaching 

 
frankge973:

mql5 and I need to know also if an order has been closed automatically due to stop loss how to know it that is to say how to check in history if an order has been closed due to stop loss reaching 

You can't close an order with MT5.

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • 2011.02.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
 

Just open an opposite order so it will cancel out.

I have also tried for the second time Mql5 and i am also having rather large problems converting between Mql4 and Mql5, for example with things like:

       volume[i]=iVolume(SymbolName(i,1),PERIOD_CURRENT,NULL);//---get volume
       spread[i]=MarketInfo(SymbolName(i,1),MODE_SPREAD);     //---get spread

I cannot seem to find a way to convert these examples into a single line code replacement.

And i have reached my final conclusion, which is that Mql5 sucks and it also does this very hard and i am never going to touch it again.

I just cannot create the "Flow" that i can create in Mql4 and i think they did a horrible job at changing all the code, i tried real hard, and several times too, but this has got to end. 

If you ask me, adding multiple symbol support for strategy tester in MT4 would be a serious step foreward since i am only converting code from MQL4 to MQL5 to test my MT4 robots !!!!

So i have some good robots in MT4 but i am un-able to test them due to the limited functionality in MT4, and so i try to convert it to MQL5 ONLY to test it and then move back to MT4 with the calculated variables found in MT5 !!

I know it makes no sense at all but it is only bacuse i am tring to find a way to test my multi symbol robots !!

 
Marco vd Heijden:

Just open an opposite order so it will cancel out.

I have also tried for the second time Mql5 and i am also having rather large problems converting between Mql4 and Mql5, for example with things like:

I cannot seem to find a way to convert these examples into a single line code replacement.

And i have reached my final conclusion, which is that Mql5 sucks and it also does this very hard and i am never going to touch it again.

I just cannot create the "Flow" that i can create in Mql4 and i think they did a horrible job at changing all the code, i tried real hard, and several times too, but this has got to end. 

If you ask me, adding multiple symbol support for strategy tester in MT4 would be a serious step foreward since i am only converting code from MQL4 to MQL5 to test my MT4 robots !!!!

So i have some good robots in MT4 but i am un-able to test them due to the limited functionality in MT4, and so i try to convert it to MQL5 ONLY to test it and then move back to MT4 with the calculated variables found in MT5 !!

I know it makes no sense at all but it is only bacuse i am tring to find a way to test my multi symbol robots !!

SymbolInfoInteger(symbol,SYMBOL_SPREAD);

This is not a valid mql4 statement, I suppose NULL should be 0 ?

volume[i]=iVolume(SymbolName(i,1),PERIOD_CURRENT,NULL);

Anyway, I understand your point of view, but you are wrong, mql5 is more powerful and efficient, it's easy to prove. Of course, you are right that mql5 is more complex and difficult to learn, that's probably the price for efficiency and speed.

Don't expect new big features in MT4/mql4, I don't think this will happen, from what I can read on the Russian forum by the Metaquotes CEO.

Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • 2010.05.17
  • Sergey Pavlov
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
 

Yes NULL should be 0 and sometimes you see that even do something is upgraded, many times you can still use the old language if they build it up on the same foundation.

Unfortunatly with MQL4 and MQL5 this is not so, however  i do see some of the old stuff that is still being used, but i also see a lot of stuff that is used in a completly different way as well as much more complicated way's of doing the same simple things.

I'm not sure what you think i am wrong about but i do know that very often so, simple systems work best.

If you are talking about efficiency do you mean resource usage? and speed? execution times? or calculation speed?

 
Marco vd Heijden:
...

I'm not sure what you think i am wrong about but i do know that very often so, simple systems work best.

Talking about that : "that Mql5 sucks"

If you are talking about efficiency do you mean resource usage? and speed? execution times? or calculation speed?

On all of these points mql5 is far better than mql4 (except maybe resource usage).
 

I am not so sure, execution times also depend on the network connection, and i noticed there are more steps involved in MQL5 calculating the same results this logically means it should take longer since it is directly related to computing capacity, i agree on the resources part too do.

Maybe this all isn't that important, to me what really matters is how does the code preform 

 
So, I have not understood correctly. 
If I know the ticket number , how can I close a running position (order), not a pending order
And how to understand if an order has been closed due to stop loss ? 
Also, How to modify a running order changing stop loss ?
It's very urgent because I need to complete a project for tomorrow and I don't know how to do. 
Thanks to all

 
frankge973:
So, I have not understood correctly. 
If I know the ticket number , how can I close a running position (order), not a pending order
And how to understand if an order has been closed due to stop loss ? 
Also, How to modify a running order changing stop loss ?
It's very urgent because I need to complete a project for tomorrow and I don't know how to do. 
Thanks to all

To close a BUY position you have to send a SELL order with the same volume as your position.

To check if it's close by stoploss you can check the history of deals.

To change a stoploss you have to send an order TRADE_ACTION_SLTP.

Please read the documentation, the forum and articles. If you need help on coding please post your attempt.