请高手帮忙把该模板修改两个指令,谢谢!
请高手帮忙把该模板修改两个指令:
1.当盈利大于开仓价30点时,开始启动跟踪止损,跟踪止损20点;
2.强制性买、卖交替开仓。
————————————————————————————————————————————
//+------------------------------------------------------------------+
//|                                                      ea模板.mq4 |
//|                      Copyright @2007, http://hexun.com/pckr
| //| | //| | | //+------------------------------------------------------------------+ #property copyright "Copyright @2006, pckr" #property link "http://hexun.com/pckr" #include
//********************************************************************
//********************************************************************
//+---------------------------------------------------+
//---- User Inputs                                    |
//+---------------------------------------------------+
extern int Slippage              =10;  // 滑点      
extern double TakeProfit        = 12;// 最大止赢
extern double StopLoss          = 30; // 最大止损
extern double TrailingStop      = 0;  // 移动止损
//---- Money Management                                  
extern int mm                    =1;  // 设为0不接受资金管理,
extern double Riskpercent        =20;  // 下单占资金的百分比
extern double DecreaseFactor    =2;  // 亏损减少下单手数
extern double Margincutoff      =80; // 资金低于Margincutoff不交易
extern double Lots              =5;  // 设置期望的手数(如果忽略资金管理). 
extern int tradeSymbolNum        =3;  // 交易笔数
              
//---- Account functions                                  
extern int AccountIsMini        =2;  // 设为1使用迷你账户,设为2使用超迷你账户
//---- 用户自定义参数
//********************************************************************
//********************************************************************
          
//---- 系统变量
string OrderText                ="";  // 在函数中使用"Buy" or "Sell"为条件
double lotMM                      =0;
int TradesInThisSymbol            =0;  // 外汇交易数
datetime LastTime;                    // 最后订单时间
double Sl                        =0;  // 止损
double Tr                        =0;  // 止赢
int NumBuys                      =0; 
int NumSells                      =0;
int MagicNumber;
//---- 用户变量
//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 初始化函数                                  |
//+------------------------------------------------------------------+
int init()
{
      
    return(0);
}
//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 取消初始化函数                      |
//+------------------------------------------------------------------+
int deinit()
{
    return(0);
}
//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 启动 start()                                  |
//+------------------------------------------------------------------+
int start()
  {
//---- Start functions variables  
  
  int donttrade = 0;
  int allexit = 0;
  int ExitCondition;
  
  //int MagicNumber =20050610;
    MagicNumber = 3000 + func_Symbol2Val(Symbol())*100; 
  string setup="hexun.com/pckr" + Symbol() + "_" + func_TimeFrame_Val2String(func_TimeFrame_Const2Val(Period()));
  if(Bars<100 || IsTradeAllowed()==false) return;
//+------------------------------------------------------------------+
//| 这里输入需要的数据如指标等                                      |
//+------------------------------------------------------------------+
      
            
//+------------------------------------------------------------------+
//| 周五平仓                                                        |
//+------------------------------------------------------------------+
  if(DayOfWeek()==5 && Hour()>=21) donttrade=1; // 21时禁止交易
  if(DayOfWeek()==5 && Hour()>=22) allexit=1;  //22时平所有合约
  
//+------------------------------------------------------------------+
//| 检查未平仓合约                                                  |
//+------------------------------------------------------------------+
    NumBuys = CheckOpenBuyPositions(MagicNumber);          // 如果有买合约,看看是否应该关闭。
    if (NumBuys > 0) TryClosePositions("BUY",allexit);
    NumSells = CheckOpenSellPositions(MagicNumber);        // 如果有卖合约,看看是否应该关闭。
    if (NumSells > 0) TryClosePositions("SELL",allexit);
    TradesInThisSymbol = CheckOpenPositions(MagicNumber);  // 更新TradesInThisSymbol值
    
//+------------------------------------------------------------------+
//| New Position Controls                                            |
//+------------------------------------------------------------------+
  if(AccountFreeMargin() < Margincutoff)    // 检查,以确保账户有足够的资金。
  {
    return(0);
  }    
  if(TradesInThisSymbol > tradeSymbolNum)              // 只允许每个货币对有TradesInThisSymbol张合约
  {
    return(0);
  }
  if(CurTime() < LastTime)                  
  {                                        
    return(0);                              
  }
    
    
    
  if(mm == 1)                              // 检查资金管理是否选定的。
    lotMM = LotsOptimized(MagicNumber, Lots, Riskpercent, DecreaseFactor, AccountIsMini);
  else 
    lotMM = Lots;                          // 如资金管理未选定,Lots为预设值
  
  OrderText = "";                          
      
    if((CheckBuyCondition() == 1))            // 如果买入的条件存在着,传递参数给doorder ( ) 。
    {
        OrderText = "BUY";
        if (StopLoss>0)
         {
           Sl = Ask-StopLoss*Point;
         } 
         else 
         {
           Sl=0;
         }
        if (TakeProfit == 0) 
           Tr = 0;
        else
           Tr = Ask+TakeProfit*Point;
    }
    if (CheckSellCondition() == 1)  // 如果卖出的条件存在着,传递参数给doorder ( ) 。
    {
        OrderText = "SELL";
        if (StopLoss>0) 
         {
           Sl = Bid+StopLoss*Point;
         } 
         else 
         {
           Sl = 0;
         }
        if (TakeProfit == 0) 
           Tr = 0;
        else
           Tr = Bid-TakeProfit*Point;
    }
  if(OrderText != "" && TradesInThisSymbol == 0 && donttrade == 0 ) 
  {
       LastTime = DoTrades(OrderText,setup,MagicNumber, lotMM, Sl, Tr, CurTime(), Slippage);
      return(0);
  }  
  Comment("更多信息请访问hexun.com/pckr"); 
    return(0);
}
//********************************************************************
//********************************************************************
//+----------------------------------------------+
//| CheckExitCondition()                        |
//|                                              |
//| 平仓条件                                    |
//| return 0 for 条件不满足                      |
//| return 1 for 条件满足                        |
//+----------------------------------------------+
int CheckExitCondition(string type)
{
  if (type == "BUY")  
    { if(true) return(1);  //输入条件
      else  return(0);
      }
  if (type == "SELL")  //输入条件
    { if(true) return (1);
      else return(0);    
    } 
  
}
//********************************************************************
//********************************************************************
//+------------------------------------------+
//| CheckBuyCondition()                      |
//|                                          |
//| 定义买入条件                            |
//|                                          |
//| return 0 for 条件不满足                  |
//| return 1 for 条件满足                    |
//+------------------------------------------+
int CheckBuyCondition()
{
  if(
      true                          
  )                            
  return(1);
  else return (0);
}
//********************************************************************
//********************************************************************
//+------------------------------------------+
//| CheckSellCondition                      |
//|                                          |
//| 定义卖出条件                            |
//|                                          |
//| return 0 for 条件不满足                  |
//| return 1 for 条件满足                    |
//+------------------------------------------+
int CheckSellCondition()
{
    if(
    true
  )
        return(1);
      
  else return (0);
}
//********************************************************************
//********************************************************************
//+--------------------------------------------------------+
//|  TryClosePositions                                    |
//+--------------------------------------------------------+
int TryClosePositions(string type,int exitall)
{
  int ExitCondition;
  
  // Print(type);
  if (type == "BUY")
  {
      ExitCondition = CheckExitCondition("BUY");    //  First check if indicators cause exit
  
      if(exitall==1) ExitCondition = 1;                              // Then check if Friday
      HandleBuys(ExitCondition,Slippage,TakeProfit,MagicNumber);
  }  
  if (type == "SELL")
  {
      ExitCondition = CheckExitCondition("SELL");  //  First check if indicators cause exit
      
      if(exitall==1) ExitCondition = 1;                            // Then check if Friday
      HandleSells(ExitCondition,Slippage,TakeProfit,MagicNumber);
    }
    return (0);
} 
| //| | //| | | //+------------------------------------------------------------------+ #property copyright "Copyright @2006, pckr" #property link "http://hexun.com/pckr" #include












