MT4三 自定义指标注意事项

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{

int limit;
int shift;
if(rates_total<Rperiod){
return rates_total;
}

}

一、跳过K线数小于period的计算

period为计算某一值需要的最小的K线数
如MA5(五日平均)最少需要已有5根K线
if(rates_total<Rperiod){
      return rates_total;
   }

二、避免计算过的指标值重复计算

利用rates_total总K线数与prev_calculated 先前计算过的K线数
的差值定义为limit,由limit限制每次价格跳动时
指标数组的赋值操作,可以避免计算过的指标值被
重复计算
limit=rates_total-prev_calculated;
for(shift=limit-1;shift>=0;shift–)
{
//指标数组赋值操作

}

三、柱状图的绘制

柱状图的绘制需要两个柱状图或一柱状图和一条线,柱状图会绘制两个数组的差值部分

四、指标的属性指定

1、属性设定
//— plot Label1
#property indicator_label1 “Label1”
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
2、代码设定
SetIndexStyle(index,type,style,width,ncolor);

五、主图指标与附图指标的区别

1、指定为主图指标
#property indicator_chart_window
2、指定为附图指标
#property indicator_separate_window

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值