论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
查看:1236回复:2
草龙
注册时间2004-12-17
[MT4指标]全平均均线
楼主发表于:2014-08-11 02:32只看该作者倒序浏览
1楼 电梯直达
电梯直达
可以研究研究看看 //+------------------------------------------------------------------+ //| AllAverages_v1.mq4 | //| Copyright ? 2007-08, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: [email protected] | //| \"Labels added by \"OTCFX\". | //+------------------------------------------------------------------+ #property copyright \"Copyright ? 2007-08, TrendLaboratory\" #property link \"http://finance.groups.yahoo.com/group/TrendLaboratory\" //---- #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Orange #property indicator_width1 2 //---- indicator parameters extern int Price=0; extern int MA_Period=5; extern int MA_Shift=0; extern int MA_Method=1; extern int Label_Size=8; extern color LabelCol=Orange; //---- indicator buffers double MA; double aPrice; //---- int draw_begin; string short_name; string xLAb1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexStyle(0,DRAW_LINE); SetIndexShift(0,MA_Shift); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); draw_begin=MA_Period; //---- indicator short name switch(MA_Method) { case 1 : short_name=\"EMA\"; break; case 2 : short_name=\"Wilder\"; break; case 3 : short_name=\"LWMA\"; break; case 4 : short_name=\"SineWMA\"; break; case 5 : short_name=\"TriMA\"; break; case 6 : short_name=\"LSMA\"; break; case 7 : short_name=\"SMMA\"; break; case 8 : short_name=\"MMA\"; break; case 9 : short_name=\"HMA\"; break; case 10: short_name=\"ZeroLagEMA\"; break; default: MA_Method=0; short_name=\"SMA\"; } IndicatorShortName(short_name+MA_Period+\")\"); SetIndexDrawBegin(0,draw_begin); SetIndexLabel(0,short_name+MA_Period+\")\"); //---- indicator buffers mapping IndicatorBuffers(2); SetIndexBuffer(0,MA); SetIndexBuffer(1,aPrice); //---- initialization done xLAb1=short_name+MA_Period+\")\"; //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int deinit() { ObjectDelete(xLAb1); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int limit, i, shift; int counted_bars=IndicatorCounted(); int JK0=0; if(counted_bars<1) for(i=1;i<=draw_begin;i++) MA[Bars-i]=iMA(NULL,0,1,0,0,Price,Bars-i); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(shift=limit; shift>=0; shift--) aPrice[shift]=iMA(NULL,0,1,0,0,Price,shift); JK0=MA_Period; for(shift=limit; shift>=0; shift--) { if(shift==Bars - MA_Period) { switch(MA_Method) { case 1 : MA[shift]=SMA(aPrice,MA_Period,shift); break; case 2 : MA[shift]=SMA(aPrice,MA_Period,shift); break; case 7 : MA[shift]=SMA(aPrice,MA_Period,shift); break; case 10: MA[shift]=SMA(aPrice,1,shift); break; } } else if(shift < Bars - MA_Period) { switch(MA_Method) { case 1 : MA[shift]=EMA(aPrice,MA,MA_Period,shift); break; case 2 : MA[shift]=Wilder(aPrice,MA,MA_Period,shift); break; case 3 : MA[shift]=LWMA(aPrice,MA_Period,shift); break; case 4 : MA[shift]=SineWMA(aPrice,MA_Period,shift); break; case 5 : MA[shift]=TriMA(aPrice,MA_Period,shift); break; case 6 : MA[shift]=LSMA(aPrice,MA_Period,shift); break; case 7 : MA[shift]=SMMA(aPrice,MA,MA_Period,shift); break; case 8 : MA[shift]=MMA(aPrice,MA_Period,shift); break; case 9 : MA[shift]=HMA(aPrice,MA_Period,shift); break; case 10: MA[shift]=ZeroLagEMA(aPrice,MA,MA_Period,shift); break; default: MA[shift]=SMA(aPrice,MA_Period,shift); break; } } } //---- done if (ObjectFind(xLAb1)!=0) ObjectCreate(xLAb1,OBJ_TEXT,0,0,0); ObjectMove(xLAb1,0,Time[0], MA[0]+0.00007); ObjectSetText(xLAb1,\" <-<\"+JK0+\",\"+short_name+\",\"+DoubleToStr( MA[0],Digits), Label_Size, \"Verdana\", LabelCol); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double SMA(double array,int per,int bar) { double Sum=0; for(int i=0;i < per;i++) Sum+=array[i+bar]; //---- return(Sum/per); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double EMA(double array1,double array2,int per,int bar) { return(array2[bar+1] + 2.0/(1+per)*(array1[bar] - array2[bar+1])); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double Wilder(double array1,double array2,int per,int bar) { return(array2[bar+1] + 1.0/per*(array1[bar] - array2[bar+1])); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double LWMA(double array,int per,int bar) { double Sum=0; double Weight=0; //---- for(int i=0;i < per;i++) { Weight+= (per - i); Sum+=array[bar+i]*(per - i); } if(Weight>0) double lwma=Sum/Weight; else lwma=0; return(lwma); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double SineWMA(double array,int per,int bar) { double pi=3.1415926535; double Sum=0; double Weight=0; double del=0.5*pi/per; //---- for(int i=0;i < per;i++) { Weight+= MathSin(0.5*pi - del*i); Sum+=array[bar+i]*MathSin(0.5*pi - del*i); } if(Weight>0) double swma=Sum/Weight; else swma=0; return(swma); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double TriMA(double array,int per,int bar) { double sma; int len=MathCeil((per+1)*0.5); ArrayResize(sma,len); for(int i=0;i < len;i++) sma=SMA(array,len,bar+i); double trima=SMA(sma,len,0); //---- return(trima); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double LSMA(double array,int per,int bar) { double Sum=0; for(int i=per; i>=1; i--) Sum+=(i-(per+1)/3.0)*array[per-i+bar]; double lsma=Sum*6/(per*(per+1)); //---- return(lsma); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double SMMA(double array1,double array2,int per,int bar) { double Sum=0; for(int i=0;i < per;i++) Sum+=array1[i+bar+1]; double smma=(Sum - array2[bar+1] + array1[bar])/per; //---- return(smma); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double MMA(double array,int per,int bar) { double Slope=0; for(int i=1;i<=per;i++) { double Factor=1 + (2 * (i - 1)); Slope+=(array[bar + i - 1] * ((per - Factor)/2)); } double sma=SMA(array,per,bar); double mma=sma + (6 * Slope)/((per + 1) * per); //---- return(mma); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double HMA(double array,int per,int bar) { double tmp; int len= MathSqrt(per); ArrayResize(tmp,len); for(int i=0; i < len;i++) tmp=2*LWMA(array,per/2,bar+i) - LWMA(array,per,bar+i); double hma=LWMA(tmp,len,0); //---- return(hma); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double ZeroLagEMA(double array1,double array2,int per,int bar) { double alfa=2.0/(1+per); int lag=0.5*(per - 1); return(alfa*(2*array1[bar] - array1[bar+lag]) + (1-alfa)*array2[bar+1]); } //+------------------------------------------------------------------+
TK29帖子1楼右侧xm竖版广告90-240
个性签名

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

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告
liangziABC
注册时间2018-05-18
zhapeng
注册时间2020-12-12

本站免责声明:

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

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

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

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

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

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