分享

双均线交叉报警指标源码公布!

 li0k 2014-08-16
  1. #property indicator_chart_window
  2. #property indicator_buffers 4
  3. #property indicator_color1 Yellow
  4. #property indicator_color2 White
  5. #property indicator_color3 Yellow
  6. #property indicator_color4 White

  7. //---- input parameters
  8. extern int 均线周期1=10;
  9. extern int 均线周期2=130;
  10. extern int 类型1=1; //类型: 0-SMA; 1-EMA; 2-SMMA; 3-LWMA
  11. extern int 类型2=1; //类型: 0-SMA; 1-EMA; 2-SMMA; 3-LWMA
  12. extern string 类型说明="0-SMA; 1-EMA; 2-SMMA; 3-LWMA";
  13. extern int 文字水平=0;
  14. extern int 文字垂直=0;
  15. extern int 文字大小=14;
  16. extern string 文字标识="1";
  17. extern color 文字颜色=Yellow;
  18. extern int 是否报警=1;
  19. extern int 是否发邮件=1;
  20. //---- buffers
  21. double Ma10[];
  22. double Ma130[];
  23. double Up[];
  24. double Down[];
  25. int TimeInMinute;
  26. int FlagAlert=0;
  27. //+------------------------------------------------------------------+
  28. //| Custom indicator initialization function |
  29. //+------------------------------------------------------------------+
  30. int init()
  31. {
  32. //---- indicators
  33. IndicatorBuffers(4);
  34. SetIndexStyle(0,DRAW_LINE);
  35. SetIndexStyle(1,DRAW_LINE);
  36. SetIndexStyle(2,DRAW_ARROW);
  37. SetIndexStyle(3,DRAW_ARROW);
  38. SetIndexBuffer(0,Ma10);
  39. SetIndexBuffer(1,Ma130);
  40. SetIndexBuffer(2,Up);
  41. SetIndexBuffer(3,Down);
  42. SetIndexArrow(2,233);
  43. SetIndexArrow(3,234);
  44. TimeInMinute=0;
  45. //----
  46. return(0);
  47. }

  48. int start()
  49. {
  50. int i;
  51. int limit;
  52. string Signal;
  53. int counted_bars=IndicatorCounted();
  54. //---- check for possible errors
  55. if(counted_bars<0) return(-1);
  56. //---- the last counted bar will be recounted
  57. if(counted_bars>0) counted_bars--;
  58. limit=Bars-counted_bars;
  59. for (i=limit-1;i>=0;i--)
  60. {
  61. Ma10[i]=iMA(NULL,0,均线周期1,0,类型1,PRICE_CLOSE,i);
  62. Ma130[i]=iMA(NULL,0,均线周期2,0,类型2,PRICE_CLOSE,i);
  63. if ((Ma10[i+1]<Ma130[i+1])&&(Ma10[i]>Ma130[i])&&(Close[i]>Ma10[i])&&(Close[i]>Ma130[i]))
  64. {
  65. Signal="["+Period()+"分钟]"+TimeMonth(Time[i]+TimeInMinute)+"月"+TimeDay(Time[i]+TimeInMinute)+"日"+TimeHour(Time[i]+TimeInMinute)+"点"+TimeMinute(Time[i]+TimeInMinute)+"分 "+Symbol()+"在价格"+DoubleToStr(Close[i],4)+"发生"+均线周期1+"均线上穿"+均线周期2+"均线";
  66. writetext(文字标识,Signal,20+文字水平,40+文字垂直,文字颜色,文字大小);
  67. Up[i]=Low[i]-3*Point;
  68. if (i==0)
  69. {
  70. if (FlagAlert==0)
  71. {
  72. if (是否报警==1)
  73. Alert(Signal);
  74. if (是否发邮件==1)
  75. SendMail(Signal,Signal);
  76. FlagAlert=1;
  77. }
  78. }
  79. }
  80. if ((Ma10[i+1]>Ma130[i+1])&&(Ma10[i]<Ma130[i])&&(Close[i]<Ma10[i])&&(Close[i]<Ma130[i]))
  81. {
  82. Signal="["+Period()+"分钟]"+TimeMonth(Time[i]+TimeInMinute)+"月"+TimeDay(Time[i]+TimeInMinute)+"日"+TimeHour(Time[i]+TimeInMinute)+"点"+TimeMinute(Time[i]+TimeInMinute)+"分 "+Symbol()+"在价格"+DoubleToStr(Close[i],4)+"发生"+均线周期1+"均线下穿"+均线周期2+"均线";
  83. writetext(文字标识,Signal,20+文字水平,40+文字垂直,文字颜色,文字大小);
  84. Down[i]=High[i]+3*Point;
  85. if (i==1)
  86. {
  87. if (FlagAlert==0)
  88. {
  89. if (是否报警==1)
  90. Alert(Signal);
  91. if (是否发邮件==1)
  92. SendMail(Signal,Signal);
  93. FlagAlert=1;
  94. }
  95. }
  96. }else FlagAlert=0;
  97. }
  98. return(0);
  99. }
  100. void writetext(string Labelname,string data,int x,int y,color ColorValue,int FontSize)//通过Object写文字
  101. {
  102. ObjectDelete(Labelname);
  103. ObjectCreate(Labelname, OBJ_LABEL, 0, 0, 0);
  104. ObjectSetText(Labelname, data, FontSize, "Arial", ColorValue);
  105. ObjectSet(Labelname, OBJPROP_CORNER, 0);
  106. ObjectSet(Labelname, OBJPROP_XDISTANCE, x);
  107. ObjectSet(Labelname, OBJPROP_YDISTANCE, y);
  108. }
--------------------------------------

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多