- //[i] BBwithFractdev
- #property indicator_chart_window
- #property indicator_buffers 3
- #property indicator_color1 Red
- #property indicator_color2 Yellow
- #property indicator_color3 Blue
- extern int 周期 = 13;
- extern double 偏差 = 2.618;
- double 红上轨[];
- double 黄中轨[];
- double 蓝下轨[];
- //--------------初始化---------------+
- void init()
- {
- SetIndexStyle(0, DRAW_LINE);
- SetIndexStyle(1, DRAW_LINE);
- SetIndexStyle(2, DRAW_LINE);
- IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
- SetIndexBuffer(0, 红上轨);
- SetIndexBuffer(1, 黄中轨);
- SetIndexBuffer(2, 蓝下轨);
- }
- //---------------主函数----------------+
- void start()
- {
- double 区间均值, sko, sum;
- if(Bars<=周期)
- return;
- for(int i=Bars-周期; i>=0; i--) {
- 黄中轨[i]= iMA(NULL,0,周期,0,MODE_SMA,PRICE_CLOSE,i);
- sum= 0;
- for(int j=0; j<周期; j++)
- sum += Close[i+j];
- 区间均值= sum/周期;
- sum= 0;
- for(j=0; j<周期; j++)
- sum += (Close[i+j]-区间均值)*(Close[i+j]-区间均值);
- sko= MathSqrt(sum/周期);
- Print("偏差= ",偏差," sko= ",sko);
- 红上轨[i]= 黄中轨[i]+(偏差*sko);
- 蓝下轨[i]= 黄中轨[i]-(偏差*sko);
- }
- }
- //+------------------------------------------------------------------+
复制代码 |