Download MetaTrader 5

PositionGetDouble(POSITION_VOLUME) does not update after SL order

To add comments, please log in or register
Marcelo Coutinho
1200
Marcelo Coutinho  

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
33253
Alain Verleyen  
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
1200
Marcelo Coutinho  
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
33253
Alain Verleyen  
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
1200
Marcelo Coutinho  
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
1200
Marcelo Coutinho  
YouTrade:
Thank you
Solved ! Thank you !
To add comments, please log in or register