Download MetaTrader 5

How i understand Close trade by TP

To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
Mohammad Ali
19494
Mohammad Ali 2014.01.20 05:12 

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
17998
Simon Gniadkowski 2014.01.20 09:44  
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
14457
whroeder1 2014.01.20 18:31  
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