Increasing a position with the new Hedging system

 

Hi All,

By setting the "position" field in the MqlTradeRequest structure I'm able to close an position (by sending and opposite order with the same volume), I'm able to reduce an position (by sending and opposite order with a smaller volume) and I'm able to swap the position (by sending and opposite order with a bigger volume).

But I'm not able to increase a position (by sending an order in the same direction of the position).

failed exchange sell 1.00 WINFUT at 43655.00000, close #9 sell 4.00 WINFUT 43560 [Invalid request]

That "close #9" tells me I'm doing something wrong.  Am I or it's a limitation of this new hedging system?

 Thanks in advice. 

 
Henrique Vilela:

Hi All,

By setting the "position" field in the MqlTradeRequest structure I'm able to close an position (by sending and opposite order with the same volume), I'm able to reduce an position (by sending and opposite order with a smaller volume) and I'm able to swap the position (by sending and opposite order with a bigger volume).

But I'm not able to increase a position (by sending an order in the same direction of the position).

That "close #9" tells me I'm doing something wrong.  Am I or it's a limitation of this new heading system?

 Thanks in advice. 

What is your trading account type: hedge or netting?
Use the standard library - the CTrade class.
 
Henrique Vilela:

Hi All,

By setting the "position" field in the MqlTradeRequest structure I'm able to close an position (by sending and opposite order with the same volume), I'm able to reduce an position (by sending and opposite order with a smaller volume) and I'm able to swap the position (by sending and opposite order with a bigger volume).

But I'm not able to increase a position (by sending an order in the same direction of the position).

That "close #9" tells me I'm doing something wrong.  Am I or it's a limitation of this new hedging system?

 Thanks in advice. 

I suppose you are using an netting account on BOVESPA ?

That seems like a bug, either in your code, either in mql5. Can you post your request code ?

 
Alain Verleyen:

I suppose you are using an netting account on BOVESPA ?

That seems like a bug, either in your code, either in mql5. Can you post your request code ?

Actually I'm using a hedge account on Bovespa.

Everything is fine with netting accounts, I'm trying hedge accounts now an trying to manipulate different positions in the same symbol by having two or more EAs in the same symbol working completely isolated.

I can select a specific position, reduce it, close it and even invert it. But if i try to increase it i get this error:

failed exchange sell 1.00 WINFUT at 43655.00000, close #9 sell 4.00 WINFUT 43560 [Invalid request]

 Code bellow:

   MqlTradeRequest request={0}; 
   request.action=TRADE_ACTION_DEAL; 
   request.symbol=_Symbol;

   MqlTradeResult result;

   // Open Position [OK]
   request.volume=2;
   request.type=ORDER_TYPE_BUY;
   OrderSend(request,result);
   
   // Get the position Id [OK]
   PositionSelect(_Symbol); // I know that I should select it by ticket, but for this example it's enough
   request.position=PositionGetInteger(POSITION_TICKET);

   // Close the position [OK]
   request.volume=2;
   request.type=ORDER_TYPE_SELL;
   OrderSend(request,result);
   request.position=0;
   
   // Open new Position [OK]
   request.volume=2;
   request.type=ORDER_TYPE_BUY;
   OrderSend(request,result);
   
   // Get the new position Id [OK]
   PositionSelect(_Symbol); // I know that I should select it by ticket, but for this example it's enough
   request.position=PositionGetInteger(POSITION_TICKET);

   // Reduce the position [OK]
   request.volume=1;
   request.type=ORDER_TYPE_SELL;
   OrderSend(request,result);

   // Increase the position [ERROR]
   request.volume=1;
   request.type=ORDER_TYPE_BUY;
   OrderSend(request,result);
 
Henrique Vilela:

Actually I'm using a hedge account on Bovespa.

Ah.

Everything is fine with netting accounts, I'm trying hedge accounts now an trying to manipulate different positions in the same symbol by having two or more EAs in the same symbol working completely isolated.

I can select a specific position, reduce it, close it and even invert it. But if i try to increase it i get this error:

 Code bellow:

You can't increase a position in hedging system. You have to open a new one.

 
Alain Verleyen:
Ah.

You can't increase a position in hedging system. You have to open a new one.

Really? Any kind of special reason for that?

I was hopping to be able to work with one position for each EA, like I'm used to to with MT4.

I believe that's the last barrier between MT4 and MT5, and I though that was finally broken.

 
Henrique Vilela:

Really? Any kind of special reason for that?

I was hopping to be able to work with one position for each EA, like I'm used to to with MT4.

I believe that's the last barrier between MT4 and MT5, and I though that was finally broken.

Manually two or three times click "Buy" - you will see how the hedge account works.
 

On a hedge account (in the MetaTrder 5) I two times have clicked "Buy":

On a hedge the account I two times have clicked "Buy" 

 

Yes, in a hedging account you can have multiple positions, that's clear.

In the MT4 you also can have multiple positions, but when you send a new order you can decide if this new order will affect an existent position or create a new one.

In the MT5 Hedge account you also can do that, but (apparently) only if you're reducing the position, you can't increase it.

For example: I can buy 5 EURUSD, then sell 1 an opt change the same position (change the original position to 4 EURUSD) as my code shows. But now if I want to buy 1, my only option is to open a new position (getting one position with 4 and one with 1). Apparently I can't make my position get back to 5.

Why this differentiation?  Why I can alter a position if I'm reducing it, and I can't alter it if I'm increasing it?

 
Henrique Vilela:

Yes, in a hedging account you can have multiple positions, that's clear.

In the MT4 you also can have multiple positions, but when you send a new order you can decide if this new order will affect an existent position or create a new one.

No you can't.

In the MT5 Hedge account you also can do that, but (apparently) only if you're reducing the position, you can't increase it.

For example: I can buy 5 EURUSD, then sell 1 an opt change the same position (change the original position to 4 EURUSD) as my code shows. But now if I want to buy 1, my only option is to open a new position (getting one position with 4 and one with 1). Apparently I can't make my position get back to 5.

Why this differentiation?  Why I can alter a position if I'm reducing it, and I can't alter it if I'm increasing it?

MT5 hedging account are working similarly to MT4.

That's how it is, I don't know why.

 
Alain Verleyen:
No you can't.

MT5 hedging account are working similarly to MT4.

That's how it is, I don't know why.

I don't code in MT4 for years and decide to download it to confirm what you said, and I guess you're right.

I can reduce it (using PositionClose with a smaller volume), close it (using PositionClose with the total volume) but there is no option to increase it. I guess when I used to code in MT4 I never tried to increase a position (order) so I never missed it and supposed it was possible.

   // Open Position
   int id = OrderSend(_Symbol,OP_BUY,2,Ask,10,0,0);
      
   // Close the position
   OrderClose(id,2,Ask,10);

   // Open new Position
   id = OrderSend(_Symbol,OP_BUY,2,Ask,10,0,0);
   
   // Reduce the position
   OrderClose(id,1,Ask,10);

   // Increase the position
   // No command to do that

 Anyway, thank you very much for your time.