有您的持续关注
我们会做得更好

智能交易系统 疯狗1 EA



疯狗1 EA名字取的有点啥味道?

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。疯狗1 EA源码:

//+------------------------------------------------------------------+
//|                                                        疯狗1.mq4 |
//|                                                           红之汇 |
//|                                                    qq:712933993 |
//+------------------------------------------------------------------+
#property copyright "红之汇"
#property link      "qq:712933993"

extern double FirstLots = 0.1;
extern int PipsAddOrder = 5;
extern int PipsTakeProfit = 5;
extern int PipsStopLoss = 5;
extern int AddOrdTimeMax = 10;
extern int Slippage = 3;
extern int MagicNumber = 888888;

static bool OpenCondition = TRUE;
static double MaxLots = 0;
bool cg = false;

int init() {
   MaxLots = MarketInfo(Symbol(), MODE_MAXLOT);
   ObjectCreate("comment_label", OBJ_LABEL, 0, 0, 0);
   ObjectSet("comment_label", OBJPROP_XDISTANCE, 50);
   ObjectSet("comment_label", OBJPROP_YDISTANCE, 20);
   ObjectSetText("comment_label", "紅之匯【瘋狗系統】①黛", 20, "Arial", Red);
   return (0);
}

int deinit() {
   ObjectDelete("comment_label");
   Comment("www.125808047.com");
   return (0);
}

int start() {
    //double HighIn4 = iHigh(Symbol(), 0, iHighest(Symbol(), 0, MODE_HIGH, 4, 1));
    //double LowIn4 = iLow(Symbol(), 0, iLowest(Symbol(), 0, MODE_LOW, 4, 1));
    double ima=iMA( NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, 1) ;
     
    if (AccountFreeMargin() <= 100.0) {
        Alert("No money!");
        return (0);
    }
   
    int OriginalLots = 0;
    if( OrdersTotal() != 0) {
       for (int i = 0; i < OrdersTotal(); i++) {
          cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
          if (OrderMagicNumber() == MagicNumber)
              OriginalLots++;
       }
    }
   
    if (OpenCondition == FALSE && OriginalLots != 0)
        CloseAllOrder();
   
    if (OriginalLots == 0) {
        OpenCondition = TRUE;
        if (Close[1] > ima)
            cg = OrderSend(Symbol(), OP_BUY, FirstLots, NormalizeDouble(Ask, Digits), 
                Slippage, 0, 0, "Order Buy", MagicNumber, 0, Blue);
        else if (Close[1] < ima)
           cg =  OrderSend(Symbol(), OP_SELL, FirstLots, NormalizeDouble(Bid, Digits), 
                Slippage, 0, 0, "Order Sell", MagicNumber, 0, Red);
    }
   
    double BuyLotsCount = 0;
    double SellLotsCount = 0;
    double LastOrderOpenPrice=0;
    int OrderCount = 0;
    int LastBuyTicket = 0;
    int LastSellTicket = 0;
    double LargestBuyLots = 0;
    double LargestSellLots = 0;
   
    if (OrdersTotal() != 0) {
        for (i = 0; i < OrdersTotal(); i++) {
            cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber){
                if (OrderTicket() > LastBuyTicket) 
                    LastBuyTicket = OrderTicket();
                if (OrderLots() > LargestBuyLots) 
                    LargestBuyLots = OrderLots();
                OrderCount++;
                BuyLotsCount += OrderLots();
            }else if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber){
                if (OrderTicket() > LastSellTicket) 
                    LastSellTicket = OrderTicket();
                if (OrderLots() > LargestSellLots) 
                    LargestSellLots = OrderLots();
                OrderCount++;
                SellLotsCount += OrderLots();
            }
        }
      
        bool SystemNormal = true;
        if(BuyLotsCount != 0 && SellLotsCount != 0)
            SystemNormal = FALSE;
        else
            SystemNormal = TRUE;
        if (SystemNormal == FALSE){
            Alert("System Error.Please close the hedge orders.");
            return (0);
        }
      
        int CurrentOrderDirection;
        if (BuyLotsCount != 0 && SellLotsCount == 0) 
            CurrentOrderDirection = 1;
        else if (BuyLotsCount == 0 && SellLotsCount != 0) 
            CurrentOrderDirection = -1;
        else
            CurrentOrderDirection = 0;
      
        if(SystemNormal == TRUE) {
            if(CurrentOrderDirection == 1) {
                for (i = 0; i < OrdersTotal(); i++) {
                    cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
                    if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber)
                        if (OrderTicket() == LastBuyTicket) 
                            LastOrderOpenPrice = OrderOpenPrice();
                }
                if (Bid - LastOrderOpenPrice >= PipsTakeProfit * Point) 
                    CloseAllOrder();
                if (LastOrderOpenPrice - Ask >= PipsAddOrder * Point)
                    if (OrderCount <= AddOrdTimeMax && 2 * LargestBuyLots <= MaxLots)
                        cg = OrderSend(Symbol(), OP_BUY, 2 * LargestBuyLots, NormalizeDouble(Ask, Digits), 
                            Slippage, 0, 0, "Order Buy", MagicNumber, 0, Red);
                if (OrderCount >= AddOrdTimeMax && LastOrderOpenPrice - Bid >= PipsStopLoss * Point)
                    CloseAllOrder();
            }else if (CurrentOrderDirection == -1) {
                for (i = 0; i < OrdersTotal(); i++) {
                    cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
                    if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber)
                        if (OrderTicket() == LastSellTicket) 
                            LastOrderOpenPrice = OrderOpenPrice();
                }
                if (LastOrderOpenPrice - Ask >= PipsTakeProfit * Point) 
                    CloseAllOrder();
                if (Bid - LastOrderOpenPrice >= PipsAddOrder * Point)
                    if (OrderCount <= AddOrdTimeMax && 2.0 * LargestSellLots <= MaxLots) 
                        cg = OrderSend(Symbol(), OP_SELL, 2.0 * LargestSellLots, NormalizeDouble(Bid, Digits), 
                            Slippage, 0, 0, "Order Sell", MagicNumber, 0, Red);
                if (OrderCount >= AddOrdTimeMax && Ask - LastOrderOpenPrice >= PipsStopLoss * Point) 
                    CloseAllOrder();
            }
       }
    }
    return (0);
}

void CloseAllOrder(){
    bool SucceedClose = FALSE;
    for (int j= OrdersTotal() - 1; j >= 0; j--) {
       cg =  OrderSelect(j,SELECT_BY_POS, MODE_TRADES);
        if ((OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderMagicNumber() == MagicNumber) 
            SucceedClose=OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(),Digits), 
                Slippage, CLR_NONE);
    }
    OpenCondition = FALSE;
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 智能交易系统 疯狗1 EA
上一篇:
下一篇:
分享到:更多 ()