指标效果图:
指标公式源码及源码注释:
N:=14; {设置周期为14天}
TYP:=(HIGH+LOW+CLOSE)/3; {计算中间价格}
CCI:(TYP-MA(TYP,14))/(0.015AVEDEV(TYP,14)),LINETHICK0; {计算CCI指标,线宽设置为0}
DRAWTEXT(CROSS(200,CCI),250,'下穿200'),COLORGREEN; {当CCI下穿200时,在250位置绘制绿色文本}
DRAWTEXT( CROSS(CCI,-200),-150,'上穿-200'),COLORYELLOW; {当CCI上穿-200时,在-150位置绘制黄色文本}
DRAWTEXT( CROSS(CCI,-100),-100,'上穿-100'),COLORFF00FF; {当CCI上穿-100时,在-100位置绘制紫色文本}
STICKLINE(CCI>0,0,CCI,1,0),COLORRED; {当CCI大于0时,绘制红色柱状线}
STICKLINE(CCI<0,0,CCI,1,0),COLORLIGREEN; {当CCI小于0时,绘制绿色柱状线}
STICKLINE(CROSS(CCI,-200) AND CCI>REF(CCI,1),CCI,0,1,0),COLORYELLOW; {当CCI上穿-200且大于前一日CCI时,绘制黄色柱状线}
STICKLINE(CROSS(200,CCI) AND CCI<REF(CCI,1),0,CCI,1,0),COLORGREEN; {当CCI下穿200且小于前一日CCI时,绘制绿色柱状线}
CCI70:(TYP-MA(TYP,70))/(0.015AVEDEV(TYP,70)),COLORYELLOW,LINETHICK2; {计算70日CCI指标,颜色为黄色,线宽为2}
差值:=CCI70-REF(CCI70,1); {计算CCI70与前一日CCI70的差值}
IF(差值>0,CCI70,DRAWNULL),COLORYELLOW,LINETHICK2; {如果差值大于0,绘制黄色CCI70线}
IF(差值<0,CCI70,DRAWNULL),COLORBLUE,LINETHICK2; {如果差值小于0,绘制蓝色CCI70线}
逃顶线:200,COLORGREEN; {设置逃顶线在200,颜色为绿色}
强势线:100,COLORRED,LINETHICK2; {设置强势线在100,颜色为红色,线宽为2}
趋势线:CCI,COLORGRAY,LINESTICK,LINETHICK1; {设置趋势线为CCI,颜色为灰色,线宽为1}
中轴线:0,COLORYELLOW,LINETHICK1; {设置中轴线在0,颜色为黄色,线宽为1}
抄底线:-100,COLORWHITE; {设置抄底线在-100,颜色为白色}
弱势线:-200,COLORGREEN; {设置弱势线在-200,颜色为绿色}
DRAWICON(CROSS(CCI,-100) OR (REF(CCI,1)>-100 AND REF(CCI,1)<-95 AND CCI>REF(CCI,1)),CCI-0.03,1); {当CCI上穿-100或在-100到-95之间且CCI上升时,在CCI下方绘制向上箭头}
DRAWICON(CROSS(100,CCI) OR (REF(CCI,1)<100 AND REF(CCI,1)>95 AND CCI<REF(CCI,1)),CCI+0.03,2); {当CCI下穿100或在100到95之间且CCI下降时,在CCI上方绘制向下箭头}