Issue with TotalOrderProfit

 

Hi all,

Using the following code am looking to close orders once the TotalOrderProfit gets equal or less than TrailedPrice.

I have put a print to check why is that not working and what I see is that the price do not come down.

Could you show  me what am doing wrong ?

 

  void StartToTrailPrice()
//---- 
       {//0      
        TotalOrderProfit = 0;                                    
        for(int Orders = OrdersTotal()-1; Orders >= 0; Orders--)       
          {//1
          if(!OrderSelect(Orders,SELECT_BY_POS,MODE_TRADES))continue;
            {//2
            if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)            
              {//3                             
               TotalOrderProfit += OrderProfit() + OrderCommission() + OrderSwap();                                                        
              }//3          
            }//2
          }//1  
          TrailedPrice = TotalOrderProfit - ProfitToProtect;
          Print("orderprofit : ",TotalOrderProfit);                                                                             
          if(TotalOrderProfit <= TrailedPrice)CloseAll();
        
 //----                             
       }//0 

 

Thank you in advance

Luis 

 
luisneves: Could you show  me what am doing wrong ?
TrailedPrice = TotalOrderProfit - ProfitToProtect;
if(TotalOrderProfit <= TrailedPrice)CloseAll();

// Substituting TradiledPrice:
if(TotalOrderProfit <= TotalOrderProfit - ProfitToProtect) 

// Subtracting TotalOrderProfit:
if(                0 <=                 - ProfitToProtect) // Always false w/ positive ProfitToProtect
Reason: