评论

收藏

非常不错的学习模板

avatar 智慧 | 348 人阅读 | 0 人评论 | 2022-02-13

input int tratp=300;//盈利多少点
input int tp=150;//止损调高到盈利多少点
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int total=OrdersTotal();
   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i, SELECT_BY_POS))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderStopLoss()<OrderOpenPrice()+tp*Point && OrderClosePrice()-OrderOpenPrice()>tratp*Point)
                 {
                  bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+tp*Point, OrderTakeProfit(), 0);
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if((OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-tp*Point) && OrderOpenPrice()-OrderClosePrice()>tratp*Point)
                 {
                  bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-tp*Point, OrderTakeProfit(), 0);
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则