wilder 发表于 2018-11-7 21:53:30

多级别均线


#property indicator_chart_window    //指标放在主图; indicator_separate_window 附图
#property indicator_buffers 2      //设置指标线数组1条

#property indicator_color1BlueViolet      //第一条指标线为白色;
#property indicator_color2Magenta

#property indicator_style1 STYLE_SOLID //线为实体的
#property indicator_width1 2         //宽度为1
#property indicator_width2 1         //宽度为1


extern int MA1=160;                  //设立二个整数型变量,默认值为12和26,允许外部修改值
extern int MA2=20;

double   buf1[];                     //创建一个数组
double   buf2[];

int init()                            //初始化函数,该函数进在指标加载时只运行一次。init是系统默认的函数名
{
   SetIndexBuffer(0,buf1);             //设置数组buf1为第一条指标线
   SetIndexStyle(0,DRAW_LINE);      // 设置第一条指标线线型为连续型曲线
   SetIndexBuffer(1,buf2);             //设置数组buf1为第一条指标线
   SetIndexStyle(1,DRAW_LINE);      // 设置第一条指标线线型为连续型曲线
   IndicatorDigits(Digits);          //设置指标精确到小数位数
   return(0);
}

//指标触发函数。与init函数相区别,该函数在有行情数据变化时被触发,
//如果数据被不断更新,则该函数则将被不断执行。

int start()      
{
   int limit=Bars-IndicatorCounted();   //自定义了一个变量limit,并对其赋值;ars是图表中的柱数(K线数)
                                       //IndicatorCounted()函数调用的是缓存中的柱数,就是已经计算过的有值的柱数。
   if(Period()==PERIOD_M1)               //判断当前为什么周期图 PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1
   {MA1=100;   }
   if(Period()==PERIOD_M5)               
   {MA1=120;   }
   if(Period()==PERIOD_M15 || Period()==PERIOD_H1)               
   {MA1=80;   }
    if(Period()==PERIOD_M30)               
   {MA1=160;   }
    if(Period()==PERIOD_H4 || Period()==PERIOD_D1 )               
   {MA1=110;   }

   for(int i=0; i<limit;i++)
    {
//给数组buf赋值,其值分别为相应位置上两条均线计算出的差
//i是水平位置索引值,即烛柱从右到左的序号,右边第一个烛柱序号为0

    buf1= iMA(NULL,0,MA1,0,1,0,i);
    buf2= iMA(NULL,0,MA2,0,1,0,i);
       }
   return(0);
}



美男子 发表于 2018-11-16 14:42:35

楼主请贴图

286332 发表于 2020-5-2 14:11:32

看帖回帖是美德!:lol

学汇生存 发表于 2020-6-25 14:31:09

帮你顶下哈!!

靖雨仇 发表于 2020-7-21 20:33:59

学习了,不错

vip123 发表于 2020-8-4 12:14:21

谢谢楼主分享

ti操盘 发表于 2020-8-8 13:15:52

谢谢楼主分享

huangj01 发表于 2020-8-9 14:54:32

谢谢楼主分享

桃太郎 发表于 2020-8-22 19:20:32

帮你顶下哈!!

张舌吴 发表于 2020-8-27 22:27:02

谢谢楼主分享
页: [1] 2
查看完整版本: 多级别均线