老码农分享 http://blog.sciencenet.cn/u/seawan //敲键读书打酱油;

博文

图线叠加(mql)

已有 3044 次阅读 2014-11-1 17:40 |个人分类:mt4|系统分类:生活其它

#property  indicator_separate_window

#property  indicator_buffers 1

#property  indicator_color1  Aqua

#property  indicator_level1  30

#property  indicator_level2  70

extern int RSI=12;

extern string 商品="GBPUSD";

double     ind_buffer[];

int init()

{

 SetIndexBuffer(0,ind_buffer);

 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);

 IndicatorShortName("RSI("+商品+"," +RSI+")");

 return(0);

}

int start()

{

 int limit;

 int counted_bars=IndicatorCounted();

 if(counted_bars<0) return(-1);

 if(counted_bars>0) counted_bars--;

 limit=Bars-counted_bars;

 for(int i=0; i<limit; i++)

   ind_buffer[i]=iRSI(商品,0,RSI,PRICE_CLOSE,i);

 return(0);

}


======ex=========




#property  indicator_separate_window
指标放在副图                


             

#property  indicator_buffers 1
设置指标线数组为1                


             

#property  indicator_color1  Aqua
设置第一条指标线颜色值为Aqua,即介于蓝绿之间的一种颜色                


             

#property  indicator_level1  30
在副图中,30值位置上画一条水平直线                


             

#property  indicator_level2  70
在副图中,70值位置上画一条水平直线                


             

extern int RSI=12;
设立一个自定义变量,允许外部值修改,整数型,变量名为"RSI",默认值12                


             

extern string 商品="GBPUSD";
设立一个自定义变量,允许外部值修改,字符串型,变量名为"商品",默认值"GBPUSD"
               


             

double     ind_buffer[];
设立一个自定义数组,双精度型                


             

int init()
设立初始化函数initinit为系统规定函数名,函数内容自定义。该函数在指标被加载时运行一次
 {
  SetIndexBuffer(0,ind_buffer);
 
设置第一条指标线的数组为ind_buffer
               


             

  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
 
设置第一条指标线的样式,DRAW_LINE表示连续曲线,STYLE_SOLID表示实心线,1号粗线                


             

  IndicatorShortName("RSI("+商品+"," +RSI+")");
 
设置指标线的显示简称
               


             

  return(0);
 
初始化函数结束
 }
int start()
设立触发函数startstart为系统规定函数名,函数内容自定义。当数据变动时,start函数被触发
 {
  int limit;
 
设立自定义变量limit,整数型
               


             

  int counted_bars=IndicatorCounted();
 
设立整数型自定义变量counted_bars,并将IndicatorCounted()的值赋给counted_bars
  IndicatorCounted()
为缓存数量,即已经计算过值的烛柱数
 
(注:可能这里解释得不是很准确,大致就这个意思)
               


             

  if(counted_bars<0) return(-1);
 
如果counted_bars值小于零,start函数结束                


             

  if(counted_bars>0) counted_bars--;
 
如果counted_bars值大于零,则counted_bars值减掉1。这是为了配合下一句,以避免limit相差1而出错                


             

  limit=Bars-counted_bars;
 
limit赋值
  Bars
为图表中的柱数
  counted_bars
为已经赋值的柱数
 
这样limit的值就是未赋值的烛柱数
 
这样做的目的是避免重复运算,优化程序
               


             

  for(int i=0; i<limit; i++)
 
循环语句,括号中有三个语句:
 
第一句int i=0; 表示循环从i=0开始
 
第二句i<limit; 这是循环的条件,如果条件满足则执行大括号中的循环体,如果条件不满足,则中止循环,跳到大括号下面的语句执行
 
第三句i++,这是循环步调控制语句,每循环一次后执行一次此语句。
  i++
相当于i=i+1,即i值在原有数值上增加1
               


             

     ind_buffer[i]=iRSI(商品,0,RSI,PRICE_CLOSE,i);
     
此语句为循环体,由于只有一个语句,所以省略花括号
     i
为图表烛柱的序号,从0开始,右边第1柱序号为0,从右向左递增
     iRSI
RSI指标的取值函数
               


             

  return(0);
  start
函数结束
 }
               




https://blog.sciencenet.cn/blog-461456-840350.html

上一篇:【教学笔记】QTP数据驱动测试的一段脚本
下一篇:新片:《超体》
收藏 IP: 60.12.210.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-28 00:54

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部