首先看效果图:

指标描述:   

这是一个做趋势的指标, 两根均线交叉, 在开仓点和平仓点把中间的差价表现出来了,还有最近2000根K线(这个数可以自己调整)一共产生了多少个交叉信号,一共有多少个盈利的信号,多少个亏损的信号,最大连续亏损多少次,最大连续盈利多少次,盈利最多的信号盈利了多少,亏损最多的信号亏损了多少。

指标源码: 

//+------------------------------------------------------------------+
//|                                                 均线交叉指标.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Silver
#property indicator_color2 DodgerBlue
#property indicator_color3 Red
#property indicator_color4 Lime
#property indicator_width1  1
#property indicator_width2  1
#property indicator_width3  0
#property indicator_width4  0
//+------------------------------------------------------------------+
input int    短期均线=13;
input int    ShorType=0;
input int    长期均线=55;
input int    LongType=0;
input int    字体大小=8;
input int    预设点差=10;
input bool   显示盈亏=true;
input bool   信号提醒=false;
input bool   显示轨迹=false;
input int    Barsback=2000;
//+------------------------------------------------------------------+
datetime LastTime;
string Names="Trade",Backgroundwidth="ggggg";
color  FontsColor=Chocolate,BackgroundColor=C'35,65,65';
double MA1,MA2,PreMA1,PreMA2,ShortMA[],LongMA[],CrossUp[],CrossDown[];
color  clor,WinClr=Red,LossClr=Lime,BuyColor=FireBrick,SellColor=LimeGreen;
int    StatsCorner=4,Bkgdpara=20,m,cnt,direction,lastcrossBar,MAxconseclosses,MAxconsecwins,conseclosses,consecwins;
double pipgains,TotalPips,TotalLosingPips,TotalWinningPips,TradeCount,LossCounts,WinCounts,WinPercent,MAXWinPips=0,MAXLossPips=0,MaxWins,MaxLoses;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(){
//--- indicator buffers mappingSetIndexBuffer(0,ShortMA);SetIndexStyle(0,DRAW_LINE,0);SetIndexDrawBegin(0,短期均线);SetIndexBuffer(1,LongMA);SetIndexStyle(1,DRAW_LINE,0);SetIndexDrawBegin(1,长期均线);SetIndexBuffer(2,CrossUp);SetIndexStyle(2,DRAW_ARROW);SetIndexArrow(2,233);SetIndexBuffer(3,CrossDown);SetIndexStyle(3,DRAW_ARROW);SetIndexArrow(3,234);
//---return(INIT_SUCCEEDED);}//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){DeleteObjects(Names);for(int i=ObjectsTotal(); i>=0; i--)if(StringFind(ObjectName(i),"JX",0)==0)ObjectDelete(ObjectName(i));}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],const double &open[],const double &high[],const double &low[],const double &close[],const long &tick_volume[],const long &volume[],const int &spread[]){
//---//--- return value of prev_calculated for next callreturn(rates_total);}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam){
//---ShowMA();DrawTraders();ShowTradeMsg();TimeRemains();TaijiandName();}
//+------------------------------------------------------------------+
void ShowMA(){int tempBars=Bars-长期均线-1;if(tempBars>Barsback) tempBars=Barsback;for(int i=0; i<tempBars; i++){MA1=iMA(NULL,0,短期均线,0,ShorType,PRICE_CLOSE,i);MA2=iMA(NULL,0,长期均线,0,LongType,PRICE_CLOSE,i);PreMA1=iMA(NULL,0,短期均线,0,ShorType,PRICE_CLOSE,i+1);PreMA2=iMA(NULL,0,长期均线,0,LongType,PRICE_CLOSE,i+1);ShortMA[i]=iMA(NULL,0,短期均线,0,ShorType,PRICE_CLOSE,i);LongMA[i]=iMA(NULL,0,长期均线,0,LongType,PRICE_CLOSE,i);//+--------------------多---------------------------+if(MA1>MA2 && PreMA1<PreMA2){CrossUp[i]=Close[i];if(信号提醒==true && i<=1 && Time[i]!=LastTime){LastTime=Time[i];Alert("均线多 ",Symbol()," , ",Period()," 分钟");}}elseCrossUp[i]=-1;//+--------------------空---------------------------+if(MA1<MA2 && PreMA1>PreMA2){CrossDown[i]=Close[i];if(信号提醒==true && i<=1 && Time[i]!=LastTime){LastTime=Time[i];Alert("均线空 ",Symbol()," , ",Period()," 分钟");}}elseCrossDown[i]=-1;}}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawTraders(){cnt=0;lastcrossBar=0;TotalPips=0;TotalLosingPips=0;TotalWinningPips=0;TradeCount=0;LossCounts=0;WinCounts=0;WinPercent=0;double Range=(iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,25,1))-iLow(NULL,0,iLowest(NULL,0,MODE_LOW,25,1)))/10;for(int i=0; i<Barsback-200; i++){pipgains=0;direction=0;MA1=iMA(NULL,0,短期均线,0,ShorType,PRICE_CLOSE,i);MA2=iMA(NULL,0,长期均线,0,LongType,PRICE_CLOSE,i);PreMA1=iMA(NULL,0,短期均线,0,ShorType,PRICE_CLOSE,i+1);PreMA2=iMA(NULL,0,长期均线,0,LongType,PRICE_CLOSE,i+1);//+--------------------多---------------------------+if(PreMA1<=PreMA2 && MA1>MA2){pipgains=Close[lastcrossBar]-Close[i]-预设点差*Point;if(显示轨迹){DrawOrderLine(GetUniqueName(Names+"trade"),Time[i],Close[i]+预设点差*Point,Time[lastcrossBar],Close[lastcrossBar],BuyColor,DoubleToStr(pipgains,1),STYLE_DOT);}direction=1;}//+--------------------空---------------------------+if(PreMA1>=PreMA2 && MA1<MA2){pipgains=Close[i]-Close[lastcrossBar]-预设点差*Point;if(显示轨迹){DrawOrderLine(GetUniqueName(Names+"trade"),Time[i],Close[i],Time[lastcrossBar],Close[lastcrossBar]+预设点差*Point,SellColor,DoubleToStr(pipgains,1),STYLE_DOT);}direction=-1;}TotalPips+=pipgains;if(pipgains<0){TradeCount++;LossCounts++;consecwins=0;conseclosses+=1;TotalLosingPips+=pipgains;MaxLoses=pipgains/Point;if(显示盈亏){DrawLabel(GetUniqueName(Names+"trade"),DoubleToStr(pipgains/Point,0),int(Time[lastcrossBar]),Close[lastcrossBar]-Range,字体大小,"Calibri",LossClr,3);}}if(pipgains>0){TradeCount++;WinCounts++;consecwins+=1;conseclosses=0;TotalWinningPips+=pipgains;MaxWins=pipgains/Point;if(显示盈亏){DrawLabel(GetUniqueName(Names+"trade"),DoubleToStr(pipgains/Point,0),int(Time[lastcrossBar]),Close[lastcrossBar]-Range,字体大小,"Calibri",WinClr,3);}}if(MAXLossPips>=MaxLoses){MAXLossPips=MaxLoses;}if(MAXWinPips<=MaxWins){MAXWinPips=MaxWins;}if(MAxconseclosses<conseclosses){MAxconseclosses=conseclosses;}if(MAxconsecwins<consecwins){MAxconsecwins=consecwins;}if(direction!=0){lastcrossBar=i;}}}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ShowTradeMsg(){string bg=Backgroundwidth;color colorr=FontsColor;if(TotalPips<0)colorr=Lime;if(TotalPips>0)colorr=Red;int x=10,y=0,dy=Bkgdpara;double PipslossPer=TotalLosingPips/(LossCounts*Point);double PipswinPer=TotalWinningPips/(WinCounts*Point);double WinLoseRate=-TotalWinningPips/TotalLosingPips;y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"Barsback :"+DoubleToStr(Barsback,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"短期均线 :"+DoubleToStr(短期均线,0),StatsCorner,x,y,字体大小,"Arial",Silver,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"长期均线 :"+DoubleToStr(长期均线,0),StatsCorner,x,y,字体大小,"Arial",DodgerBlue,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"预设点差 :"+DoubleToStr(预设点差,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"交易单量 :"+DoubleToStr(TradeCount,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"盈利单数 :"+DoubleToStr(WinCounts,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"亏损单数 :"+DoubleToStr(LossCounts,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"最大连胜 :"+DoubleToStr(MAxconsecwins,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"最大连亏 :"+DoubleToStr(MAxconseclosses,0),StatsCorner,x,y,字体大小,"Arial",Lime,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"盈利点数 :"+DoubleToStr(TotalWinningPips/Point,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"亏损点数 :"+DoubleToStr(TotalLosingPips/Point,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"总计点数 :"+DoubleToStr(TotalPips/Point,0),StatsCorner,x,y,字体大小,"Arial",colorr,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"每笔均亏 :"+DoubleToStr(PipslossPer,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"每笔均赢 :"+DoubleToStr(PipswinPer,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"单笔最亏 :"+DoubleToStr(MAXLossPips,0),StatsCorner,x,y,字体大小,"Arial",Lime,false);y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"单笔最赢 :"+DoubleToStr(MAXWinPips,0),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);if(TotalLosingPips!=0){y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"盈亏比值 :"+DoubleToStr(WinLoseRate,2),StatsCorner,x,y,字体大小,"Arial",FontsColor,false);}y+=dy;DrawFixedLabel(GetUniqueName(Names),bg,StatsCorner,x-5,y-5,16,"Webdings",BackgroundColor,false);DrawFixedLabel(GetUniqueName(Names),"策略胜率 :"+DoubleToStr(100*WinCounts/TradeCount,2)+"%",StatsCorner,x,y,字体大小,"Arial",FontsColor,false);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void TimeRemains(){int minute=int(Time[0]+60*Period()-TimeCurrent());int second=minute%60;minute=(minute-minute%60)/60;ObjectCreate("JX-time",OBJ_TEXT,0,Time[0],Close[0]);ObjectSetText("JX-time","               "+string(minute)+":"+string(second),10,"Verdana",Yellow);ObjectMove("JX-time",0,Time[0],Close[0]);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void TaijiandName(){m++;if(m>8)m=0;if(m>=0 && m<=2)clor=LossClr;if(m>=3 && m<=5)clor=White;if(m>=6 && m<=8)clor=WinClr;ObjectCreate("JX-taiji",OBJ_LABEL,0,0,0);ObjectSet("JX-taiji",OBJPROP_CORNER,2);ObjectSet("JX-taiji",OBJPROP_YDISTANCE,5);ObjectSet("JX-taiji",OBJPROP_XDISTANCE,5);ObjectSetText("JX-taiji",CharToStr(91),18,"WingDings",clor);ObjectCreate("JX-nm",OBJ_LABEL,0,0,0);ObjectSetText("JX-nm",AccountName()+" : "+DoubleToStr(AccountNumber(),0),10,"Arial",FontsColor);ObjectSet("JX-nm",OBJPROP_CORNER,2);ObjectSet("JX-nm",OBJPROP_XDISTANCE,33);ObjectSet("JX-nm",OBJPROP_YDISTANCE,10);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawOrderLine(string name,datetime starts,double startPrice,datetime ends,double endPrice,color c,string label,int style){ObjectCreate(name,OBJ_TREND,0,starts,startPrice,ends,endPrice);ObjectSet(name,OBJPROP_RAY,0);ObjectSet(name,OBJPROP_COLOR,c);ObjectSet(name,OBJPROP_STYLE,style);ObjectSetText(name,label,0);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawLabel(string objname,string s,int LTime,double LPrice,int FSize,string Font,color c,int width){if(ObjectFind(objname)<0){ObjectCreate(objname,OBJ_TEXT,0,LTime,LPrice);}else{if(ObjectType(objname)==OBJ_TEXT){ObjectSet(objname,OBJPROP_TIME1,LTime);ObjectSet(objname,OBJPROP_PRICE1,LPrice);}}ObjectSet(objname,OBJPROP_FONTSIZE,FSize);ObjectSetText(objname,s,FSize,Font,c);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawFixedLabel(string objname,string s,int Corner,int DX,int DY,int FSize,string Font,color c,bool sbg){ObjectCreate(objname,OBJ_LABEL,0,0,0);ObjectSet(objname,OBJPROP_CORNER,Corner);ObjectSet(objname,OBJPROP_XDISTANCE,DX);ObjectSet(objname,OBJPROP_YDISTANCE,DY);ObjectSet(objname,OBJPROP_BACK,sbg);ObjectSetText(objname,s,FSize,Font,c);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string GetUniqueName(string px){cnt++;return (px+" "+DoubleToStr(cnt,0));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DeleteObjects(string px){int L = StringLen(px);int i = 0;while(i<ObjectsTotal()){string ObjName=ObjectName(i);if(StringSubstr(ObjName,0,L)!=px){i++;continue;}ObjectDelete(ObjName);}}
//+------------------------------------------------------------------+
//| 程序结束                                                         |
//+------------------------------------------------------------------+

注意:本指标亲测可用,如果还有什么问题,可直接跟我联系80364276。
分享:

【漆天编程】最牛逼的均线交叉指标,做出了EA历史数据测试器的效果相关推荐

  1. 几位阿里朋友重写的Java并发编程,牛逼了

    昨天在黄金时代群里和读者聊机械键盘大 F 的时候,好朋友 cxuan 推了一篇文章,吸引了我的眼球,名叫"太赞了,阿里几位工程师重写了 <Java 并发编程>",我看完 ...

  2. 卧底各大程序员圈,才知道什么才是牛逼的程序员!

    来源:zhihu.com/question/27606439/answer/503448244 长期卧底各大程序员圈,总结出现实中那些牛逼程序员的主要表现症状,如下: 1.一般人写的代码花哨.重复,满 ...

  3. 什么样的程序员才是牛逼的程序员

    长期卧底各大程序员圈,总结出现实中那些牛逼程序员的主要表现症状,如下: 1.一般人写的代码花哨.重复,满是奇技淫巧,牛逼程序员写的代码简洁.有力,码风健壮. 2.都是一毕业就干开发,一般人薪水还不到 ...

  4. 编程十年 (2):前传2——哪有这么牛逼的游戏机?

    编程十年 (2):前传2--哪有这么牛逼的游戏机? 本文地址:http://www.cnblogs.com/AndersLiu/archive/2011/04/19/programming10year ...

  5. 在 B 站学编程,真滴牛逼!

    互联网让信息更容易触达,但是由于信息过于庞大,筛选出有价值的信息所花费的精力也会很大. 众所周知,B 站是一个学习的网站,很多人在 B 站上大学.考研.学编程,但 B 站的视频资源那更是五花八门,要从 ...

  6. 安卓编程用什么软件_震惊!安卓IOS都可以用的牛逼软件

    哈喽!小伙伴们大家好,在过去小辉辉推送的文章及软件中,小辉辉发现,大家普遍对观看影视的软件情有独钟,好了,为了满足大家一致的需求,小辉辉今天为大家推荐一个无论安卓手机还是苹果手机都可以用的牛逼影视观看 ...

  7. 虽然这些代码很少,就几行,但却很牛逼!

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 作者:编程艺术思维 来源:urlify.cn/jqUree ...

  8. 卸载Notepad++!事实已证明,它更牛逼……

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 作者:lucida lucida.me/blog/subl ...

  9. 推荐一位二本毕业1年,上海买房的大佬,牛逼!

    锋哥是我的好朋友,他二本毕业1年,靠自己一步步努力,挣钱攒钱,升职拿奖金,在上海结婚并买了第一套房,真的强! #22周岁,我完成了两件人生大事##其实,我曾经想当个北漂他自学编程从机械转行大数据,大二 ...

  10. 雷军这个程序员!真的牛逼!

    阅读本文大概需要3分钟. 这两天忙着给CEO汇报工作以及跟进几个新产品的进展,忙到连新闻都没时间看. 今天终于轻松了点,早上起来刷了刷知乎,看见一个让我惊呆了的消息:雷军要造车了!雷军宣称亲自带队,初 ...

最新文章

  1. |Tyvj|动态规划|P1004 滑雪
  2. Spring boot错误处理原理
  3. 讲一下python的背景知识
  4. java安全(二):JDBC|sql注入|预编译
  5. 我对NHibernate的感受(3):有些尴尬的集合支持
  6. Magento 移除标签 How to remove “Tags” block from a product page
  7. Mac 更适合做开发?从零把 Mac 打造成开发利器
  8. 关于csv文件转化为张量
  9. 帕特·基辛格被任命为英特尔CEO已有一年
  10. ajax datatype_jQuery中的 AJAX
  11. 微信公众号之生成带参数的二维码
  12. 体验引擎:游戏设计全景探秘
  13. Android进阶笔记12:ListView篇之图片优化
  14. WMI 错误 10的解决
  15. vue3笔记(乱七芭蕉更新中)
  16. 微信小程序~textarea字数限制与计算
  17. 青龙羊毛——酷狗滴滴
  18. ReadMe 好看指南
  19. 学渣的刷题之旅 leetcode刷题 13.罗马数字转整数
  20. 专防诈骗 法国新型信用卡密码随时变

热门文章

  1. 洛谷P3015 [USACO11FEB] Best Parenthesis
  2. 百度IP地址查询API使用: 应用类型为浏览器端
  3. 常用的特效功能实现代码
  4. vim中实现大小写转换
  5. 台式计算机mac地址查询,计算机mac地址查询
  6. 科幻链接现实:加密艺术的诞生与发展
  7. 青橙 GO M3 3G手机(珍珠黑)WCDMA/GSM 双卡双待 360特供机--高通胶水双核,A5老架构,内存缩水,,,强烈要求降价...
  8. 计算机作文英语初中,初中英语常见的作文类型及应对技巧
  9. 2011考研数学核心题型-陈文灯
  10. Git - IDEA中分支右侧上下箭头的含义