群里网友发帖,反编译后代码无法编译,寻求帮助的一个EA。
为了读懂改EA、便于交流,将变量、子函数位置改变下,注释中添加自己的理解。发帖学习加备忘【该EA高风险、逻辑前后不一致等,仅做学习用,不挂盘,及时是模拟盘】
下面源代码也经常错位,附带上传附件。
[ol][*]//+------------------------------------------------------------------+
[*]//| Website: eurcny.cn |
[*]//+------------------------------------------------------------------+
[*]
[*]//#include //注释了选择弹出窗口,无需导入该文件
[*]
[*]#define MAGICMA 20130604
[*]
[*]//extern string temp = "资金5000 下0.01手起步 EURUSD M15";//未使用,估计该EA最初设计是为EURUSD15图
[*]//extern string 一到七单加码间隔 = "?";//未使用,加单改用函数
[*]//extern string 八单以上加码间隔 = "";////未使用,加单改用函数
[*]
[*]extern string Commentt = "稳准狠一号EA";//订单注释文本
[*]extern int gi_268 = 5000;//帐号资金相关
[*]extern int 加码间隔点数一 = 15;
[*]extern int 加码间隔点数二 = 50;//存在一个10倍关系
[*]extern int 总体盈利点数 = 5;
[*]extern int K长度大于本点数时暂停运行EA = 15;
[*]extern bool 弹窗报警开关 = TRUE;
[*]extern int 有几个多单或空单持仓时暂停EA = 18;
[*]extern int 有几个持仓时见微利就平仓 = 8;
[*]extern double 多个持仓时到设定的获利额就平仓 = 200.0;
[*]extern double 当点差大于几个点时暂停EA = 5.0;
[*]extern bool 当净值小于余额的百分50暂停EA = TRUE;
[*]extern bool 达到设定的亏损额平仓 = FALSE;
[*]extern double 设定亏损额 = 1000.0;//仓位控制不如改成亏损比例
[*]extern bool 达到设定的获利额平仓 = FALSE;
[*]extern double 设定获利额 = 3000.0;
[*]extern double gd_260 = 1.5;//追加下单量倍率
[*]
[*]int isFive = 1;//四位 1,五位 10
[*]int newLotstep = 0;//新交易订单变量
[*]int priceInterval1 = 15;//加码间隔1
[*]int priceInterval2 = 500;//加码间隔2
[*]int AllProfitPoint = 5;//总体盈利点数profitPoint
[*]bool 屏幕显示 = FALSE;//屏幕显示开关
[*]int sleepTime = 1;//休眠时间(分钟)
[*]int getTicketNo;//订单编号
[*]int datetime1St = 0;//首次交易时间,不再1MIN K线开始时交易
[*]int datetimeNst = 0;//加仓交易时间,不再1MIN K线开始时交易
[*]int countBuyOrSell;//市场单中多单或空单数量
[*]bool goToBuy;//是否多单入场
[*]bool goToSell;//是否空单入场
[*]double firstBuyLots;//首次BUY订单交易量
[*]double firstSellLots;//首次SELL订单交易量
[*]double minLot = 0.01;//默认最小交易手数,而非MODE_MINLOT,及EA使用范围有额外要求
[*]int maxBuyOrders = 13;//单边最多BUY订单数量
[*]int maxSellOrders = 13;//单边最多SELL订单数量
[*]double nextBuyOrderLot;//追加多单下单量
[*]double nextSellOrderLot;//追加空单下单量
[*]bool gi_248 = FALSE;//判断是否使用变量倍数加仓 该变量无法在外部修改,LotExponent()未被使用
[*]bool gi_236 = FALSE;//是否根据上一个15分钟K线方法确定是否继续下单
[*]bool gi_240 = FALSE;//待确定 是否处理首次最小交易手数
[*]
[*]bool gi_244 = TRUE;//待确定 逻辑关系 该EA设计后期倍忽略
[*]double gd_196 = 1.0;//待确定 BUY 订单下单幅度,该数据的订单次方,如果是1,可忽略
[*]double gd_212 = 1.0;//待确定 SELL订单 下单幅度,该数据的订单次方,如果是1,可忽略
[*]
[*]
[*]//以下未定义初始值未实际调用
[*]//double g_bid_340;
[*]//double gd_348;
[*]
[*]//+------------------------------------------------------------------+
[*]//| NewLotstep() |
[*]//| 下单变量的自然对数/10的自然对数 绝对值然后取整数 |
[*]//+------------------------------------------------------------------+
[*]double NewLotstep()
[*] {
[*] int lotStep = MathCeil(MathAbs(MathLog(MarketInfo(Symbol(), MODE_LOTSTEP)) / MathLog(10)));
[*] return (lotStep);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| Information() |
[*]//| 屏幕显示信息 |
[*]//+------------------------------------------------------------------+
[*]void Information()
[*] {
[*] if (屏幕显示)
[*] {
[*] Comment("\n" + " 适合小资金运作的" + Symbol() + "" + "\n"
[*] + " ------------------------------------------------" + "\n"
[*] + " 平台商: " + AccountCompany() + " 杠杆 1:" + DoubleToStr(AccountLeverage(), 0) + "\n"
[*] + " ------------------------------------------------" + "\n"
[*] + " 多单个数:" + CountTrades("buy") + "\n"
[*] + " 多单获利:" + DoubleToStr(Balance("buy", "Balance"), 2)+ "\n"
[*] + " 多单手数: " + DoubleToStr(Balance("buy", "Lot"), 2) + "\n"
[*] + " ------------------------------------------------" + "\n"
[*] + " 空单个数:" + CountTrades("sell") + "\n"
[*] + " 空单获利:" + DoubleToStr(Balance("sell", "Balance"), 2) + "\n"
[*] + " 空单手数: " + DoubleToStr(Balance("sell", "Lot"), 2) + "\n"
[*] + " ------------------------------------------------" + "\n"
[*] + " 浮动盈亏: " + DoubleToStr(Balance("buy","Balance")+Balance("sell","Balance"),2)+ "\n"
[*] + " ------------------------------------------------" + "\n"
[*] + " 结合盘面行情在震荡回调幅度大于5%的行情使用,能做任何货币对,推荐低点差近距离挂单货币对" + "\n"
[*] + " ");
[*] }
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| CountTrades() |
[*]//| 统计订单数量 |
[*]//+------------------------------------------------------------------+
[*]int CountTrades(string buyOrSell)
[*] {
[*] int orderNo5 = 0;
[*] for(int orderNo6=OrdersTotal()-1;orderNo6>=0;orderNo6--)
[*] {
[*] OrderSelect(orderNo6, SELECT_BY_POS, MODE_TRADES);
[*] //if (OrderSymbol()!=Symbol() || OrderMagicNumber() != MAGICMA) continue;//MAGIC时而统计时而不统计,高风险,与下一句重复,忽略
[*] if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)//MAGIC时而统计时而不统计,高风险
[*] {
[*] if (buyOrSell== "buy") if (OrderType()==OP_BUY) orderNo5++;
[*] if (buyOrSell== "sell")if (OrderType()==OP_SELL) orderNo5++;
[*] }
[*] }
[*] return (orderNo5);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| Balance() |
[*]//| 统计订单浮动盈亏、手数 |
[*]//+------------------------------------------------------------------+
[*]double Balance(string buyOrSell, string as_8)
[*] {
[*] double ld_ret_16 = 0;
[*] for(int orderNo7 = OrdersTotal() - 1;orderNo7>= 0;orderNo7--)
[*] {
[*] OrderSelect(orderNo7, SELECT_BY_POS, MODE_TRADES);
[*] //if (OrderSymbol() != Symbol() || OrderMagicNumber() != MAGICMA) continue;//MAGIC时而统计时而不统计,高风险,与下一句重复,忽略
[*] if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)//MAGIC时而统计时而不统计,高风险
[*] {
[*] if(buyOrSell=="buy")
[*] {
[*] if(OrderType()==OP_BUY)
[*] {
[*] if (as_8 == "Balance") ld_ret_16 = ld_ret_16+OrderProfit()-OrderSwap()-OrderCommission();
[*] //OrderProfit()是否已经除去了OrderSwap()、OrderCommission()?
[*] if (as_8 == "Lot") ld_ret_16 += OrderLots();
[*] }
[*] }
[*] if(buyOrSell == "sell")
[*] {
[*] if(OrderType() == OP_SELL)
[*] {
[*] if(as_8 == "Balance") ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission();
[*] if(as_8 == "Lot") ld_ret_16 += OrderLots();
[*] }
[*] }
[*] }
[*] }
[*] return (ld_ret_16);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| NewLots() |
[*]//| 首次交易订单量 传递参数我任何意义,优化 |
[*]//+------------------------------------------------------------------+
[*]double NewLots()
[*] {
[*] double newMinlot;
[*] double modeMinlot = MarketInfo(Symbol(), MODE_MINLOT);
[*]// if (buyOrSell== "buy")//优化代码,删除传参
[*]// {
[*] if (gi_240) newMinlot = minLot;
[*] else newMinlot = NormalizeDouble(minLot*NormalizeDouble(AccountBalance()/gi_268,0),newLotstep);
[*]// }
[*]// if (buyOrSell== "sell")
[*]// {
[*]// if (gi_240) newMinlot = minLot;
[*]// else newMinlot=NormalizeDouble(minLot*NormalizeDouble(AccountBalance()/gi_268,0),newLotstep);
[*]// }//buy or sell 一样,优化代码
[*] if (newMinlot = 0;orderNo8--)
[*] {
[*] OrderSelect(orderNo8, SELECT_BY_POS, MODE_TRADES);
[*] //if (OrderSymbol() != Symbol() || OrderMagicNumber() != MAGICMA) continue;
[*] //MAGIC时而统计时而不统计,高风险,与下一句重复,忽略
[*] if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)//MAGIC时而统计时而不统计,高风险
[*] {
[*] if (buyOrSell == "buy")
[*] {
[*] if(OrderType()==OP_BUY)
[*] {
[*] newTakeProfit = allAvePrice + AllProfitPoint * isFive * Point;
[*] //if (OrderTakeProfit()!=newTakeProfit)OrderModify(OrderTicket(),allAvePrice,OrderStopLoss(),newTakeProfit,0,Yellow);
[*] //OrderModify可以修改收盘价格? 将收盘价格改回订单入场价
[*] if (OrderTakeProfit()!=newTakeProfit)OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),newTakeProfit,0,Yellow);
[*] }
[*] }
[*] if (buyOrSell == "sell")
[*] {
[*] if (OrderType() == OP_SELL)
[*] {
[*] newTakeProfit =allAvePrice - AllProfitPoint * isFive * Point;
[*] //if (OrderTakeProfit()!=newTakeProfit)OrderModify(OrderTicket(),allAvePrice,OrderStopLoss(),newTakeProfit,0,Yellow);
[*] if (OrderTakeProfit()!=newTakeProfit)OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),newTakeProfit,0,Yellow);
[*] }
[*] }
[*] }
[*] }
[*] }
[*]
[*]
[*]//+------------------------------------------------------------------+
[*]//| AveragePrice() |
[*]//| 计算订单平均价格 |
[*]//+------------------------------------------------------------------+
[*]double AveragePrice(string buyOrSell)
[*] {
[*] double avePrice = 0;
[*] double countLots = 0;
[*] for (int orderNo9 = OrdersTotal()-1;orderNo9>=0;orderNo9--)
[*] {
[*] OrderSelect(orderNo9, SELECT_BY_POS, MODE_TRADES);
[*] //if (OrderSymbol() != Symbol() || OrderMagicNumber() != MAGICMA) continue;
[*] //MAGIC时而统计时而不统计,高风险,与下一句重复,忽略
[*] if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)//MAGIC时而统计时而不统计,高风险
[*] {
[*] if (buyOrSell == "buy")
[*] {
[*] if (OrderType() == OP_BUY)
[*] {
[*] avePrice+= OrderOpenPrice() * OrderLots();
[*] countLots+= OrderLots();
[*] }
[*] }
[*] if (buyOrSell == "sell")
[*] {
[*] if (OrderType() == OP_SELL)
[*] {
[*] avePrice+= OrderOpenPrice() * OrderLots();
[*] countLots+= OrderLots();
[*] }
[*] }
[*] }
[*] }
[*] avePrice= NormalizeDouble(avePrice/countLots, Digits);
[*] return (avePrice);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| NextOrder() |
[*]//| 判断是否继续下单 |
[*]//+------------------------------------------------------------------+
[*]//int NextOrder(string buyOrSell) {//更正数据类型 INT型虽然也可以编译
[*]bool NextOrder(string buyOrSell)
[*] {
[*] int extentToOrder;//价格波动多少区间后继续下单
[*] bool isPlaceOrder = FALSE;//是否下订单
[*]
[*] //优化代码中重复调用函数的计算
[*] int buyCountTrades=CountTrades("buy");
[*] int sellCountTrades=CountTrades("sell");
[*]
[*] double lastClose = iClose(Symbol(), PERIOD_M15, 1);
[*] double lastOpen = iOpen(Symbol(), PERIOD_M15, 1);
[*] if (buyOrSell=="buy")
[*] {
[*] extentToOrder = NormalizeDouble(priceInterval1*MathPow(gd_196,buyCountTrades), 0);
[*] //1的X次方还是1啊....
[*] if (buyCountTrades== 7) extentToOrder = priceInterval2 / 10;
[*] if (buyCountTrades== 8) extentToOrder = priceInterval2 / 10;
[*] if (buyCountTrades== 9) extentToOrder = priceInterval2 / 10;
[*] if (buyCountTrades== 10) extentToOrder = priceInterval2 / 10;
[*] if (buyCountTrades== 11) extentToOrder = priceInterval2 / 6;
[*] if (buyCountTrades== 12) extentToOrder = priceInterval2 / 6;
[*] if (buyCountTrades== 13) extentToOrder = priceInterval2 / 4;
[*] if (FindLastOrder(buyOrSell, "Price")-Ask>=extentToOrder*isFive*Point && CountTrades(buyOrSell) =extentToOrder*isFive*Point && CountTrades(buyOrSell)= lastClose) isPlaceOrder = TRUE;
[*] else isPlaceOrder = FALSE;
[*] }
[*] else isPlaceOrder = TRUE;
[*] }
[*] }
[*] return (isPlaceOrder);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| FindLastOrder() |
[*]//| 判断最后一个订单的入场价格或手数 |
[*]//+------------------------------------------------------------------+
[*]double FindLastOrder(string buyOrSell, string as_8)
[*] {
[*] double lastOrderOpen;
[*] double lastOrderLots;
[*] int lastOrderTicket= 0;
[*] for (int orderNo10=OrdersTotal()-1;orderNo10>= 0;orderNo10--)
[*] {
[*] OrderSelect(orderNo10, SELECT_BY_POS, MODE_TRADES);
[*] //if (OrderSymbol() != Symbol() || OrderMagicNumber() != MAGICMA) continue;
[*] //MAGIC时而统计时而不统计,高风险,与下一句重复,忽略
[*] if (OrderSymbol() == Symbol() && OrderMagicNumber()==MAGICMA)//MAGIC时而统计时而不统计,高风险
[*] {
[*] if (buyOrSell == "buy")
[*] {
[*] if (OrderType() == OP_BUY)
[*] {
[*] if (OrderTicket() > lastOrderTicket)//使用订单时间也许更好
[*] {
[*] lastOrderOpen = OrderOpenPrice();
[*] lastOrderLots = OrderLots();
[*] lastOrderTicket= OrderTicket();
[*] }
[*] }
[*] }
[*] if (buyOrSell == "sell")
[*] {
[*] if (OrderType() == OP_SELL)
[*] {
[*] if (OrderTicket() > lastOrderTicket)
[*] {
[*] lastOrderOpen = OrderOpenPrice();
[*] lastOrderLots = OrderLots();
[*] lastOrderTicket= OrderTicket();
[*] }
[*] }
[*] }
[*] }
[*] }
[*] if (as_8 == "Price") return (lastOrderOpen);
[*] if (as_8 == "Lots") return (lastOrderLots);
[*] return (0.0);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| NextLot() |
[*]//| 计算继续下单订单下单手数 |
[*]//+------------------------------------------------------------------+
[*]double NextLot(string buyOrSell)
[*] {
[*] double nextOrderLot;
[*] if (gi_248) gd_260 = LotExponent();//判断是否使用变量倍数加仓
[*] if (buyOrSell == "buy") nextOrderLot = NormalizeDouble(FindLastOrder(buyOrSell, "Lots") * gd_260, newLotstep);
[*] if (buyOrSell == "sell")nextOrderLot = NormalizeDouble(FindLastOrder(buyOrSell, "Lots") * gd_260, newLotstep);
[*] return (nextOrderLot);
[*] }
[*]
[*]//+------------------------------------------------------------------+
[*]//| LotExponent() 默认该函数未被调用 |
[*]//| 计算继续下单订单下单倍率 |
[*]//+------------------------------------------------------------------+
[*]double LotExponent()
[*] {
[*] double ld_0 = 0;
[*] double nextOrderLotRatio = 1;
[*] while (ld_0 = K长度大于本点数时暂停运行EA * isFive * Point)
[*] {
[*] if (弹窗报警开关 != TRUE) return (0);
[*] Alert("上根K线长度大于设定的长度,可能仍然在单边行情中,所以在本根K线暂停运行EA");
[*] return (0);
[*] }
[*] if (MathAbs(Bid - iOpen(NULL,0, 0)) >= K长度大于本点数时暂停运行EA * isFive * Point ||
[*] MathAbs(iHigh(NULL,0,0)-iLow(NULL,0,0)) >= K长度大于本点数时暂停运行EA * isFive * Point)
[*] {
[*] if (弹窗报警开关 != TRUE) return (0);
[*] Alert("最新K线长度大于设定的长度,可能是单边行情的起点或仍然在单边行情中,所以在本根K线立即暂停运行EA");
[*] return (0);
[*] }
[*]
[*] //348 340开始未定义初始值后期未调用
[*] //gd_348 = MathAbs(Bid - g_bid_340);
[*] //g_bid_340 = Bid;
[*]
[*]
[*]//以下检测多订单平仓条件,统计订单中判断MAGIC,平仓未判断,存在风险
[*] int orderBuyCount = 0;//多单订单数量统计
[*] int orderSellCount = 0;//空单订单数量统计
[*] for (int orderNo1 = 0;orderNo1 = 有几个持仓时见微利就平仓 || orderSellCount >= 有几个持仓时见微利就平仓 &&
[*] // AccountProfit() >= 多个持仓时到设定的获利额就平仓)
[*] if(MathMax(orderBuyCount,orderSellCount)>=有几个多单或空单持仓时暂停EA ) return(0);
[*] if(MathMax(orderBuyCount,orderSellCount)>=有几个持仓时见微利就平仓 && AccountProfit() >= 多个持仓时到设定的获利额就平仓)
[*] {
[*] for (int orderNo2 = OrdersTotal() - 1;orderNo2>= 0;orderNo2--)
[*] {
[*] OrderSelect(orderNo2, SELECT_BY_POS, MODE_TRADES);
[*] if (OrderType()==OP_BUY && OrderSymbol()==Symbol())//统计订单中判断MAGIC,平仓未判断,存在风险
[*] {
[*] OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),0,CLR_NONE);//最高滑点数为0,存在平单失败的风险
[*] //Alert("有多个多单持仓时,当获利达到设定的获利额多空单就一次性全部平仓");//有报警,不适合在VPS上运行,改打印
[*] Print("有多个多单持仓时,当获利达到设定的获利额多空单就一次性全部平仓");
[*] }
[*] if (OrderType()==OP_SELL && OrderSymbol()==Symbol())//统计订单中判断MAGIC,平仓未判断,存在风险
[*] {
[*] OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);//最高滑点数为0,存在平单失败的风险
[*] //Alert("有多个空单持仓时,当获利达到设定的获利额多空单就一次性全部平仓");//有报警,不适合在VPS上运行,改打印
[*] Print("有多个空单持仓时,当获利达到设定的获利额多空单就一次性全部平仓");
[*] }
[*] }
[*] }
[*]//多单平仓代码结束----------------------------------
[*]
[*]//判断暂停EA下单代码
[*] if(Ask-Bid>=当点差大于几个点时暂停EA*isFive*Point) return (0);
[*] if(当净值小于余额的百分50暂停EA && AccountEquity()= 0;orderNo3--)
[*] {
[*] OrderSelect(orderNo3, SELECT_BY_POS, MODE_TRADES);
[*] if(OrderType()= 设定获利额)
[*] {
[*] for(int orderNo4= OrdersTotal() - 1;orderNo4>= 0;orderNo4--)
[*] {
[*] OrderSelect(orderNo4, SELECT_BY_POS, MODE_TRADES);
[*] if(OrderType() 0 && NextOrder("buy"))
[*] {
[*] nextBuyOrderLot = NextLot("buy");
[*] while (getTicketNo 0 && NextOrder("sell"))
[*] {
[*] nextSellOrderLot = NextLot("sell");
[*] while (getTicketNo 复制代码
|