📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    据说是比较好的mt4样本

    2011-10-09 · 5203 阅读
    样本EA代码,功能齐全
      稍作修改即得成品
      
      //+------------------------------------------------------------------+                                 
      //|                                       大家要顶呀,我是新手,支持我!
      //+------------------------------------------------------------------+
      #property copy* "Copy* 2009 tom 的EA"
      #property link     
      extern string    basic1="==== MegaTrend参数 ====================";
      extern    int period=15;
      extern   int   method=3;                         // MODE_SMA
      extern  int    pr*=0;
      extern string    basic="==== Basic Settings ====================";
      extern double    TakeProfit=100;
      extern double    Stoploss=50;
      extern double    原始手数=0.1;
              double   Lots;
      extern int       加仓次数=2;
      extern string    averages="==== MA Settings ====================";
      extern int       FastPeriod=5;                   // Period for calculating MA
      extern int       FastShift=0;                    // Shift the MA over X number of bars
      extern int       FastType=0;                     // 0: ** moving average
                                                       // 1: Exponential moving average
                                                       // 2: Smoothed moving average
                                                       // 3: Linear weighted moving average
                                                       
      extern int       FastApplication=0;              // 0: Close pr*
                                                       // 1: Open pr*
                                                       // 2: High pr*
                                                       // 3: Low pr*
                                                       // 4: Median pr*, (high+low)/2
                                                       // 5: Typical pr*, (high+low+close)/3
                                                       // 6: Weighted close pr*, (high+low+close+close)/4
      extern int       SlowPeriod=21;
      extern int       SlowShift=0;
      extern int       SlowType=0;
      extern int       SlowApplication=0;
      extern string    manage="==== Order Management ====================";
      extern int       BreakEvenAtProfit=0;
      extern int       BreakEvenShift=0;               // Move the breakeven point up or down around the order open pr*
      extern int       TrailingStop=30;
      extern bool      OnlyTrailAfterProfit=false;     // Trailing Stop will only trails when order is profitable
      extern string    account="==== Account Settings ====================";
      extern int       MinimumEquity=0;                // New orders will be disabled if equity drops below minimum
      extern int       MinimumBalance=0;               // New orders will be disabled if balance drops below minimum
      extern string    activity="==== EA Activity Settings ====================";
      extern bool      DisableClosingOrders=false;    // If true, the order closing section of the EA will not run
      extern bool      DisableNewOrders=false;        // If true, the order creating section of the EA will not run
      extern int       ConcurrentOrdersMax=1;         // Maximum number of orders at any one time
      extern string    id="==== Identity Settings ====================";
      extern int       ExpertID=127792141;            // Magic number: for identifying an EA\'s orders
      extern bool      TimeSpecific=false;            // If true, Time frames are considered in determining
                                                      // whether an order belongs to the EA or not
                                                      
                                                      
                                                      
             string    ExpertName="www.imt4.com";    // Expert name: for aesthetic purposes
      int BuySellSig=-1; //买卖信号
      datetime lastTradeTime = 0;
      //+------------------------------------------------------------------+
      //| expert initialization function                                   |
      //+------------------------------------------------------------------+
      int init()
        {
         Comment(ExpertName + " is waiting for the next tick to begin.");
         return(0);
        }
      //+------------------------------------------------------------------+
      //| expert deinitialization function                                 |
      //+------------------------------------------------------------------+
      int deinit()
        {
         return(0);
        }
      //+------------------------------------------------------------------+
      //| expert start function                                            |
      //+------------------------------------------------------------------+
      int start()
        {
        手数加倍计算();
         Comment(ExpertName + " has started.");
         int buyOrders=0, sellOrders=0, buyPending=0, sellPending=0;
         checkOrderStatus(buyOrders, sellOrders, buyPending, sellPending);
         int instantOrders = buyOrders + sellOrders;
         int pendingOrders = buyPending + sellPending;
         int allOrders     = instantOrders + pendingOrders;
         advancedStopManager(instantOrders);
      //+------------------------------------------------------------------+
      //| variable and indicator declaration                               |
      //+------------------------------------------------------------------+
         if (FastType3)
            FastType=0;
         if (FastApplication6)
            FastType=0;
         if (SlowType3)
            SlowType=0;
         if (SlowApplication6)
            SlowType=0;
            
         /*   
         double fastMA0 = iMA(NULL,0,FastPeriod,FastShift,FastType,FastApplication,1);
         double fastMA1 = iMA(NULL,0,FastPeriod,FastShift,FastType,FastApplication,2);
         double slowMA0 = iMA(NULL,0,SlowPeriod,SlowShift,SlowType,SlowApplication,1);
         double slowMA1 = iMA(NULL,0,SlowPeriod,SlowShift,SlowType,SlowApplication,2);
      */
      BuySellSig=BuyorSell();
      //Print(BuySellSig);
      //+------------------------------------------------------------------+
      //| close existing orders under apprpriate conditions                |
      //+------------------------------------------------------------------+
         if (DisableClosingOrders==false && allOrders>0)  {
      //+------------------------------------------------------------------+
      //+------------------------------------------------------------------+
         if (sellOrders==1)
            if (BuySellSig==0)
               closeSellOrder();
         if (buyOrders==1)
            if (BuySellSig==1)
               closeBuyOrder();
          
            
      //+------------------------------------------------------------------+
      //+------------------------------------------------------------------+
            }
      //+------------------------------------------------------------------+
      //| create new orders                                                |
      //+------------------------------------------------------------------+
         if (newOrderPrevention(allOrders) == false && Time[0] != lastTradeTime)  {
      //+------------------------------------------------------------------+
      //+------------------------------------------------------------------+
         if (buyOrders==0)
            if (BuySellSig==0)
            {
               lastTradeTime = Time[0];
               sendBuyOrder();
            }
         if (sellOrders==0)
            if (BuySellSig==1)
            {
               lastTradeTime = Time[0];
               sendSellOrder();
            }
      //+------------------------------------------------------------------+
      //+------------------------------------------------------------------+
            }
         return(0);
        }
       
      //+------------------------------------------------------------------+
      //| middle-man modules                                               |
      //+------------------------------------------------------------------+
      void sendBuyOrder() // Standard Version 1.71
      { versatileOrderTaker(1, Ask); }
         
      //+------------------------------------------------------------------+
      void sendSellOrder() // Standard Version 1.71
      { versatileOrderTaker(2, Bid); }
      //+------------------------------------------------------------------+
      void closeSellOrder() // Standard Version 1.71
      { versatileOrderCloser(2); }
      //+------------------------------------------------------------------+
      void closeBuyOrder() // Standard Version 1.71
      { versatileOrderCloser(1); }
      //+------------------------------------------------------------------+
      //+------------------------------------------------------------------+
      //| modules and functions                                            |
      //+------------------------------------------------------------------+
      void trailingStopManager() // Standard Version 1.71
      {
         
         int cnt, total = OrdersTotal();
         for(cnt=0;cnt0 && orderBelongsToMe())
            {
               if (OrderType()==OP_BUY)
               {
                  if ((Bid-OrderOpenPr*()>

    据说是比较好的mt4样本

    据说是比较好的mt4样本
    oint*TrailingStop) || OnlyTrailAfterProfit==false)
                  {
                     if (OrderStopLoss()Point*TrailingStop) || OnlyTrailAfterProfit==false)
                  {
                     if ((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                        OrderModify(OrderTicket(),OrderOpenPr*(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                  }
               }
            }  
         }
      }
      //+------------------------------------------------------------------+
      void breakEvenManager() // Standard Version 1.71
      {
         for(int cnt=0;cnt0 && orderBelongsToMe())
            {
               if (OrderType()==OP_BUY)
               {
                  if (Bid-OrderOpenPr*()>=Point*BreakEvenAtProfit)
                  {
                     if (OrderStopLoss()!=OrderOpenPr*() + BreakEvenShift*Point)
                        OrderModify(OrderTicket(),OrderOpenPr*(),OrderOpenPr*()+ BreakEvenShift*Point,OrderTakeProfit(),0,Green);
                  }
               }
               else if (OrderType()==OP_SELL)
               {
                  if (OrderOpenPr*()-Ask>=Point*BreakEvenAtProfit)
                  {
                     if (OrderStopLoss()!=OrderOpenPr*() - BreakEvenShift*Point)
                        OrderModify(OrderTicket(),OrderOpenPr*(),OrderOpenPr*()- BreakEvenShift*Point,OrderTakeProfit(),0,Red);
                  }
               }
            }
         }
      }
         
      //+------------------------------------------------------------------+
      // Standard Version 1.71
      void checkOrderStatus(int& buyOrders,int& sellOrders,int& buyPending, int& sellPending)
      {
         for(int cnt=OrdersTotal();cnt>=0;cnt--)
         {
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if ( orderBelongsToMe() )
            {  
               if (OrderType()==OP_BUY)
                  {buyOrders++;}
               else if (OrderType()==OP_SELL)
                  {sellOrders++;}
               else if (OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
                  {buyPending++;}
               else if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)
                  {sellPending++;}
            }
         }
      }
      //+------------------------------------------------------------------+
      void advancedStopManager(int instantOrders) // Standard Version 1.71
      {
          
         if (instantOrders>=1)
         {
            if (BreakEvenAtProfit>0)
               breakEvenManager();
            if (TrailingStop>0)
               trailingStopManager();
          }
      }
      //+------------------------------------------------------------------+
      bool orderBelongsToMe() // Standard Version 1.71
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==**MagicGenerator() )
             return (true);
         else
            return (false);
      }
      //+------------------------------------------------------------------+
      int **MagicGenerator() // Standard Version 1.71
      {
         int truMagic;
         
         if (TimeSpecific)
            truMagic = ExpertID + (Period()*17 + 203);
         else
            truMagic = ExpertID;      
         return (truMagic);
      }
      //+------------------------------------------------------------------+
      string commentString() // Standard Version 1.71
      {
         string tfString, fullComment;
         
         switch (Period())  
         {   
            case 1:      tfString = "1 Min";    break;
            case 5:      tfString = "5 Min";    break;
            case 15:     tfString = "15 Min";   break;  
            case 30:     tfString = "30 Min";   break;  
            case 60:     tfString = "1 Hour";   break;  
            case 240:    tfString = "4 Hour";   break;  
            case 1440:   tfString = "Daily";    break;  
            case 10080:  tfString = "Weekly";   break;  
            case 40320:  tfString = "Monthly";  break;  
            default:     tfString = "Unknown";   
         }
         fullComment=StringConcatenate(ExpertName, ": ", tfString);
         return (fullComment);
      }
      
      未完,见2楼
    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 16 个

    anbuimn LV5

    发表于 2012-11-25 16:59:05 | 显示全部楼层

    i love you

    yangsluo LV7

    发表于 2012-11-25 16:59:05 | 显示全部楼层

    请发一个试试,谢谢!RongYuanQiong@163.com 。。。  

    yiyang LV5

    发表于 2012-11-25 18:27:51 | 显示全部楼层

    今天无聊来逛逛  

    牛策反 LV6

    发表于 2012-11-25 18:27:51 | 显示全部楼层

    楼主也是培训师吗  

    wenken123 LV4

    发表于 2012-11-25 18:27:51 | 显示全部楼层

    请发一个试试,谢谢!RongYuanQiong@163.com 。。。  

    lljia LV4

    发表于 2012-11-25 18:27:51 | 显示全部楼层

    呵呵 大家好奇嘛 来观看下~~~~  

    45646 LV4

    发表于 2012-11-25 18:27:51 | 显示全部楼层

    哎 怎么说那~~  

    木兰花花 LV2

    发表于 2013-5-7 15:39:29 | 显示全部楼层

    ‘未完,见2楼’,没有么

    心事难寄 LV3

    发表于 2015-3-31 04:30:52 | 显示全部楼层

    看看,看看。谢谢。你要发,我也要发。
    12下一页
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服