Questions from Beginners MQL5 MT5 MetaTrader 5 - page 656

 
In MQL5 to close an order you have to open a mirror counter-order and there is no other way?
 
new-rena:
In MQL5 to close an order you have to open a mirror counter-order and nothing else?

Use you standard library:

#include <Trade\Trade.mqh>
CTrade         m_trade;                      // trading object
...
m_trade.PositionClose(....
или
m_trade.PositionCloseBy(..

and don't have to think about anything.

 
Vladimir Karputov:

Use you standard library:

#include <Trade\Trade.mqh>
CTrade         m_trade;                      // trading object
...
m_trade.PositionClose(....
или
m_trade.PositionCloseBy(..

and don't have to think about it.

How can you not think about it? I'm writing a program in MQL5 for real trading, i.e. with real MY money!

I have read the documentation. I do not see a problem with closing a position.

The question is different. - Our SELL is blocked by BUY and SELL and BUY are merged into a single order with a volume equal to zero - is this a close?

So MQL5 excludes lots? Which means I have no chances to get lucky, except for final and irrevocable loss at reversal of the signal (order)?

Look at the signals - MQL5 is not as good as MQL4, to put it mildly...

You'd better improve the situation and remove such a nonsense as "position" from MQL5

 
new-rena:

I have read the documentation.

It shows.

new-rena:

...

So MQL5 excludes locks? It means I have no chance to make a single move and get a permanent loss?

Look at the signals - MQL5 is lame compared to MQL4, to put it mildly...

You'd better improve the situation and remove such a nonsense as "position" from MQL5

You should look through the Help sometimes, keep abreast of updates and read articles:Hedging system for position accounting has been added to MetaTrader 5

 
new-rena:

How can you not think about it? I am writing a program in MQL5 for real trading, i.e. with real MY money!

I have read the documentation. I do not see a problem with closing a position.

The question is different. - Our SELL is blocked by BUY and SELL and BUY are merged into a single order with a volume equal to zero - is this a close?

So MQL5 excludes lots? Which means that there is no chance for me to get lucky, besides incontrovertibly and irrevocably getting a loss?

Look at the signals - MQL5 is lame compared to MQL4, to put it mildly...

You need to correct the situation and remove such a nonsense as "position" from MQL5

Here is an example for a hedge account:

The first operation is Buy 0.02 and the second operation is Sell 0.01. The total of two positions: Buy 0.02 and Sell 0.001. Then we close the Sell 0.01 position and close the Buy 0.02 position:

//+------------------------------------------------------------------+
//|                                                       TestEA.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
CTrade         m_trade;                      // trading object
CPositionInfo  m_position;                   // trade position object
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   static long counter=0;
   counter++;
   if(counter%300==0 && counter<700)
     {
      static int number=0;
      number++;
      if(number==1)
         m_trade.Buy(0.02);
      if(number==2)
         m_trade.Sell(0.01);
     }
   if(counter>7000)
     {
      int positions= PositionsTotal();
      if(positions == 0)
         return;
      int positions_total=PositionsTotal();
      for(int i=positions_total-1;i>=0;i--)
         if(m_position.SelectByIndex(i))
            m_trade.PositionClose(m_position.Ticket(),-1);
     }
  }
//+------------------------------------------------------------------+

and Journal:

Trade   2016.02.25 00:13:35   instant buy 0.02 EURUSD at 1.10167 (1.10158 / 1.10167 / 1.10158)
Trades  2016.02.25 00:13:35   deal #2 buy 0.02 EURUSD at 1.10167 done (based on order #2)
Trade   2016.02.25 00:13:35   deal performed [#2 buy 0.02 EURUSD at 1.10167]
Trade   2016.02.25 00:13:35   order performed buy 0.02 at 1.10167 [#2 buy 0.02 EURUSD at 1.10167]
TestEA (EURUSD,H1)      2016.02.25 00:13:35   CTrade::OrderSend: instant buy 0.02 EURUSD at 1.10167 [done at 1.10167]
Trade   2016.02.25 00:30:17   instant sell 0.01 EURUSD at 1.10157 (1.10157 / 1.10164 / 1.10157)
Trades  2016.02.25 00:30:17   deal #3 sell 0.01 EURUSD at 1.10157 done (based on order #3)
Trade   2016.02.25 00:30:17   deal performed [#3 sell 0.01 EURUSD at 1.10157]
Trade   2016.02.25 00:30:17   order performed sell 0.01 at 1.10157 [#3 sell 0.01 EURUSD at 1.10157]
TestEA (EURUSD,H1)      2016.02.25 00:30:17   CTrade::OrderSend: instant sell 0.01 EURUSD at 1.10157 [done at 1.10157]
TestEA (EURUSD,H1)      2016.02.25 02:12:06   PositionClose #3 POSITION_TYPE_SELL 0.01
Trade   2016.02.25 02:12:06   instant buy 0.01 EURUSD at 1.10131, close #3 (1.10123 / 1.10131 / 1.10123)
Trades  2016.02.25 02:12:06   deal #4 buy 0.01 EURUSD at 1.10131 done (based on order #4)
Trade   2016.02.25 02:12:06   deal performed [#4 buy 0.01 EURUSD at 1.10131]
Trade   2016.02.25 02:12:06   order performed buy 0.01 at 1.10131 [#4 buy 0.01 EURUSD at 1.10131]

TestEA (EURUSD,H1)      2016.02.25 02:12:06   CTrade::OrderSend: instant buy 0.01 position #3 EURUSD at 1.10131 [done at 1.10131]
TestEA (EURUSD,H1)      2016.02.25 02:12:06   PositionClose #2 POSITION_TYPE_BUY 0.02
Trade   2016.02.25 02:12:06   instant sell 0.02 EURUSD at 1.10123, close #2 (1.10123 / 1.10131 / 1.10123)
Trades  2016.02.25 02:12:06   deal #5 sell 0.02 EURUSD at 1.10123 done (based on order #5)
Trade   2016.02.25 02:12:06   deal performed [#5 sell 0.02 EURUSD at 1.10123]
Trade   2016.02.25 02:12:06   order performed sell 0.02 at 1.10123 [#5 sell 0.02 EURUSD at 1.10123]
TestEA (EURUSD,H1)      2016.02.25 02:12:06   CTrade::OrderSend: instant sell 0.02 position #2 EURUSD at 1.10123 [done at 1.10123]

What exactly is not clear? That you need to open an opposite order with the same volume to close the position?

Files:
TestEA.mq5  5 kb
 
Anatoli Kazharski:

I can see that.

Tolyana, I'm sick of you.

Can't you write in business without being sarcastic?

 
new-rena:

Tolyana, I'm sick of you.

Can you write in business without being sarcastic?

What is this?

You should lookatthe Help sometimes,watch for updates and read articles:MetaTrader 5 has added a hedging system for position accounting

 
Anatoli Kazharski:

What is this?

You should look atthe Help sometimes,watch for updates and read articles:MetaTrader 5 has added a hedging system for position accounting

This one -"It shows." no more!!!!!!!!!!!!!!!

If you can reply, then write a reply and basta.

Then I'd say, "Thank you."

But in this case, please, I can just send it.

 
new-rena:

Tolyana, I'm sick of you.

Can you write in business without being sarcastic?

It seems to be all on the point and even with references... When someone declares that he read the documentation and asks to remove netting (which, by the way, is used on FORTS)... there's no room for sarcasm here.
 
new-rena:

That'sit-"It shows." no more!!!!!!!!!!!!!!!

If you can answer it, just write back and basta.

Then I'd say, "Thank you."

But in this case, please, I can just send it.

Make sure you don't get sent. )
Reason: