找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 13|回复: 0

请教如何在指标中编写,在两线之间画线段

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-20 18:18:00 | 显示全部楼层 |阅读模式
各位老师,思路如下:1.当两线之间距离由大变小时,在K棒对应的两指标线之间画线段;2.当两线之间距离由小变大时,在K棒对应的两指标线之间画线段;我的指标代码如下:#property indicator_chart_window#property indicator_buffers 5#property indicator_color1 White#property indicator_color2 Yellow#property indicator_color3 Yellow//---- input parametersextern int BBI_Ma1 = 3;extern int BBI_Ma2 = 6;extern int BBI_Ma3 = 12;extern int BBI_Ma4 = 24;extern int Boll_Ma = 50;extern int Boll_P = 2;extern int Ma_Method = 0;//=0:Simple moving average,=1:Exponential moving average,=2:Smoothed moving average,=3inear weighted moving average//---- indicator buffersdouble up[];double lower[];double BBI[];                              double BBI_std[];//standard deviation       double BBI_av[];//average                  double BBI_av2[];                        

//+------------------------------------------------------------------+//| Custom indicator initialization function                         |//+------------------------------------------------------------------+int init()  {//---- first positions skipped when drawing   SetIndexDrawBegin(0,BBI_Ma4+Boll_Ma*2);   SetIndexDrawBegin(1,BBI_Ma4+Boll_Ma*2);   SetIndexDrawBegin(2,BBI_Ma4+Boll_Ma*2);//---- 3 indicator buffers mapping      SetIndexBuffer(0,BBI);   SetIndexBuffer(1,up);   SetIndexBuffer(2,lower);   SetIndexBuffer(3,BBI_std);   SetIndexBuffer(4,BBI_av);    SetIndexBuffer(5,BBI_av2);//---- drawing settings   SetIndexStyle(0,DRAW_NONE);   SetIndexStyle(1,DRAW_LINE);   SetIndexStyle(2,DRAW_LINE);   SetIndexStyle(3,DRAW_NONE);   SetIndexStyle(4,DRAW_NONE);   SetIndexStyle(5,DRAW_NONE);//---- index labels   SetIndexLabel(0,"BBI_av");   SetIndexLabel(1,"BBI UPR");   SetIndexLabel(2,"BBI DWR");   IndicatorShortName("BBIboll band");   SetIndexEmptyValue(0,0);   SetIndexEmptyValue(1,0);   SetIndexEmptyValue(2,0);   SetIndexEmptyValue(3,0);   SetIndexEmptyValue(4,0);   SetIndexEmptyValue(5,0);

//---- initialization done   return(0);     }

int start()  {   int limit;   int counted_bars=IndicatorCounted();      double ma1,ma2,ma3,ma4,std;

   if(Bars<BBI_Ma4+Boll_Ma*2)return(-1);//---- check for possible errors   if(counted_bars<0) return(-1);//---- last counted bar will be recounted   if(counted_bars>0) counted_bars--;   limit=Bars-counted_bars;//+BBI_Ma4+Boll_Ma;//---- main loop   while(limit>-1)     {       ma1 = iMA(NULL,0,BBI_Ma1,0,Ma_Method,PRICE_CLOSE,limit);       ma2 = iMA(NULL,0,BBI_Ma2,0,Ma_Method,PRICE_CLOSE,limit);       ma3 = iMA(NULL,0,BBI_Ma3,0,Ma_Method,PRICE_CLOSE,limit);       ma4 = iMA(NULL,0,BBI_Ma4,0,Ma_Method,PRICE_CLOSE,limit);       BBI[limit] = 0.25 * (ma1 + ma2 + ma3 + ma4);   

       BBI_av[limit] = iMAOnArray(BBI,0,Boll_Ma,0,Ma_Method,limit);  

       limit --;     }                                                   

   limit=Bars-counted_bars;   while(limit>-1)     {

       BBI_av2[limit] = iMAOnArray(BBI_av,0,Boll_Ma,0,Ma_Method,limit);          std = 0;             std = iStdDevOnArray(BBI_av,0,Boll_Ma,Ma_Method,0,limit);      up[limit] = BBI_av[limit] + Boll_P * std;            //指标线上轨      lower[limit] = BBI_av[limit] - Boll_P * std;       //指标线下轨                            limit --;     }    Comment("BBI_av: ",BBI_av[0],"  ",up[0],"  ",lower[0]);  

//---- done   return(0);  }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-10 19:18 , Processed in 0.103973 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表