|
Stoller 平均范围通道是由 Manning Stoller 在1980年代早期开发的, 根据ATR组件的波动, 通道会有所缩放.
STARC (或 Stoller Average Range Channels) 带用于计算市场的波动.
基础公式如下:
上面部分(Upper Band): SMA(6) + 2 * ATR(15)
下面部分(Lower Band): SMA(6) - 2 * ATR(15)
一般的判断逻辑是:
如果价格接近通道上沿, 买入风险较高而卖出风险较低. 相反, 如果价格接近通道下沿, 卖出风险较高而买入风险较低.
下面我们看一下源码:
- //+------------------------------------------------------------------+
- //| StarcBands.mq4 |
- //| Copyright 2019, MetaQuotes Software Corp. |
- //| http://www.geekquant.com/ |
- //| geekquant 2019 |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2019, MetaQuotes Software Corp."
- #property link "http://www.geekquant.com/"
- //----
- #property indicator_chart_window
- #property indicator_buffers 3
- #property indicator_color1 clrPurple
- #property indicator_color2 clrBlue
- #property indicator_color3 clrRed
- //---- indicator parameters
- extern int BandsPeriod=6;
- extern int ATR=15;
- extern double Multiplier = 2.0;
- extern int BandsShift = 0;
- //---- buffers
- double MovingBuffer[];
- double UpperBuffer[];
- double LowerBuffer[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- //---- indicators
- SetIndexStyle(0,DRAW_LINE);
- SetIndexBuffer(0,MovingBuffer);
- //---
- SetIndexStyle(1,DRAW_LINE);
- SetIndexBuffer(1,UpperBuffer);
- //---
- SetIndexStyle(2,DRAW_LINE);
- SetIndexBuffer(2,LowerBuffer);
- //----
- SetIndexDrawBegin(0,BandsPeriod+BandsShift);
- SetIndexDrawBegin(1,BandsPeriod+BandsShift);
- SetIndexDrawBegin(2,BandsPeriod+BandsShift);
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Bollinger Bands |
- //+------------------------------------------------------------------+
- int start()
- {
- int i,k,counted_bars=IndicatorCounted();
- double deviation;
- double sum,oldval,newres;
- //----
- if(Bars<=BandsPeriod)
- return(0);
- //---- initial zero
- if(counted_bars<1)
- for(i=1; i<=BandsPeriod; i++)
- {
- MovingBuffer[Bars-i]= EMPTY_VALUE;
- UpperBuffer[Bars-i] = EMPTY_VALUE;
- LowerBuffer[Bars-i] = EMPTY_VALUE;
- }
- //----
- int limit=Bars-counted_bars;
- if(counted_bars>0)
- limit++;
- for(i=0; i<limit; i++)
- MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,
- MODE_SMA,PRICE_CLOSE,i);
- //----
- i=Bars-BandsPeriod+1;
- if(counted_bars>BandsPeriod-1)
- i=Bars-counted_bars-1;
- while(i>=0)
- {
- sum=0.0;
- k=i+BandsPeriod-2;
- oldval=MovingBuffer[i];
- while(k>=i)
- {
- newres=Close[k]-oldval;
- sum+=newres*newres;
- k--;
- }
- deviation=Multiplier*iATR(NULL,0,ATR,i); // MathSqrt(sum / BandsPeriod);
- UpperBuffer[i] = oldval + deviation;
- LowerBuffer[i] = oldval - deviation;
- i--;
- }
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
复制代码 欢迎学习交流
|
|