Closing trades

 

Hi all,

I've written a simple ea, but I can't get something done in this code. I want to trail the profit of the group inclusive the loss ones. 

void TrailingStairs(int ticket,int trldistance)
   {
    int Spred=Ask - Bid;
    if (OrderType()==OP_BUY)
      {
       if((Bid-OrderOpenPrice())>(Point*trldistance))
         {
          if(OrderStopLoss()<Bid-Point*trldistance || (OrderStopLoss()==0))
            {
             OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
             if (PolLots)
             if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
               {
               OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);
               }
             else
               {
               OrderClose(ticket,OrderLots(),Ask,3,Green);
               }
            }
         }
       }

 Thanks,

Jason 

 

You have to select the order to use functions like OrderType(), OrderOpenPrice()... Check OrderSelect()

 
OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
  1. OrderSelect first
  2. What are Function return values ? How do I use them ? - MQL4 forum
  3. Adjust for 4/5 digit brokers
  4. Do not use normalizeDouble ever.
Reason: