0
点赞
收藏
分享

微信扫一扫

量化交易之MQL4篇 - 指标与数组的关系、指标系统函数、指标属性

左小米z 2023-03-02 阅读 92





// 指标放在主图

#property indicator_chart_window


// 设置指标线数为 1 条, 颜色为黄色

#property indicator_buffers 1

#property indicator_color1 Yellow

double mk[];


extern int 均线 = 10;


double temp0;

double temp1;


int init() {



// 指标线数量为 1 条

IndicatorBuffers(1);



// 第 1 条指标线的数组为 mk[]

SetIndexBuffer(0, mk);



// 第 1 条指标线的线型为箭头符号

SetIndexStyle(0, DRAW_LINE);



// 第 1 条指标线的箭头符号为第 204 种符号, 如果换一个编号, 那出现的就是另一种符号。箭头符号的编码详见《MT4编程参考》

SetIndexArrow(0, 202);



// 设置指标线的小数位数, Digits = 当前汇率的小数位数

IndicatorDigits(Digits);



return 0;

}


int start() {



int limit = 0;

int counted_bars = IndicatorCounted();



// IndicatorCounted(): 当前盘面上不包括当前k线的k线个数。 Bars: 当前盘面上包括当前k线的k线个数。

// Print("counted_bars: " + counted_bars + " Bars: " + Bars);



limit = Bars - counted_bars - 均线;



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



temp0 = iMA(Symbol(), PERIOD_CURRENT, 均线, 0, 0, 0, i);

temp1 = iMA(Symbol(), PERIOD_CURRENT, 均线, 0, 0, 0, i+1);



// 给数组mk在i位置上赋空值, EMPTY_VALUE 就是空值

mk[i] = EMPTY_VALUE;



if(Close[i] > temp0 && Close[i+1] < temp1) mk[i] = temp0;

if(Close[i] < temp0 && Close[i+1] < temp1) mk[i] = temp0;



}



return 0;
}


举报

相关推荐

0 条评论