Download MetaTrader 5
To add comments, please log in or register
Enable MQL5 Storage to store your source codes. It is free!
m
105
m 2014.09.29 08:41 

Hi,

I tried write proper code for function, but (I think) I can't call it. Have you got any suggestions? I read tutorials and  tried to find solution of this problem using break, return.... Bool return value, and I can't use void. Maybe

int start()
{
.
.
.
Trailing(true);
return(0);
}
 
 
bool Trailing(bool ans=true)
 {
   int MagicNumber=OrderMagicNumber();
   double Type=OrderType();
   double TrailingStop=100;
   double Poczatek=0;
  
    for (int i=OrdersTotal()-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)break;
       if (OrderSymbol()!=Symbol())continue;
        if (MagicNumber!=OrderMagicNumber()) continue;           
       
        while(true)      
        {     
                if (Type==OP_BUY)
                {
                  if((Bid-OrderOpenPrice())>Point*Poczatek || (Bid-OrderOpenPrice())<Point*Poczatek)
                     if (OrderStopLoss()<Bid-Point*TrailingStop)                    
                     {             
                      ans=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop),OrderTakeProfit(),0);                               
                     }   
                     return(false);     
                }           
                  if (Type==OP_SELL)
                  {
                     if((OrderOpenPrice()-Ask)>Point*Poczatek || (OrderOpenPrice()-Ask)<Point*Poczatek)
                        if(OrderStopLoss()>Ask+TrailingStop*Point||OrderStopLoss()==0) 
                      {                 
                        ans=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Point*TrailingStop),OrderTakeProfit(),0);                                    
                      }  
                      return(false);            
                  }
                                       
         }      
     } return(true);
   }

error is in the loop.

/
To add comments, please log in or register