last deal closed "direction"

 

Hello,

I need a very simple way to find if the last deal CLOSED a BUY opened or a SELL opened position.

EXAMPLE: If I use Ctrade trade; trade.PositionClose() how do I find if I closed a BUY opened or a SELL opened position.

Thanks again for help ! 

 
tenlau:

Hello,

I need a very simple way to find if the last deal CLOSED a BUY opened or a SELL opened position.

EXAMPLE: If I use Ctrade trade; trade.PositionClose() how do I find if I closed a BUY opened or a SELL opened position.

Thanks again for help ! 

You can try this:

HistorySelect(0, TimeCurrent());

and then

Print("Last deal type = "+EnumToString((ENUM_DEAL_TYPE)HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE))); 

If the last deal type was a buy deal (buy, buy limit, buy stop or buy stop limit), you have closed a short position. If the last deal type was a sell deal (sell, sell limit, sell stop or sell stop limit), then you have closed a long position.

P.S.: of course I'm assuming you actually know your last deal has closed a previously opened position.

 
Malacarne:

You can try this:

and then

If the last deal type was a buy deal (buy, buy limit, buy stop or buy stop limit), you have closed a short position. If the last deal type was a sell deal (sell, sell limit, sell stop or sell stop limit), then you have closed a long position.

P.S.: of course I'm assuming you actually know your last deal has closed a previously opened position.

Thank you Malacarne. Works like a charm !
Reason: