OrderModify

 
Подскажите как зделать чтобы каждый раз при изминении цены на 10 пунктов к примеру, стоп и профит тоже перемещались ,а не один раз, покажите на примере пожалуйста:


#property copyright ""
#property link      ""
#define MAGIC 20050610
extern double    StopLoss                      = 60;
extern double    TakeProfit                    = 12;
extern double    TrailingStop                  = 10;
extern double    MarginPercent                 = 20;
extern bool      MoneyManagement               =true;
extern double    Lots                          = 0.1;
extern double    UpLine                        = 80;
extern double    DwLine                        = 20;
 
void TrailingStop()
   {
   if (TrailingStop<0) return;
   for (int i=0; i<OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGIC) continue;
      if (OrderType()==OP_BUY)
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,
                                 Ask+TakeProfit*Point,0,Green);
                     return(0);
                    }
                 }
              }
      if (OrderType()==OP_SELL)
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,
                                 Bid-TakeProfit*Point,0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
//-------------------------        
void CloseBuy()
   {
   for (int i=OrdersTotal()-1; i>=0; i--)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()!=Symbol() || OrderType()!=OP_BUY) continue;
      OrderClose(OrderTicket(),OrderLots(),Bid,3);
      }
   }
//-----------------------------------     
void CloseSell()
   {
   for (int i=OrdersTotal()-1; i>=0; i--)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()!=Symbol() || OrderType()!=OP_SELL) continue;
      OrderClose(OrderTicket(),OrderLots(),Ask,3);
      }
   }
//------------------------------------------------------------
int TotalBuy()
   {
   int count=0;
   for (int i=0; i<OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY) count++;
      }
   return (count);
   }
//------------------------------------------------------------
int TotalSell()
   {
   int count=0;
   for (int i=0; i<OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL) count++;
      }
   return (count);
   }
//------------------------------------------------------------
void OpenBuy()
   {
   double profit;
   double loss;
   loss=0; if (StopLoss>0) loss=Ask-StopLoss*Point;
   profit=0; if (TakeProfit>0) profit=Ask+TakeProfit*Point;
   if (OrderSend(Symbol(),OP_BUY,LotsCounting(),Ask,3,loss,profit,"покупка #",MAGIC,0,Blue)==0)
      Print("Open error #",GetLastError());
   }
//----------------------------------------------------------------
void OpenSell()
   {
   double profit;
   double loss;
   loss=0; if (StopLoss>0) loss=Bid+StopLoss*Point;
   profit=0; if (TakeProfit>0) profit=Bid-TakeProfit*Point;
   if (OrderSend(Symbol(),OP_SELL,LotsCounting(),Bid,3,loss,profit,"продажа #",MAGIC,0,Red)==0)
      Print("Open error #",GetLastError());
   }
//------------------------------------------------------------------------
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
   if(buys>0) return(buys);
   else       return(-sells);
  }
//----------------------------------------------------------------------------------     
double LotsCounting()
   {
   double lots=Lots;
   if (MoneyManagement)
      {
      lots=NormalizeDouble((MarginPercent*AccountFreeMargin()/100000),1);
      if (lots>10) lots=NormalizeDouble(lots,0);
      }
   if (lots<0.1) lots=0.1;
   return (lots);
   }
//---------------------------------------------------------------------------------
void CheckOpen()
  { 
 
   double Stoc;
   double StocSignal;
   double  ma;  
   int    res;
   HideTestIndicators(true);
   ma = iMA(NULL,PERIOD_M5,8,0,0,PRICE_CLOSE,0);
   Stoc = iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   StocSignal = iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
//условие открытия
   double buy =  Close[0]>=ma && Close[1]<=ma && Stoc < DwLine && Stoc > StocSignal;
   double sell = Close[0]<=ma && Close[1]>=ma && Stoc > UpLine && Stoc < StocSignal;
   
 if (buy == true)OpenBuy();
     
 if (sell == true)OpenSell();
     
  }    
//---------------------------------------------------------------------------- 
void CheckClose()
  {
   double Stoc;
   double StocSignal;
   double  ma;  
   if(Volume[0]>1) return;
   HideTestIndicators(true);
   ma = iMA(NULL,PERIOD_M5,8,0,0,PRICE_CLOSE,0);
   Stoc = iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   StocSignal = iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
 
   double CloseSell = Close[0] > ma &&  Stoc < DwLine && Stoc > StocSignal;
   double CloseBuy =  Close[0] < ma &&  Stoc > UpLine && Stoc < StocSignal;
   
   if (TotalBuy() > 0 && CloseBuy == true)CloseBuy();
   if (TotalSell() > 0 && CloseSell == true)CloseSell();
  }
//-----------------------------------------------------------------------------   
void start()
  {
   TrailingStop();
   if(DayOfWeek()==0 || DayOfWeek()==6) return;  
   if(Bars<50 || IsTradeAllowed()==false) return;
   if(CalculateCurrentOrders(Symbol())==0) CheckOpen() ;
   else                                    CheckClose();
  }