10评论

0收藏

bands r2

avatar admin | 1734 人阅读 | 10 人评论 | 2018-01-18

XAUUSDM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                                        Bands.mq4 |
  3. //|        // //         Copyright ?2005, MetaQuotes Software Corp. |
  4. //|                                       http://www.metaquotes.net/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright ?2005, MetaQuotes Software Corp."
  7. #property link      "http://www.metaquotes.net/"
  8. //+------------------------------------------------------------------+
  9. //|                                                                  |
  10. //|    2008 Speech. Speech.tpl  Rev.2a 2008 ( itemsdepot@hotmail.com)|
  11. //|                                                                  |
  12. //+------------------------------------------------------------------+
  13. #property indicator_chart_window
  14. #property indicator_buffers 3
  15. #property indicator_color1 Gray
  16. #property indicator_color2 OliveDrab
  17. #property indicator_color3 Brown

  18. #property indicator_width1 1
  19. #property indicator_width2 3
  20. #property indicator_width3 3

  21. ////

  22. //---- indicator parameters
  23. extern bool   BBDrawBands=True;
  24. extern int    BandsDrawRange=100;
  25. extern int    BandsShift=0;
  26. extern double BandsDeviations=2.0;
  27. extern bool   BandsAlertBoxOn=False;
  28. extern bool   BandSoundAlertHighOn=True;
  29. extern bool   BandSoundAlertLowOn=True;
  30. extern string WaveBandName="bandup.wav";
  31. extern string WaveBandName2="banddown.wav";
  32. extern double BBAlarmDelay=22;
  33. extern int    BBCandleAlertRange=2;
  34. extern int    BandsMAPeriod=7;
  35. extern int    BBMovingAverage=0;
  36. extern string BBMovingAverageSettings="0-SMA,1-EMA,2-SMMA,3-LWMA";   // simple, exponential, smoothed , linear
  37. extern int    BBAppliedPrice=0;
  38. extern string BBAppliedPriceSettings1="0-Close,1-Open,2-High,3-Low";
  39. extern string BBAppliedPriceSettings2="4-Median,5-Typical,6-Weighted";
  40. extern double BBTime;

  41. //----------------- buffers
  42. double MovingBuffer[];
  43. double UpperBuffer[];
  44. double LowerBuffer[];
  45. double BBBreachLog[];

  46. //+------------------------------------------------------------------+
  47. //| Custom indicator initialization function                         |
  48. //+------------------------------------------------------------------+

  49. int init()
  50.   {
  51.    //---- indicators ------------------------------------------------
  52.    
  53.    IndicatorShortName("Bands R2");

  54.    if (BBDrawBands) SetIndexStyle(0,0,0,indicator_width1,indicator_color1);
  55.      else SetIndexStyle(0,12,0,indicator_width1,indicator_color1);     
  56.    SetIndexBuffer(0,MovingBuffer);
  57.    SetIndexDrawBegin(0,BandsDrawRange);
  58.    
  59.    if (BBDrawBands) SetIndexStyle(1,0,0,indicator_width2,indicator_color2);
  60.      else SetIndexStyle(1,12,0,indicator_width2,indicator_color2);        
  61.    SetIndexBuffer(1,UpperBuffer);
  62.    SetIndexDrawBegin(1,BandsDrawRange);
  63.    
  64.    if (BBDrawBands) SetIndexStyle(2,0,0,indicator_width3,indicator_color3);
  65.      else SetIndexStyle(2,12,0,indicator_width3,indicator_color3);         
  66.    SetIndexBuffer(2,LowerBuffer);
  67.    SetIndexDrawBegin(2,BandsDrawRange);   
  68.    
  69.    BBTime=TimeLocal();
  70.    return(0);
  71.   }
  72.   
  73.   
  74. //+------------------------------------------------------------------+
  75. //| Bollinger Bands                                                  |
  76. //+------------------------------------------------------------------+
  77. int start()
  78.   {
  79.   
  80.    int    i,k;
  81.    bool   BBSpeak=False;
  82.    double deviation;
  83.    double sum,oldval,newres;
  84.    double BBFinishTime=TimeCurrent();
  85.    
  86.    //----
  87.    if(Bars<=BandsDrawRange) return(0);
  88.    

  89.    //------------------------------------------------------------ Draw
  90.    
  91.    
  92.    for(i=BandsDrawRange; i>=0; i--)
  93.    {
  94.    
  95.       if (BBMovingAverage>3 && BBMovingAverage<0) BBMovingAverage=0;
  96.       if (BBAppliedPrice>6 && BBAppliedPrice<6 ) BBAppliedPrice=0;
  97.    
  98.       MovingBuffer[i]=iMA(NULL,0,BandsMAPeriod,BandsShift,BBMovingAverage,BBAppliedPrice,i);                  
  99.          
  100.       //---------------------
  101.       sum=0.0;
  102.       k=i+BandsMAPeriod-1;
  103.       oldval=MovingBuffer[i];
  104.       
  105.       while(k>=i)
  106.       {
  107.         newres=Close[k]-oldval;
  108.         sum+=newres*newres;
  109.         k--;
  110.       }   
  111.       deviation=BandsDeviations*MathSqrt(sum/BandsMAPeriod);     
  112.       if (oldval>0) UpperBuffer[i]=oldval+deviation;
  113.       if (oldval>0) LowerBuffer[i]=oldval-deviation;               
  114.          
  115.                   
  116.      } // ----------------------------------------- End Draw
  117.      
  118.      
  119.      
  120.      
  121.      //-------------------------------------------- Start Speak
  122.    
  123.      BBSpeak=False;
  124.      BBFinishTime=TimeLocal();
  125.                                                    
  126.      if ((BBFinishTime - BBTime) >= BBAlarmDelay )    // && pos==0)
  127.        {      
  128.            BBFinishTime=TimeLocal();
  129.            BBTime=TimeLocal();
  130.            BBSpeak=True;
  131.            
  132.        }        
  133.    
  134.      while (BBSpeak==True)
  135.      {
  136.         for(i=0; i<=BBCandleAlertRange; i++)
  137.         {
  138.           //--------------------------
  139.           if (High[i] > UpperBuffer[i])
  140.           {
  141.             if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" High Band Cross: "+High[i]);
  142.             if (BandSoundAlertHighOn==True) PlaySound(WaveBandName);
  143.             BBSpeak=False;
  144.           }
  145.          
  146.           if (Low[i] < LowerBuffer[i])
  147.           {
  148.             if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" Low Band Cross: "+Low[i]);
  149.             if (BandSoundAlertLowOn==True) PlaySound(WaveBandName2);
  150.             BBSpeak=False;
  151.           }
  152.        if (i >= BBCandleAlertRange) BBSpeak=False;
  153.        }           
  154.      }   
  155.      
  156.      //--------------------------------------------- End Speak

  157.    
  158.    return(0);
  159.   }
  160. //+------------------------------------------------- End initStart()
复制代码


BandsR2a.mq4
""
还没有人打赏,支持一下

评论|共 10 个

beyond

发表于 2020-2-29 12:10:45 | 显示全部楼层

LZ说的很不错

以瞬

发表于 2020-6-14 16:52:15 | 显示全部楼层

我是来刷分的,嘿嘿

ewpnhopn

发表于 2020-6-22 16:09:44 | 显示全部楼层

帮帮顶顶!!

ecuig

发表于 2020-7-14 14:23:36 | 显示全部楼层

谢谢楼主分享

诚意无价sz

发表于 2020-8-23 15:05:36 | 显示全部楼层

帮你顶下哈!!

joyce77939

发表于 2020-8-29 12:19:10 | 显示全部楼层

学习了,不错

伤心处

发表于 2020-9-1 19:31:25 | 显示全部楼层

谢谢楼主分享

huangj01

发表于 2020-9-3 21:08:06 | 显示全部楼层

谢谢楼主分享

hopyhua

发表于 2021-7-4 22:04:04 | 显示全部楼层

12下一页
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则