请教如何在指标中编写,在两线之间画线段 新评论 cyli2018 2021.04.12 14:29 各位老师,思路如下: 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 parameters extern 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,=3:Linear weighted moving average //---- indicator buffers double 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); } 附加的文件: tlxp_20210412123813.png 179 kb 求好人帮忙把这几行通达信代码改成MQl语言,很感谢 [警告关闭!]任何新手问题,为了不给论坛添乱。专业人士,不要走过。没有你,哪里都不能去。 跪求代码解读注解 本人刚接触mql4,实在不懂,求大神或好心人帮忙解读代码 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
各位老师,思路如下:
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 parameters
extern 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,=3:Linear weighted moving average
//---- indicator buffers
double 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);
}