【MT4指标】Stoller 平均范围通道

0
回复
5779
查看
[复制链接]

95

主题

18

回帖

515

积分

高级会员

积分
515
来源: 2019-7-26 09:22:25 显示全部楼层 |阅读模式
Stoller 平均范围通道是由 Manning Stoller 在1980年代早期开发的, 根据ATR组件的波动, 通道会有所缩放.

STARC (或 Stoller Average Range Channels) 带用于计算市场的波动.

基础公式如下:

上面部分(Upper Band): SMA(6) + 2 * ATR(15)

下面部分(Lower Band): SMA(6) - 2 * ATR(15)

一般的判断逻辑是:

如果价格接近通道上沿, 买入风险较高而卖出风险较低. 相反, 如果价格接近通道下沿, 卖出风险较高而买入风险较低.


下面我们看一下源码:
  1. //+------------------------------------------------------------------+
  2. //|                                                   StarcBands.mq4 |
  3. //|                      Copyright 2019, MetaQuotes Software Corp. |
  4. //|                                       http://www.geekquant.com/ |
  5. //|                                                    geekquant 2019 |
  6. //+------------------------------------------------------------------+
  7. #property copyright "Copyright 2019, MetaQuotes Software Corp."
  8. #property link      "http://www.geekquant.com/"
  9. //----
  10. #property indicator_chart_window
  11. #property indicator_buffers 3
  12. #property indicator_color1 clrPurple
  13. #property indicator_color2 clrBlue
  14. #property indicator_color3 clrRed
  15. //---- indicator parameters
  16. extern int    BandsPeriod=6;
  17. extern int    ATR=15;
  18. extern double Multiplier = 2.0;
  19. extern int    BandsShift = 0;
  20. //---- buffers
  21. double MovingBuffer[];
  22. double UpperBuffer[];
  23. double LowerBuffer[];
  24. //+------------------------------------------------------------------+
  25. //| Custom indicator initialization function                         |
  26. //+------------------------------------------------------------------+
  27. int init()
  28.   {
  29. //---- indicators
  30.    SetIndexStyle(0,DRAW_LINE);
  31.    SetIndexBuffer(0,MovingBuffer);
  32. //---
  33.    SetIndexStyle(1,DRAW_LINE);
  34.    SetIndexBuffer(1,UpperBuffer);
  35. //---
  36.    SetIndexStyle(2,DRAW_LINE);
  37.    SetIndexBuffer(2,LowerBuffer);
  38. //----
  39.    SetIndexDrawBegin(0,BandsPeriod+BandsShift);
  40.    SetIndexDrawBegin(1,BandsPeriod+BandsShift);
  41.    SetIndexDrawBegin(2,BandsPeriod+BandsShift);
  42. //----
  43.    return(0);
  44.   }
  45. //+------------------------------------------------------------------+
  46. //| Bollinger Bands                                                  |
  47. //+------------------------------------------------------------------+
  48. int start()
  49.   {
  50.    int i,k,counted_bars=IndicatorCounted();
  51.    double deviation;
  52.    double sum,oldval,newres;
  53. //----
  54.    if(Bars<=BandsPeriod)
  55.       return(0);
  56. //---- initial zero
  57.    if(counted_bars<1)
  58.       for(i=1; i<=BandsPeriod; i++)
  59.         {
  60.          MovingBuffer[Bars-i]= EMPTY_VALUE;
  61.          UpperBuffer[Bars-i] = EMPTY_VALUE;
  62.          LowerBuffer[Bars-i] = EMPTY_VALUE;
  63.         }
  64. //----
  65.    int limit=Bars-counted_bars;
  66.    if(counted_bars>0)
  67.       limit++;
  68.    for(i=0; i<limit; i++)
  69.       MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,
  70.                           MODE_SMA,PRICE_CLOSE,i);
  71. //----
  72.    i=Bars-BandsPeriod+1;
  73.    if(counted_bars>BandsPeriod-1)
  74.       i=Bars-counted_bars-1;
  75.    while(i>=0)
  76.      {
  77.       sum=0.0;
  78.       k=i+BandsPeriod-2;
  79.       oldval=MovingBuffer[i];
  80.       while(k>=i)
  81.         {
  82.          newres=Close[k]-oldval;
  83.          sum+=newres*newres;
  84.          k--;
  85.         }
  86.       deviation=Multiplier*iATR(NULL,0,ATR,i); // MathSqrt(sum / BandsPeriod);
  87.       UpperBuffer[i] = oldval + deviation;
  88.       LowerBuffer[i] = oldval - deviation;
  89.       i--;
  90.      }
  91. //----
  92.    return(0);
  93.   }
  94. //+------------------------------------------------------------------+
复制代码
欢迎学习交流

       股票.jpg

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册
关注微信