Forget Outdated Indicators and Buy Latest Ones in MetaTrader Market
MQL4.com is moving to MQL5.com. Sign up for the new web portal for traders!

Get last order result (buy,sell,close,stop loss)...

Back to topics list To post a new topic, please log in or register
avatar
8
jjperellos 2007.09.04 22:27
 

Hello,

I'm working with an ea, and I need to know if the last trade closed for stop loss.

How can I know it?

Thanks.

 
USDJYP is playing hide and seek game!
USDJYP is playing hide and seek game!
Karim El Bawab | 27 February 2015, 17:50 | Views: 85
Chart LINK: https://www.mql5.com/en/charts/3086980/usdjpy-d1-mercer-fx-limited   Short Comment: USDJYP jumped from 119.10 to 119.70 (Today, 27th February, 2015) opening the road to test the resistance around 120.25. The first week of March is gonna be a strong battle between the bulls and the bears. Who is gonna win the next week?  I am am still bullish however, this pair can fall to 115 level in no time. Take care!
avatar
322
wackena 2007.09.04 23:56 #
 

Try this:

Stringo provided this code to find last closed trade in another thread.

int last_trade=HistoryTotal();
if(last_trade>0)
  {
   if(OrderSelect(last_trade-1,SELECT_BY_POS,MODE_HISTORY)==true)
     {
      Print("Last trade ticket ",OrderTicket(),"   op ",OrderType(), "   time ",TimeToStr(OrderCloseTime()),"   price ",OrderClosePrice());
     }
  }

You could change to this:

int last_trade=HistoryTotal();
if(last_trade>0)
  {
   if(OrderSelect(last_trade-1,SELECT_BY_POS,MODE_HISTORY)==true)
     {
      if(OrderSymbol()==Symbol() && OrderClosePrice()==OrderStopLoss())
         {
          Print("Last closed order was OrderType = ",OrderType(),"  Time = ",TimeToStr(OrderCloseTime()),"  close at StopLoss  ",OrderClosePrice());
         }
     }
  }
you can replace OrderStopLoss() with OrderTakeProfit() for when order closes at takeprofit.

 
Back to topics list  

To add comments, please log in or register