//+------------------------------------------------------------------+
//| southgis.com_MACD.mq4 |
//| Copyright ?2014, www.southgis.com |
//| http://www.southgis.com |
//+------------------------------------------------------------------+
#property copyright "www.southgis.com"
#property link "http://www.southgis.com"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Red
#property indicator_color4 Lime
//---- input parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int ExtWPRPeriod=14;
extern double WRMin=-65;
extern double WRMax=-35;
extern double MACDMax=0.00007;
extern double MACDMin=-0.00007;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int index=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,ExtMapBuffer4);
//----
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"DIFF");
SetIndexLabel(1,"DEA");
SetIndexLabel(2,"MACD");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
for(int i=0;i<index; i++)
{
ObjectDelete("vline"+i);
//ObjectDelete("arrow"+i);
ObjectDelete("text"+i);
}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int limit;
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- DIF counted in the 1-st buffer
for(int i=0; i<limit; i++)
ExtMapBuffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- MACD line counted in the 2-nd buffer
for(i=0; i<limit; i++)
ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1,Bars,SignalSMA,0,MODE_EMA,i);
//---- BAR line counted in the 3,4 buffer
for(i=limit-1;i>=0;i--)
{
double dMaxHigh=0.0;
double dMinLow=0.0;
double WPR=0.0;
if(ExtMapBuffer1[i] > ExtMapBuffer2[i])
{
ExtMapBuffer3[i] = 2*(ExtMapBuffer1[i]-ExtMapBuffer2[i]);
ExtMapBuffer4[i] = 0;
//出現金叉
if(index>15&&counted_bars>-1&&ExtMapBuffer1[i+1] < ExtMapBuffer2[i+1])
{
dMaxHigh=High[Highest(NULL,0,MODE_HIGH,ExtWPRPeriod,i)];// 將. 賦爲第i個週期內最高價
dMinLow=Low[Lowest(NULL,0,MODE_LOW,ExtWPRPeriod,i)];// 將..賦爲第i個週期內最低價
//數組(第i個威廉指標值)= 100*(周極高-當時收)/(周極高-週期極低)
WPR=-100*(dMaxHigh-Close[i])/(dMaxHigh-dMinLow);
//此處可剔除盤整對MACD的影響
if(WPR>=WRMin&&WPR<=WRMax)
{
//diff上穿dea,金叉,但是要注意,0軸之下的金叉不靠譜,要排除,這裏把DIFF的值控制在一個合理的範圍,不能過低
if(ExtMapBuffer1[i]>MACDMin&&ExtMapBuffer2[i]>MACDMin)
{
ObjectCreate("vline"+index,OBJ_VLINE,0,Time[i],0);
ObjectSet("vline"+index,OBJPROP_COLOR,Red);
//ObjectCreate("arrow"+index,OBJ_ARROW,0,Time[i],Close[i]);
//ObjectSet("arrow"+index,OBJPROP_COLOR,Red);
ObjectCreate("text"+index,OBJ_TEXT,0,Time[i],Close[i]);
ObjectSetText("text"+index,"R:"+MathRound(WPR)+" "+ExtMapBuffer1[i],10,"Arial",White);
}
}
//如果是高位金叉,則靠譜
else if(WPR>=(WRMin-20)&&WPR<=(WRMax+20)&&ExtMapBuffer1[i]>MACDMax&&ExtMapBuffer2[i]>MACDMax)
{
ObjectCreate("vline"+index,OBJ_VLINE,0,Time[i],0);
ObjectSet("vline"+index,OBJPROP_COLOR,Red);
ObjectCreate("text"+index,OBJ_TEXT,0,Time[i],Close[i]);
ObjectSetText("text"+index,"R:"+MathRound(WPR)+" "+ExtMapBuffer1[i],10,"Arial",White);
}
}
}
else
{
ExtMapBuffer4[i] = 2*(ExtMapBuffer1[i]-ExtMapBuffer2[i]);
ExtMapBuffer3[i] = 0;
//出現死叉
if(index>15&&counted_bars>-1&&ExtMapBuffer1[i+1] > ExtMapBuffer2[i+1])
{
dMaxHigh=High[Highest(NULL,0,MODE_HIGH,ExtWPRPeriod,i)];// 將. 賦爲第i個週期內最高價
dMinLow=Low[Lowest(NULL,0,MODE_LOW,ExtWPRPeriod,i)];// 將..賦爲第i個週期內最低價
//數組(第i個威廉指標值)= 100*(周極高-當時收)/(周極高-週期極低)
WPR=-100*(dMaxHigh-Close[i])/(dMaxHigh-dMinLow);
//此處可剔除盤整對MACD的影響
if(WPR>=WRMin&&WPR<=WRMax)
{
//diff下穿dea,死叉,但是要注意,0軸之上的死叉不靠譜,要排除,這裏讓DIFF不要高於零軸太多
if(ExtMapBuffer1[i]<MACDMax&&ExtMapBuffer2[i]<MACDMax)
{
ObjectCreate("vline"+index,OBJ_VLINE,0,Time[i],0);
ObjectSet("vline"+index,OBJPROP_COLOR,Lime);
//ObjectCreate("arrow"+index,OBJ_ARROW,0,Time[i],Close[i]);
//ObjectSet("arrow"+index,OBJPROP_COLOR,Lime);
//ObjectSet("arrow"+index,OBJPROP_ARROWCODE,242);
ObjectCreate("text"+index,OBJ_TEXT,0,Time[i],Close[i]);
ObjectSetText("text"+index,"R:"+MathRound(WPR)+" "+ExtMapBuffer1[i],10,"Arial",White);
}
}//如果是低位死叉,則靠譜
else if(WPR>=(WRMin-20)&&WPR<=(WRMax+20)&&ExtMapBuffer1[i]<MACDMin&&ExtMapBuffer2[i]<MACDMin)
{
ObjectCreate("vline"+index,OBJ_VLINE,0,Time[i],0);
ObjectSet("vline"+index,OBJPROP_COLOR,Lime);
ObjectCreate("text"+index,OBJ_TEXT,0,Time[i],Close[i]);
ObjectSetText("text"+index,"R:"+MathRound(WPR)+" "+ExtMapBuffer1[i],10,"Arial",White);
}
}
}
index++;
}
//----
return(0);
}
//+------------------------------------------------------------------+
適用於歐元美元 M1,M5週期
MT4平臺下的指標——基於MACD和威廉指標的綜合考慮
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.