<em id="8ntms"></em><progress id="8ntms"><track id="8ntms"></track></progress>
  • <em id="8ntms"></em>
    1. <tbody id="8ntms"><track id="8ntms"></track></tbody>
      1. 您現在的位置:程序化交易>> 外匯現貨>> MT5>> MT5知識>>正文內容

        MT5編程實例課程(阿郎)---第三講(均線交叉EA) [MT4]

        • #property copyright "Simon Yau"
          #property link "http://www.fx998.cn"
          #property version "1.00"
          int maFastHandle, maSlowHandle; //定義兩個指標操作句柄,用來操作兩條均線
          double maFast[], maSlow[]; //定義兩個數組,用于保存均線的數值
          //+------------------------------------------------------------------+
          //| Expert initialization function |
          //+------------------------------------------------------------------+
          int OnInit()
          {
          //---
          //在初始化函數OnInit中,分別指定兩個操作句柄所對應的均線指標
          maFastHandle = iMA(Symbol(), PERIOD_CURRENT, 5, 0, MODE_SMA, PRICE_CLOSE); //對應5期均線
          maSlowHandle = iMA(Symbol(), PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_CLOSE); //對應10期均線

          ArraySetAsSeries(maFast, true); //將數組設置為倒序保存,即圖表上方向由右向左
          ArraySetAsSeries(maSlow, true); //同上
          //---
          return(0);
          }
          //+------------------------------------------------------------------+
          //| Expert deinitialization function |
          //+------------------------------------------------------------------+
          //+------------------------------------------------------------------+
          //| Expert tick function |
          //+------------------------------------------------------------------+
          void OnTick()
          {
          //---
          MqlTradeRequest request;
          MqlTradeResult result;

          CopyBuffer(maFastHandle, 0, 0, 3, maFast); //將句柄對應的指標數值復制入數組
          CopyBuffer(maSlowHandle, 0, 0, 3, maSlow); //同上

          if (maFast[1]>maSlow[1] && maFast[2]<=maSlow[2]) //數組獲得指標的數值后,就可以進行均線交叉的判定了
          {
          request.action = TRADE_ACTION_DEAL;
          request.symbol = Symbol();
          request.volume = 0.1;
          request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
          request.type = ORDER_TYPE_BUY;

          OrderSend(request, result); //下單
          }
          else if (maFast[1]<maSlow[1] && maFast[2]>=maSlow[2])
          {
          request.action = TRADE_ACTION_DEAL;
          request.symbol = Symbol();
          request.volume = 0.1;
          request.price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
          request.type = ORDER_TYPE_SELL;

          OrderSend(request, result);
          }
          }
          作者:阿郎(shawnyau)栽自火線論壇http://www.fx998.cn。
          Lesson3代碼.rar (2 K) 下载次数:155

        【字體: 】【打印文章】【查看評論

        相關文章

          沒有相關內容
        真钱三公