Download MetaTrader 5

How i understand Close trade by TP

To add comments, please log in or register
Mohammad Ali
21374
Mohammad Ali  

Hi Guys

Is there any MQL code that i understand last trade is close by TP. I wrote below code but it is not work.Because sometime ClosePrice=TakePrice is not True. I attach picture that u understand that ClosePrice=TakePrice is not always true. How can i solve this problem.

double GetLastTrade()  
{
   int ord; lord=0;
   string c;
//----
   for(int i=OrdersHistoryTotal()-1;i>=0;i--) 
   {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if(OrderSymbol()==Symbol()) 
      {
         if (OrderType()==OP_BUY) lord=1;
         if (OrderType()==OP_SELL) lord=-1;
         c=StringSubstr(OrderComment(),0,StringFind(OrderComment(),"_",0));
         lpos=StrToInteger(c);
         
         lop = NormalizeDouble(OrderOpenPrice(), Digits);
         lcp = NormalizeDouble(OrderClosePrice(), Digits);
         lsl = NormalizeDouble(OrderStopLoss(), Digits);
         ltp = NormalizeDouble(OrderTakeProfit(), Digits);
         llot = OrderLots();
         lProfit = OrderProfit();

         if (ltp==lcp)  //OrderProfit()>0
          return(OrderLots()); 
         else 
          return(-OrderLots());
      }
   }
   return(0);
}

Simon Gniadkowski
Moderator
18024
Simon Gniadkowski  
capilta:

Hi Guys

Is there any MQL code that i understand last trade is close by TP.

No, there isn't. You have to do it by deduction.
whroeder1
15595
whroeder1  
capilta: but it is not work.Because sometime ClosePrice=TakePrice is not True.
  1. Of course it doesn't. The == operand. - MQL4 forum
  2. You have to do it by deduction.
    bool isCloseByTP = MathAbs( OrderClosePrice() - OrderTakeProfit() ) // Assumes no
                     < MathAbs( OrderClosePrice() - OrderStopLoss() );  // OrderClose

To add comments, please log in or register