周六到了,侠哥继续给大家安排EA源码。
今天分享的这个是以前很火的一款老EA,叫聚宝盆2.0。它属于网格马丁类策略,但不是完全无脑乱开仓,而是加入了均线方向过滤和分组管理逻辑。
先说它的优点。
第一,多空订单分开管理。多单和空单用不同识别编号,统计、加仓、平仓互不干扰,复盘和管理会更清楚。
第二,它不是纯盲网格。首单会参考大周期均线方向,只在符合趋势判断的时候启动,相比那种什么行情都硬开仓的网格EA,逻辑上会更规整一点。
第三,它有分组止盈和动态平仓。既可以整体达到目标后统一出场,也可以根据盈利情况分批处理,行情稍微回撤时,能先锁一部分利润。
第四,它限制了最大订单数量和最大持仓手数,不会无限制加仓,至少从代码层面给仓位设了一道边界。

但缺点也必须讲清楚。
它默认的均线周期非常长,信号会比较滞后,适合看大方向,不适合短线频繁切换。一旦行情突然反转,均线很可能反应不过来。
另外,它本质上还是网格马丁。只要遇到趋势反转后的深度回调,同方向仓位越堆越多,浮亏压力还是会很大。
还有一个问题,它更偏向先处理盈利单,亏损单容易留下来,长期运行可能出现小赚不断、大亏难受的情况。
最关键的是,它没有硬止损逻辑。遇到极端行情、跳空或者黑天鹅,风险会非常大。
所以这类EA适合研究和回测,不建议直接重仓实盘跑。源码我放下面了,不会编译或者报错的朋友,可以来找侠哥拿。
私信侠哥:wzc10106 源码我放下面了,需要的自取!
#property copyright ""#property link ""#property version "1.0"#property strict#property indicator_chart_window#property indicator_buffers 2#property indicator_color1 clrBlue#property indicator_color2 clrRed#property indicator_width1 2#property indicator_width2 2input int Distance = 20; // Arrow distance from Hi/Loenum alert{Off = 0, // OffCurrent = 1, // At current barPrevious = 2 // At previous closed bar};input alert notificationsOn = 1; // Notificationsinput bool desktop_notifications = true; // Desktop MT4 notificationsinput bool email_notifications = false; // Email notificationsinput bool push_notifications = false; // Push mobile notificationsinput bool sound_notifications = false; // Sound notificationsinput string sound_file = "Tick.wav"; // Choose a sound file for notificationsdouble BufferUP[];double BufferDO[];string shortname = "3Bars_HL";//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intinit(){SetIndexStyle(0, DRAW_ARROW);SetIndexStyle(1, DRAW_ARROW);SetIndexArrow(0, 233);SetIndexArrow(1, 234);SetIndexBuffer(0, BufferUP);SetIndexBuffer(1, BufferDO);SetIndexLabel(0, "UP");SetIndexLabel(1, "DOWN");SetIndexEmptyValue(0, EMPTY_VALUE);SetIndexEmptyValue(1, EMPTY_VALUE);IndicatorShortName("Outside_Last_Dir");return(0);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intdeinit(){return(0);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intstart(){int S, limit;if(Bars <= 4)return(0);if(IndicatorCounted() < 0)return(-1);bool nb = IsNewBar();if(nb)limit = Bars - 4;elselimit = 4;for(int i = 0 ; i < limit; i++){S = form(i);BufferUP[i] = EMPTY_VALUE;BufferDO[i] = EMPTY_VALUE;switch(S){case 1:BufferUP[i] = Low[i] - Distance * Point;break;case -1:BufferDO[i] = High[i] + Distance * Point;break;}}if(notificationsOn > 0){checkAlert(nb);}return(0);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intform(int bar){if(Close[bar] > High[bar + 1] && Close[bar] > High[bar + 2] && Close[bar] > High[bar + 3])return 1;if(Close[bar] < Low[bar + 1] && Close[bar] < Low[bar + 2] && Close[bar] < Low[bar + 3])return -1;return(0);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+boolIsNewBar(){static datetime lastbar;datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE);if(lastbar != curbar){lastbar = curbar;return true;}return false;}//+------------------------------------------------------------------+bool alerted;voidcheckAlert(bool nb){if(nb)alerted = false;if(notificationsOn == 1 && !alerted){if(BufferUP[0] > 0 && BufferUP[0] != EMPTY_VALUE){Notify(1);alerted = true;}if(BufferDO[0] > 0 && BufferDO[0] != EMPTY_VALUE){Notify(2);alerted = true;}}if(notificationsOn == 2 && nb){if(BufferUP[1] > 0 && BufferUP[1] != EMPTY_VALUE){Notify(11);}if(BufferDO[1] > 0 && BufferDO[1] != EMPTY_VALUE){Notify(22);}}}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidNotify(int type){string text = shortname + ": ";switch(type){case 1:text += " Turn UP before bar closes - " + _Symbol + " " + GetTimeFrame(_Period);break;case 2:text += " Turn DOWN before bar closes - " + _Symbol + " " + GetTimeFrame(_Period);break;case 11:text += " Turned UP after bar closed - " + _Symbol + " " + GetTimeFrame(_Period);break;case 22:text += " Turned DOWN after bar closed - " + _Symbol + " " + GetTimeFrame(_Period);break;}text += " ";if(desktop_notifications)Alert(text);if(push_notifications)SendNotification(text);if(email_notifications)SendMail("MetaTrader Notification", text);if(sound_notifications)PlaySound(sound_file);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+stringGetTimeFrame(int lPeriod){switch(lPeriod){case PERIOD_M1:return ("M1");case PERIOD_M5:return ("M5");case PERIOD_M15:return ("M15");case PERIOD_M30:return ("M30");case PERIOD_H1:return ("H1");case PERIOD_H4:return ("H4");case PERIOD_D1:return ("D1");case PERIOD_W1:return ("W1");case PERIOD_MN1:return ("MN1");}return IntegerToString(lPeriod);}由于时间有限加上对源码的追溯做不到最终解释权,所以我们提供的源码EA仅仅只能用来做模拟测试使用,严格禁止
夜雨聆风