HI,大家好,我是侠哥!
周三没行情,正好适合整理点源码给大家。最近分享的EA源码,很多朋友反馈不错,也有兄弟私信我说:侠哥,能不能做一款专门控制风险的辅助EA?不是用来开单赚钱,而是用来管账户、管仓位、管自己手痒。
这个想法我觉得很有必要。因为很多人亏钱,不一定是策略太差,而是风控太松,做着做着就上头了。

所以这款辅助EA的定位很简单:它不负责判断方向,只负责限制风险。 核心功能主要有几个。
第一,单笔最大亏损限制。每一单如果亏损达到设定金额,EA会自动处理,避免一笔单子越拖越大。
第二,单日开仓次数限制。当天交易次数用完,就不允许继续开仓,专门防止频繁交易和情绪化下单。
第三,账户浮亏比例限制。如果整体浮亏达到设定比例,EA会直接禁止新开仓,防止亏损状态下继续加仓扩大风险。
第四,持仓品种数量限制。比如最多同时交易几个品种,超过数量就不让再开,避免账户太分散、风险不好控制。

特别是喜欢追单、扛单、连续下单的朋友,这类辅助EA不是为了让你赚更多,而是先让你少犯错。
交易里,控制风险永远比抓机会更重要。机会没了还有下一次,本金没了就真的难受了。 源码我整理好了,需要的朋友可以自取;不会编译的,也可以来问侠哥。
私信侠哥:wzc10106 源码我放下面了,需要的自取!
extern int BarsToCheck = 3456;extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;extern int CCIPeriod = 45; //15,extern ENUM_APPLIED_PRICE CCIPrice = PRICE_TYPICAL;extern int HotLevel = 100; //70,extern color Rectangle1 = C'150,60,60'; //0x4040a0;extern color Rectangle2 = C'60,60,150'; //0x804040;extern bool PlusATR = false,ShowLines = false,RayRight = false;extern int HowH1forRay = 96;extern ENUM_LINE_STYLE RayStyle = STYLE_DOT;extern int AlertBar = 1;extern bool AlertsMessage = true, //false,AlertsSound = true, //false,AlertsEmail = false,AlertsMobile = false;extern string SoundFile = "alert2.wav"; //"news.wav"; //"news.wav", //"stops.wav" //"expert.wav"//****************************************************************************//*** Custom indicator buffers ***//****************************************************************************double CCI[]; int TFK, SGB; string BH2xID, sTFR, cTFR; datetime TimeBar=0;//****************************************************************************//*** Custom indicator initialization function ***//****************************************************************************int init(){TimeFrame = fmax(TimeFrame,_Period); TFK = TimeFrame/_Period; sTFR = StringSubstr(EnumToString(TimeFrame),7); cTFR = StringSubstr(EnumToString(ENUM_TIMEFRAMES(_Period)),7); //IndikName = WindowExpertName();//---CCIPeriod = MathMax(CCIPeriod,2); SGB = AlertBar*TFK;//---IndicatorBuffers(1); IndicatorDigits(0); //(Digits-Digits%2);//-----SetIndexBuffer(0,CCI); SetIndexStyle(0,DRAW_NONE);//-----BH2xID = "BH'CCI'TT["+(string)BarsToCheck+":"+(string)CCIPeriod+">"+StringSubstr(EnumToString(CCIPrice),6)+"±"+(string)HotLevel+"]";//-----return(0);}//****************************************************************************//*** Custom indicator deinitialization function ***//****************************************************************************int deinit() { delete_objects_containing(BH2xID); return(0); }//-----//-----void delete_objects_containing(string bhname){for (int i=ObjectsTotal()-1; i>=0; i--){ if (StringFind(ObjectName(i),bhname)>= 0)ObjectDelete(ObjectName(i)); }}//****************************************************************************//*** Custom indicator iteration function ***//****************************************************************************int start(){int counted_bars=IndicatorCounted(); if (BarsToCheck<CCIPeriod) BarsToCheck = Bars-3-CCIPeriod;delete_objects_containing(BH2xID);int hh, ll, sh, sl, eh=0, el=0; /*double p;*/ int lastHH=0, lastLL=0;double RangeATR = PlusATR ? iATR(NULL,TimeFrame,CCIPeriod,iBarShift(NULL,TimeFrame,Time[0])) /*/CCIPeriod*/ : 0; //10*Point; //оригинал....//****************************************************************************while ( (eh >= 0 && eh < BarsToCheck) || (el >= 0 && el < BarsToCheck) ) //for (e=0; e>=0 && e<BarsToCheck; e++) //{find_last_stoch_high(eh+1, hh, sh, eh); //p = High[h]; //оригинал....find_last_stoch_low (el+1, ll, sl, el); //p = Low[h]; //оригинал....//-----if (eh > 0){ObjectCreate(BH2xID+"H"+sh, OBJ_RECTANGLE, 0, Time[sh-1], High[hh]+RangeATR, Time[eh+1], Low[sh]-RangeATR);ObjectSet(BH2xID+"H"+sh, OBJPROP_HIDDEN,false);ObjectSet(BH2xID+"H"+sh, OBJPROP_COLOR, Rectangle1);}//---if (el > 0){ObjectCreate(BH2xID+"L"+sl, OBJ_RECTANGLE, 0, Time[sl-1], Low[ll] - RangeATR, Time[el+1], High[sl]+RangeATR);ObjectSet(BH2xID+"L"+sl, OBJPROP_HIDDEN,false);ObjectSet(BH2xID+"L"+sl, OBJPROP_COLOR, Rectangle2);}//-----if (lastHH>0 && ShowLines && iBarShift(NULL,PERIOD_H1,Time[hh])<=HowH1forRay) // && High[last_h] < p ){ //ObjectCreate(BH2xID+"D"+sh, OBJ_TREND, 0, Time[h], p, Time[last_h], High[last_h]); //оригинал....ObjectCreate(BH2xID+"D"+sh, OBJ_TREND, 0, Time[hh], High[hh], Time[lastHH-1], Low[lastHH-1]);ObjectSet(BH2xID+"D"+sh, OBJPROP_RAY, RayRight);ObjectSet(BH2xID+"D"+sh, OBJPROP_HIDDEN,false);ObjectSet(BH2xID+"D"+sh, OBJPROP_COLOR, Rectangle1 -15); //RedObjectSet(BH2xID+"D"+sh, OBJPROP_STYLE, RayStyle);} else ObjectDelete(BH2xID+"D"+sh);//-----if (lastLL>0 && ShowLines && iBarShift(NULL,PERIOD_H1,Time[ll])<=HowH1forRay) // && Low[last_h] > p ){ //ObjectCreate(BH2xID+"U"+sl, OBJ_TREND, 0, Time[h], p, Time[last_h], Low[last_h]); //оригинал....ObjectCreate(BH2xID+"U"+sl, OBJ_TREND, 0, Time[ll], Low[ll], Time[lastLL-1], High[lastLL-1]);ObjectSet(BH2xID+"U"+sl, OBJPROP_RAY,RayRight);ObjectSet(BH2xID+"U"+sl, OBJPROP_HIDDEN,false);ObjectSet(BH2xID+"U"+sl, OBJPROP_COLOR, Rectangle2 -15); //LimeObjectSet(BH2xID+"U"+sl, OBJPROP_STYLE, RayStyle);} else ObjectDelete(BH2xID+"U"+sl);//-----lastHH = hh;lastLL = ll;}//****************************************************************************for (int e=BarsToCheck; e>=0; e--) { CCI[e]=0; CCI[e] = iCCI(NULL,TimeFrame,CCIPeriod,CCIPrice,iBarShift(NULL,TimeFrame,Time[e])); }//****************************************************************************//*** BH CCI Alerts TT [x3] ***//****************************************************************************if (AlertsMessage || AlertsEmail || AlertsMobile || AlertsSound){string messageDN = "BH CCI TT << "+_Symbol+", "+cTFR+" << Signal DN << SELL"; //HA CLH 3C TTstring messageUP = "BH CCI TT >> "+_Symbol+", "+cTFR+" >> Signal UP >> BUY"; //HA CLH 3C TT//-----if (TimeBar!=iTime(NULL,TimeFrame,0) && CCI[SGB] < HotLevel && CCI[1+SGB] >= HotLevel){if (AlertsMessage) Alert(messageDN);if (AlertsEmail) SendMail(Symbol(),messageDN);if (AlertsMobile) SendNotification(messageDN);if (AlertsSound) PlaySound(SoundFile); //"stops.wav" //"news.wav"TimeBar=iTime(NULL,TimeFrame,0); //return(0);}//-----else if (TimeBar!=iTime(NULL,TimeFrame,0) && CCI[SGB] > -HotLevel && CCI[1+SGB] <= -HotLevel){if (AlertsMessage) Alert(messageUP);if (AlertsEmail) SendMail(Symbol(),messageUP);if (AlertsMobile) SendNotification(messageUP);if (AlertsSound) PlaySound(SoundFile); //"stops.wav" //"news.wav"TimeBar=iTime(NULL,TimeFrame,0); //return(0);}}//------return(0);}//****************************************************************************//*** BH CCI Alerts TT [x3] ***//****************************************************************************void find_last_stoch_high(int x, int& p, int& s, int& e){s = -1;e = -1;p = x;//-----for (int i=x; i<x+BarsToCheck; i++){if (iCCI(NULL,TimeFrame,CCIPeriod,CCIPrice,iBarShift(NULL,TimeFrame,Time[i])) > HotLevel){p = i;s = i;break;}}//-----if (s>0)for (i=s+1; i<s+BarsToCheck; i++){if (iCCI(NULL,TimeFrame,CCIPeriod,CCIPrice,iBarShift(NULL,TimeFrame,Time[i])) < HotLevel){e = i-1;break;}else { if (iHigh(NULL,TimeFrame,iBarShift(NULL,TimeFrame,Time[i])) > High[p]) p = i; }}}//****************************************************************************//*** BH CCI Alerts TT [x3] ***//****************************************************************************void find_last_stoch_low(int x, int& p, int& s, int& e){s = -1;e = -1;p = x;//-----for (int i=x; i<x+BarsToCheck; i++){if (iCCI(NULL,TimeFrame,CCIPeriod,CCIPrice,iBarShift(NULL,TimeFrame,Time[i])) < -HotLevel){p = i;s = i;break;}}//-----if (s>0)for (i=s+1; i<s+BarsToCheck; i++) //iCCI(NULL,0,CCIPeriod,CCIPrice,i){if (iCCI(NULL,TimeFrame,CCIPeriod,CCIPrice,iBarShift(NULL,TimeFrame,Time[i])) > -HotLevel){e = i-1;break;}else { if (iLow(NULL,TimeFrame,iBarShift(NULL,TimeFrame,Time[i])) < Low[p]) p = i; }}}由于时间有限加上对源码的追溯做不到最终解释权,所以我们提供的源码EA仅仅只能用来做模拟测试使用,严格禁止商业使用和跑实盘!
夜雨聆风