Download MetaTrader 5

PositionGetDouble(POSITION_VOLUME) does not update after SL order

To add comments, please log in or register
Find out how social trading can improve your profits
Marcelo Coutinho
1151
Marcelo Coutinho 2014.05.13 04:40 

Hi all, 

Any idea why PositionGetDouble(POSITION_VOLUME) does not update its value after being stopped by SL order ?

void OnTick()
{
(...)
   if(PositionSelect(my_symbol)) // seleciona a posição
     {
      ContratosAtual=PositionGetDouble(POSITION_VOLUME);
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) orderAtual=1;
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) orderAtual=-1;
      Relatorio("COM POSICAO");
     }
(...)
         mrequest.price=NormalizeDouble(price_info.bid,_Digits);               // latest bix price
         mrequest.sl=NormalizeDouble(price_info.bid+stop_loss*_Point,_Digits); // Stop Loss (SELL)
(...)
}
Alain Verleyen
Moderator
30743
Alain Verleyen 2014.05.13 08:18  
YouTrade:

Hi all, 

Any idea why PositionGetDouble(POSITION_VOLUME) does not update its value after being stopped by SL order ?

Sorry but your question is not clear ? If SL was reached, there is no more position.
Marcelo Coutinho
1151
Marcelo Coutinho 2014.05.13 13:38  
angevoyageur:
Sorry but your question is not clear ? If SL was reached, there is no more position.

Yes ... the SL order was reached. The next OnTick(), I was expecting the ContratosAtual=PositionGetDouble(POSITION_VOLUME) changed to 0 (zero) but instead, it remains with the same value as it was before.

So my question is do I have run any Refresh() command ?

Alain Verleyen
Moderator
30743
Alain Verleyen 2014.05.13 13:45  
YouTrade:

Yes ... the SL order was reached. The next OnTick(), I was expecting the ContratosAtual=PositionGetDouble(POSITION_VOLUME) changed to 0 (zero) but instead, it remains with the same value as it was before.

So my question is do I have run any Refresh() command ?

Your PositionSelect() should return false if you don't have a position. If you don't have a position there is no point the check POSITION_VOLUME.

If your PositionSelect() returns true, and so the volume is unchanged, that means the terminal is not yet aware your position was closed.

Marcelo Coutinho
1151
Marcelo Coutinho 2014.05.13 17:25  
angevoyageur:

Your PositionSelect() should return false if you don't have a position. If you don't have a position there is no point the check POSITION_VOLUME.

If your PositionSelect() returns true, and so the volume is unchanged, that means the terminal is not yet aware your position was closed.

Thank you
Marcelo Coutinho
1151
Marcelo Coutinho 2014.05.14 01:10  
YouTrade:
Thank you
Solved ! Thank you !
To add comments, please log in or register