论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
查看:1240回复:5
草龙
注册时间2004-12-17
[MT4指标]在主图均线上添加cci指标
楼主发表于:2014-09-29 05:52只看该作者倒序浏览
1楼 电梯直达
电梯直达
这个指标的实现方法很新颖 以主图为0轴来画cci指标 主图指 mt4指标类型:震荡指标 是否能用在mt4手机版上:否 是否含有未来函数:无 //+------------------------------------------------------------------+ //| CCI.mq4 | //| Copyright ? 2004, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright \"Copyright ? 2004, MetaQuotes Software Corp.\" #property link \"http://www.metaquotes.net/\" //---- #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 Aqua //---- input parameters //---- indicator parameters extern string m = \"--Moving Average Types--\"; extern string m0 = \" 0 = SMA\"; extern string m1 = \" 1 = EMA\"; extern string m2 = \" 2 = SMMA\"; extern string m3 = \" 3 = LWMA\"; extern string m4 = \" 4 = LSMA\"; extern int MA_Type=0; extern string p = \"--Applied Price Types--\"; extern string p0 = \" 0 = close\"; extern string p1 = \" 1 = open\"; extern string p2 = \" 2 = high\"; extern string p3 = \" 3 = low\"; extern string p4 = \" 4 = median(high+low)/2\"; extern string p5 = \" 5 = typical(high+low+close)/3\"; extern string p6 = \" 6 = weighted(high+low+close+close)/4\"; extern int MA_AppliedPrice = 0; extern string c = \"--CCI Inputs--\"; extern int CCIPeriod = 14; extern int SmoothingMA_Type = 2; extern int SmoothingMA_Period = 3; //---- buffers double CCIBuffer; double CCIBufferSmoothed; double RelBuffer; double DevBuffer; double MovBuffer; int MA_Mode; string strMAType; int SmoothingMode; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- 3 additional buffers are used for counting. IndicatorBuffers(5); SetIndexBuffer(1, RelBuffer); SetIndexBuffer(2, DevBuffer); SetIndexBuffer(3, MovBuffer); //---- indicator lines SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, CCIBuffer); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1, CCIBufferSmoothed); //---- if(CCIPeriod <= 0) CCIPeriod = 14; SmoothingMode = SmoothingMA_Type; if (SmoothingMA_Type > 3) SmoothingMode = 2; //---- SetIndexDrawBegin(0, CCIPeriod); //---- name for DataWindow and indicator subwindow label switch (MA_Type) { case 1: strMAType=\"EMA\"; MA_Mode=MODE_EMA; break; case 2: strMAType=\"SMMA\"; MA_Mode=MODE_SMMA; break; case 3: strMAType=\"LWMA\"; MA_Mode=MODE_LWMA; break; case 4: strMAType=\"LSMA\"; break; default: strMAType=\"SMA\"; MA_Mode=MODE_SMA; break; } short_name = \"CCI-\" +strMAType+ \" (\" +CCIPeriod + \") \"; IndicatorShortName(short_name); SetIndexLabel(0, short_name); //---- return(0); } //+------------------------------------------------------------------------+ //| LSMA - Least Squares Moving Average function calculation | //| LSMA_In_Color Indicator plots the end of the linear regression line | //+------------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| LSMA with PriceMode | //| PrMode 0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, | //| 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4 | //+------------------------------------------------------------------+ double LSMA(int TimeFrame, int Rperiod, int prMode, int shift) { int i, myShift; double sum, pr; int length; double lengthvar; double tmp; double wt; length = Rperiod; sum = 0; for(i = length; i >= 1 ; i--) { lengthvar = length + 1; lengthvar /= 3; tmp = 0; myShift = length - i + shift; switch (prMode) { case 0: pr = iClose(NULL,TimeFrame,myShift);break; case 1: pr = iOpen(NULL,TimeFrame,myShift);break; case 2: pr = iHigh(NULL,TimeFrame,myShift);break; case 3: pr = iLow(NULL,TimeFrame,myShift);break; case 4: pr = (iHigh(NULL,TimeFrame,myShift) + iLow(NULL,TimeFrame,myShift))/2;break; case 5: pr = (iHigh(NULL,TimeFrame,myShift) + iLow(NULL,TimeFrame,myShift) + iClose(NULL,TimeFrame,myShift))/3;break; case 6: pr = (iHigh(NULL,TimeFrame,myShift) + iLow(NULL,TimeFrame,myShift) + iClose(NULL,TimeFrame,myShift) + iClose(NULL,TimeFrame,myShift))/4;break; } tmp = ( i - lengthvar)*pr; sum+=tmp; } wt = sum*6/(length*(length+1)); wt = MathFloor(wt/Point)*Point; return(wt); } //+------------------------------------------------------------------+ //| Commodity Channel Index | //+------------------------------------------------------------------+ int start() { int i, k, counted_bars = IndicatorCounted(); double price, sum, mul; if(CCIPeriod <= 1) return(0); if(Bars <= CCIPeriod) return(0); //---- initial zero if(counted_bars < 1) { for(i = 1; i <= CCIPeriod; i++) CCIBuffer[Bars-i] = 0.0; for(i = 1; i <= CCIPeriod; i++) DevBuffer[Bars-i] = 0.0; for(i = 1; i <= CCIPeriod; i++) MovBuffer[Bars-i] =0.0; } //---- last counted bar will be recounted int limit = Bars - counted_bars; if(counted_bars > 0) limit++; //---- moving average for(i = 0; i < limit; i++) { if (MA_Type == 4) MovBuffer=LSMA(0, CCIPeriod, MA_AppliedPrice,i); else MovBuffer=iMA(NULL,0,CCIPeriod,0,MA_Mode,MA_AppliedPrice,i); } //---- standard deviations i = Bars - CCIPeriod + 1; if(counted_bars > CCIPeriod - 1) i = Bars - counted_bars - 1; mul = 0.015 / CCIPeriod; while(i >= 0) { sum = 0.0; k = i + CCIPeriod - 1; while(k >= i) { price =(High[k] + Low[k] + Close[k]) / 3; sum += MathAbs(price - MovBuffer); k--; } DevBuffer = sum*mul; i--; } i = Bars - CCIPeriod + 1; if(counted_bars > CCIPeriod - 1) i = Bars - counted_bars - 1; while(i >= 0) { price = (High + Low + Close) / 3; RelBuffer = price - MovBuffer; i--; } //---- cci counting i = Bars - CCIPeriod + 1; if(counted_bars > CCIPeriod - 1) i = Bars - counted_bars - 1; while(i >= 0) { if(DevBuffer == 0.0) CCIBuffer = 0.0; else CCIBuffer = RelBuffer / DevBuffer; i--; } //---- cci smoothing i = Bars - CCIPeriod + 1; if(counted_bars > CCIPeriod - 1) i = Bars - counted_bars - 1; while(i >= 0) { CCIBufferSmoothed = iMAOnArray(CCIBuffer, 0, SmoothingMA_Period, 0, SmoothingMode, i); i--; } //---- return(0); } //+------------------------------------------------------------------+
TK29帖子1楼右侧xm竖版广告90-240
个性签名

阅尽天下指标
搬砖开始,始于2014

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告
baigy
注册时间2015-07-12
liujiqi
注册时间2006-09-20
liujiqi
注册时间2006-09-20
发表于:2015-08-08 16:42只看该作者
4楼
楼主的指标生成不了ex4文件,用不了
liujiqi
注册时间2006-09-20
mikexun
注册时间2015-08-14
发表于:2015-08-15 12:07只看该作者
6楼
有未来函数么

本站免责声明:

1、本站所有广告及宣传信息均与韬客无关,如需投资请依法自行决定是否投资、斟酌资金安全及交易亏损风险;

2、韬客是独立的、仅为投资者提供交流的平台,网友发布信息不代表韬客的观点与意思表示,所有因网友发布的信息而造成的任何法律后果、风险与责任,均与韬客无关;

3、金融交易存在极高法律风险,未必适合所有投资者,请不要轻信任何高额投资收益的诱导而贸然投资;投资保证金交易导致的损失可能超过您投入的资金和预期。请您考虑自身的投资经验及风险承担能力,进行合法、理性投资;

4、所有投资者的交易帐户应仅限本人使用,不应交由第三方操作,对于任何接受第三方喊单、操盘、理财等操作的投资和交易,由此导致的任何风险、亏损及责任由投资者个人自行承担;

5、韬客不隶属于任何券商平台,亦不受任何第三方控制,韬客不邀约客户投资任何保证金交易,不接触亦不涉及投资者的任何资金及账户信息,不代理任何交易操盘行为,不向客户推荐任何券商平台,亦不存在其他任何推荐行为。投资者应自行选择券商平台,券商平台的任何行为均与韬客无关。投资者注册及使用韬客即表示其接受和认可上述声明,并自行承担法律风险。

版权所有:韬客外汇论坛 www.talkfx.com 联络我们:[email protected]