Schließung von halben Parzellen. - Seite 19

 
Ich dachte nur, es wäre nur fair, diesen Thread zu aktualisieren, da eine Menge Leute mir geholfen haben, zu verstehen, wie ich das hinbekomme und es funktioniert! Dies ist, wie ich es arbeiten süß wie eine Nuss und Schließen zu den richtigen Zeiten haben. FirstTarget zuerst, wenn das wahr ist und erfolgreich geschlossen hat, dann die EMA schließen, und dann die TwoRatio_Buy Ziel...

//+--------------------------------------------------------------------------------------------------+
//| Close OP_BUY Half lots @ 1:1 Function                                                            |
//+--------------------------------------------------------------------------------------------------+
void CloseHalfOrder()
{   
   
   static datetime partclosedonce;
   static datetime partclosedtwice;
   static datetime partclosedthird;
   
   double minLot=MarketInfo(Symbol(),MODE_MINLOT);
   double lotStep=MarketInfo(Symbol(),MODE_LOTSTEP);
   double half_1st=MathFloor(OrderLots()/First_Target/lotStep)*lotStep;
   double half_2nd=MathFloor(OrderLots()/EMA_Target/lotStep)*lotStep;
   double Target_2 =MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;
   
   double EMA_Bar = iClose(NULL, PERIOD_H1, 1);
   double EMA_MA = iMA(Symbol(),60,21,0,1,0,0);
   
   double FirstTarget_Buy = OrderOpenPrice()+(( OrderTakeProfit()-OrderOpenPrice())/6);
   double TwoRatio_Buy = OrderOpenPrice()+(( OrderTakeProfit()-OrderOpenPrice())/3);  

   
for(int c=OrdersTotal()-1; c>=0; c--)
    {
      if(OrderSelect(c,SELECT_BY_POS,MODE_TRADES))
       if(OrderMagicNumber()==MagicNumber)
        if(OrderSymbol() == Symbol())
        { 
         
          if(OrderOpenTime() != partclosedonce)  
           if(OrderType()==OP_BUY && Bid >= FirstTarget_Buy+(Point/2) && OrderLots()>minLot) 
              {
              bool Close_Half_Order_Buy=OrderClose(OrderTicket(),half_1st,Bid,5,Blue);
              }
               
          if(Close_Half_Order_Buy==True && OrderOpenPrice() > OrderStopLoss())
              {
              MoveToBreakEven(); 
              }
              if(Close_Half_Order_Buy==True)
                 {
                 partclosedonce = OrderOpenTime();
                 } 
      
          if(partclosedonce == OrderOpenTime() && partclosedonce != partclosedtwice && OrderOpenTime() != partclosedtwice)
           if(Bid - OrderOpenPrice() > Point / 2. 
            && OrderType()==OP_BUY && EMA_Bar < EMA_MA && OrderLots()>minLot)
              {
              bool EMA_Buy_Close=OrderClose(OrderTicket(),half_2nd,Bid,5,CLR_NONE);
              if(EMA_Buy_Close==True)partclosedtwice = OrderOpenTime();
              }     
                 
          if(OrderOpenTime() != partclosedthird)
           if(OrderType()==OP_BUY && Bid >= TwoRatio_Buy+(Point/2) && OrderLots()>minLot)
              {
              bool Two_Ratio_Buy=OrderClose(OrderTicket(),Target_2,Bid,5,CLR_NONE);
              if(Two_Ratio_Buy==True)partclosedthird = OrderOpenTime();
              }     
        }
     }
}