设置指标线线的偏移量。
void SetIndexShift(
int index, // 指标线索引号 0-7
int shift // 偏移量
);
对于正值,线图将向右移动,否则将向左移动。 也就是说,在当前条上计算的值将被绘制到相对于当前条的位置。
该函数与SetIndexDrawBegin的区别是,SetIndexShift将指标线向左或者向右平移;SetIndexDrawBegin设置的是开始绘制指标线的位置。
示例:
#property strict //— 指标设置 #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Blue #property indicator_color2 Red #property indicator_color3 Lime //— 输入参数 input int InpJawsPeriod=13; // Jaws Period input int InpJawsShift=8; // Jaws Shift input int InpTeethPeriod=8; // Teeth Period input int InpTeethShift=5; // Teeth Shift input int InpLipsPeriod=5; // Lips Period input int InpLipsShift=3; // Lips Shift //— 指标数组 double ExtBlueBuffer[]; double ExtRedBuffer[]; double ExtLimeBuffer[]; //+——————————————————————+ //| 指标初始化 | //+——————————————————————+ void OnInit(void) { IndicatorDigits(Digits); //— 设置平移的柱数,也可理解为K线数量 SetIndexShift(0,InpJawsShift); SetIndexShift(1,InpTeethShift); SetIndexShift(2,InpLipsShift); //— 跳过第一个位置 SetIndexDrawBegin(0,InpJawsShift+InpJawsPeriod); SetIndexDrawBegin(1,InpTeethShift+InpTeethPeriod); SetIndexDrawBegin(2,InpLipsShift+InpLipsPeriod); //— 3 个指标线 SetIndexBuffer(0,ExtBlueBuffer); SetIndexBuffer(1,ExtRedBuffer); SetIndexBuffer(2,ExtLimeBuffer); //— 指标类型是线条 SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_LINE); //— 指标线标签名 SetIndexLabel(0,”Gator Jaws”); SetIndexLabel(1,”Gator Teeth”); SetIndexLabel(2,”Gator Lips”); } //+——————————————————————+ //| 每个价格更新时执行 | //+——————————————————————+ 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=rates_total-prev_calculated; //— 主循环 for(int i=0; i<limit; i++) { //— 均线偏移量设置为0,因为先调用 SetIndexShift ExtBlueBuffer[i]=iMA(NULL,0,InpJawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i); ExtRedBuffer[i]=iMA(NULL,0,InpTeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i); ExtLimeBuffer[i]=iMA(NULL,0,InpLipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i); } //— return(rates_total); } |