百变霹雳小小招财猫!
大型投行
- 金钱
- 36815 美元
- 权重
- 437 股
|
DiNapoli MACD - mtf & alerts Indicator
“DiNapoli is using smoothing factors of 0.213, 0.108, and 0.199, which when translated to periods we are used to, becomes 8.3896, 17.5185 and 9.0503. Here is one that can work with fractional periods and is set by default to calculate DiNapoliMACD”.
译文如下:
老帝用了三个参数来对MACD进行平滑,这三个参数分别是0.213, 0.108, and 0.199。如果把这三个参数换算成我们平时用的参数,就是8.3896, 17.5185 and 9.0503。这个指标做成了老帝的效果,它最大的特色就是将默认参数调整成了非整数,这样就能够与老帝接轨了。
这是一个多周期指标,同时可以对信号报警。
关于指标的用法,可以问度娘,也可以参阅以下链接
http://my.fx3q.com/thread-832-1-2.html
强烈建议使用这个指标之前,先去搞明白帝纳波利点位交易法的具体内容。否则对您来说,这就是一个有点别扭的MACD而已。
MQ4源代码
DiNapoli MACD - mtf & alerts.mq4
(11.4 KB, 下载次数: 41, 售价: 5 金钱)
编译好的EX4
DiNapoli MACD - mtf & alerts.ex4
(14.21 KB, 下载次数: 54, 售价: 5 金钱)
代码:
- //+------------------------------------------------------------------+
- //| DiNapoli MACD |
- //+------------------------------------------------------------------+
- #property indicator_separate_window
- #property indicator_buffers 6
- #property indicator_color1 MediumVioletRed
- #property indicator_color2 MediumVioletRed
- #property indicator_color3 DeepSkyBlue
- #property indicator_color4 DeepSkyBlue
- #property indicator_color5 DimGray
- #property indicator_color6 Gold
- #property indicator_width2 2
- #property indicator_width4 2
- #property indicator_width5 1
- #property indicator_width6 2
- //
- //
- //
- //
- //
- extern string TimeFrame = "Current time frame";
- extern double FastPeriod = 8.3896;
- extern double SlowPeriod = 17.5185;
- extern double SignalPeriod = 9.0503;
- extern int Price = PRICE_CLOSE;
- extern bool Interpolate = true;
- extern bool alertsOn = False;
- extern bool alertsOnZeroCross = true;
- extern bool alertsOnCurrent = true;
- extern bool alertsMessage = true;
- extern bool alertsSound = false;
- extern bool alertsEmail = false;
- //
- //
- //
- //
- //
- double buffer1[];
- double buffer2[];
- double buffer3[];
- double buffer4[];
- double buffer5[];
- double buffer6[];
- double trend[];
- double trenda[];
- //
- //
- //
- //
- //
- string indicatorFileName;
- bool returnBars;
- bool calculateValue;
- int timeFrame;
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- //
- //
- //
- //
- //
- int init()
- {
- IndicatorDigits(6);
- IndicatorBuffers(8);
- SetIndexBuffer(0,buffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
- SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
- SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
- SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
- SetIndexBuffer(4,buffer5);
- SetIndexBuffer(5,buffer6);
- SetIndexBuffer(6,trend);
- SetIndexBuffer(7,trenda);
- FastPeriod = MathMax(FastPeriod,1);
- SlowPeriod = MathMax(SlowPeriod,1);
- SignalPeriod = MathMax(SignalPeriod,1);
-
- //
- //
- //
- //
- //
-
- indicatorFileName = WindowExpertName();
- calculateValue = TimeFrame=="calculateValue"; if (calculateValue) { return(0); }
- returnBars = TimeFrame=="returnBars"; if (returnBars) { return(0); }
- timeFrame = stringToTimeFrame(TimeFrame);
-
- //
- //
- //
- //
- //
-
- IndicatorShortName(timeFrameToString(timeFrame)+" DiNapoli MACD ("+DoubleToStr(FastPeriod,4)+","+DoubleToStr(SlowPeriod,4)+","+DoubleToStr(SignalPeriod,4)+","+")");
- }
- //
- //
- //
- //
- //
- int deinit()
- {
- return(0);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- //
- //
- //
- //
- //
- double work[][3];
- #define _ema1 0
- #define _ema2 1
- int start()
- {
- int counted_bars=IndicatorCounted();
- int i,r,limit;
- if(counted_bars<0) return(-1);
- if(counted_bars>0) counted_bars--;
- limit=MathMin(Bars-counted_bars,Bars-1);
- if (returnBars) { buffer1[0] = MathMin(limit+1,Bars-1); return(0); }
- //
- //
- //
- //
- //
- if (calculateValue || timeFrame == Period())
- {
- if (ArrayRange(work,0)!= Bars) ArrayResize(work,Bars);
- double alpha1 = 2.0/(1.0+FastPeriod);
- double alpha2 = 2.0/(1.0+SlowPeriod);
- double alpha3 = 2.0/(1.0+SignalPeriod);
- for(i=limit,r=Bars-i-1; i>=0; i--,r++)
- {
- double price = iMA(NULL,0,1,0,MODE_SMA,Price,i);
- if (r==0)
- {
- work[r][_ema1] = price;
- work[r][_ema2] = price;
- buffer6[i] = 0;
- continue;
- }
-
- //
- //
- //
- //
- //
-
- work[r][_ema1] = work[r-1][_ema1]+alpha1*(price-work[r-1][_ema1]);
- work[r][_ema2] = work[r-1][_ema2]+alpha2*(price-work[r-1][_ema2]);
-
- buffer5[i] = work[r][_ema1]-work[r][_ema2];
- buffer6[i] = buffer6[i+1]+alpha3*(buffer5[i]-buffer6[i+1]);
- buffer1[i] = EMPTY_VALUE;
- buffer2[i] = EMPTY_VALUE;
- buffer3[i] = EMPTY_VALUE;
- buffer4[i] = EMPTY_VALUE;
- trend[i] = trend[i+1];
- trenda[i] = trenda[i+1];
-
- //
- //
- //
- //
- //
-
- if (buffer5[i]>0) trend[i] = 1;
- if (buffer5[i]<0) trend[i] = -1;
- if (trend[i] == 1)
- {
- if (buffer5[i] > buffer5[i+1]) { buffer4[i] = buffer5[i]; }
- if (buffer5[i] < buffer5[i+1]) { buffer3[i] = buffer5[i]; }
- if (buffer5[i] == buffer5[i+1])
- {
- if (buffer3[i+1] != EMPTY_VALUE) buffer3[i] = buffer5[i];
- if (buffer4[i+1] != EMPTY_VALUE) buffer4[i] = buffer5[i];
- }
- }
- if (trend[i] == -1)
- {
- if (buffer5[i] > buffer5[i+1]) { buffer1[i] = buffer5[i]; }
- if (buffer5[i] < buffer5[i+1]) { buffer2[i] = buffer5[i]; }
- if (buffer5[i] == buffer5[i+1])
- {
- if (buffer1[i+1] != EMPTY_VALUE) buffer1[i] = buffer5[i];
- if (buffer2[i+1] != EMPTY_VALUE) buffer2[i] = buffer5[i];
- }
- }
-
- if (alertsOnZeroCross)
- {
- if (buffer5[i]>0) trenda[i] = 1;
- if (buffer5[i]<0) trenda[i] = -1;
- }
- else
- {
- if (buffer5[i]>buffer6[i]) trenda[i] = 1;
- if (buffer5[i]<buffer6[i]) trenda[i] = -1;
- }
- }
- manageAlerts();
- return(0);
- }
- //
- //
- //
- //
- //
- limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
- for (i=limit; i>=0; i--)
- {
- int y = iBarShift(NULL,timeFrame,Time[i]);
- buffer1[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,0,y);
- buffer2[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,1,y);
- buffer3[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,2,y);
- buffer4[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,3,y);
- buffer5[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,4,y);
- buffer6[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,5,y);
- trend[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",FastPeriod,SlowPeriod,SignalPeriod,Price,6,y);
- trenda[i] = trenda[i+1];
- //
- //
- //
- //
- //
-
- if (alertsOnZeroCross)
- {
- if (buffer5[i]>0) trenda[i] = 1;
- if (buffer5[i]<0) trenda[i] = -1;
- }
- else
- {
- if (buffer5[i]>buffer6[i]) trenda[i] = 1;
- if (buffer5[i]<buffer6[i]) trenda[i] = -1;
- }
- //
- //
- //
- //
- //
-
- if (!Interpolate || y==iBarShift(NULL,timeFrame,Time[i-1])) continue;
- //
- //
- //
- //
- //
- datetime time = iTime(NULL,timeFrame,y);
- for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;
- for(int k = 1; k < n; k++)
- {
- buffer5[i+k] = buffer5[i] + (buffer5[i+n] - buffer5[i])*k/n;
- buffer6[i+k] = buffer6[i] + (buffer6[i+n] - buffer6[i])*k/n;
- if (buffer1[i+k] != EMPTY_VALUE) buffer1[i+k] = buffer5[i+k];
- if (buffer2[i+k] != EMPTY_VALUE) buffer2[i+k] = buffer5[i+k];
- if (buffer3[i+k] != EMPTY_VALUE) buffer3[i+k] = buffer5[i+k];
- if (buffer4[i+k] != EMPTY_VALUE) buffer4[i+k] = buffer5[i+k];
- }
- }
- manageAlerts();
-
- //
- //
- //
- //
- //
- return(0);
- }
- //+-------------------------------------------------------------------
- //|
- //+-------------------------------------------------------------------
- //
- //
- //
- //
- //
- void manageAlerts()
- {
- if (!calculateValue && alertsOn)
- {
- if (alertsOnCurrent)
- int whichBar = 0;
- else whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));
- if (trenda[whichBar] != trenda[whichBar+1])
- {
- if (trenda[whichBar] == 1) doAlert(whichBar,"up");
- if (trenda[whichBar] == -1) doAlert(whichBar,"down");
- }
- }
- }
- //
- //
- //
- //
- //
- void doAlert(int forBar, string doWhat)
- {
- static string previousAlert="nothing";
- static datetime previousTime;
- string message;
-
- if (previousAlert != doWhat || previousTime != Time[forBar]) {
- previousAlert = doWhat;
- previousTime = Time[forBar];
- //
- //
- //
- //
- //
- message = StringConcatenate(Symbol()," ",timeFrameToString(timeFrame)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," DiNapoli MACD trend changed to ",doWhat);
- if (alertsMessage) Alert(message);
- if (alertsEmail) SendMail(StringConcatenate(Symbol()," DiNapoli MACD "),message);
- if (alertsSound) PlaySound("alert2.wav");
- }
- }
- //+-------------------------------------------------------------------
- //|
- //+-------------------------------------------------------------------
- //
- //
- //
- //
- //
- string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
- int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
- //
- //
- //
- //
- //
- int stringToTimeFrame(string tfs)
- {
- tfs = stringUpperCase(tfs);
- for (int i=ArraySize(iTfTable)-1; i>=0; i--)
- if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
- return(Period());
- }
- string timeFrameToString(int tf)
- {
- for (int i=ArraySize(iTfTable)-1; i>=0; i--)
- if (tf==iTfTable[i]) return(sTfTable[i]);
- return("");
- }
- //
- //
- //
- //
- //
- string stringUpperCase(string str)
- {
- string s = str;
- for (int length=StringLen(str)-1; length>=0; length--)
- {
- int char = StringGetChar(s, length);
- if((char > 96 && char < 123) || (char > 223 && char < 256))
- s = StringSetChar(s, length, char - 32);
- else if(char > -33 && char < 0)
- s = StringSetChar(s, length, char + 224);
- }
- return(s);
- }
复制代码 |
|