アプリ版:「スタンプのみでお礼する」機能のリリースについて

下記、MACDのプログラム、私としてはMACDライン、シグナルラインともにEMAを使いたいのですが、プログラムのどこがおかしいのか、EMAのMACD(Alertなし)と比べると全然表示が違います。どなたか詳しい方、変更の仕方を教えてください。(プログラムがわからないのでどこがおかしいのか・・・)
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
#property indicator_level1 0
#property indicator_levelcolor White
//---- input parameters
extern int fast_Period = 12;
extern int slow_Period = 26;
extern int signal_Period = 9;
extern string AlertSound = "alert.wav";
//---- buffers
double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{ //---- indicators
SetIndexStyle(0,DRAW_LINE,1,2);
SetIndexBuffer(0,Buffer1);
SetIndexLabel(0,"Main");
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Buffer2);
SetIndexLabel(1,"Signal");
//----
return(0);}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{int counted_bars = IndicatorCounted();
int limit = Bars - counted_bars;
for(int i=0; i < limit; i++)
{Buffer1[i] = iMACD(NULL, 0, fast_Period, slow_Period,signal_Period, PRICE_CLOSE,MODE_MAIN , i);
Buffer2[i] = iMACD(NULL, 0, fast_Period, slow_Period,signal_Period, PRICE_CLOSE,MODE_SIGNAL , i); }
if(Buffer1[1] < Buffer2[1] && Buffer1[0] > Buffer2[0])
{ PlaySound(AlertSound); ObjectDelete("BuySignal");
ObjectCreate("BuySignal",OBJ_ARROW,0 ,Time[0] ,Low[0]-10*Point);
ObjectSet("BuySignal",OBJPROP_ARROWCODE, 217);
ObjectSet("BuySignal",OBJPROP_COLOR, Blue); }
else if(Buffer1[1] > Buffer2[1] && Buffer1[0] < Buffer2[0])
{PlaySound(AlertSound); ObjectDelete("SellSignal");
ObjectCreate("SellSignal",OBJ_ARROW,0 ,Time[0] ,High[0]+10*Point);
ObjectSet("SellSignal",OBJPROP_ARROWCODE, 218);
ObjectSet("SellSignal",OBJPROP_COLOR, Red); }
//Comment ("MAIN: ",Buffer1[0]," / SIGNAL: ",Buffer2[0]);
return(0);}
//+------------------------------------------------------------------+

A 回答 (4件)

実際にMT4に表示させてみたのですが、特にヘンなところが見当たりません。



>EMAのMACD(Alertなし)と比べると全然表示が違います。

とありますが、これは表示される線の色が違うとかの話しですか?

この回答への補足

線の色ではなく、同じサブチャートに表示した際、線が重なり合うはずなのですが、全然重なり合いません。

補足日時:2012/12/28 00:13
    • good
    • 0

深いところに足を踏み入れてしまったようですね。



実は、MT4はMACDだけでなくADXなどにも標準のものと若干表示が違う(ADXなどは無茶苦茶
違います!)ものがあるのです。
ただ、それぞれどれが正しいかは、そもそもインジケーター自身に正しいも正しくないも
ないので(ちょっと意味が深すぎますね)解釈論になります。自分で正しいと思ったインジ
ケーターを使うしかありません。

ゴタクは置いておいて、表示が異なると言われる「EMAのMACD(Alertなし)」のソースを
貼り付けることはできますか?

正確に見てみたいと思います。

この回答への補足

下記、Alertがありますが、実際に重なりあわないプログラムです。
#property indicator_separate_window #property indicator_buffers 5 #property indicator_color1 Green #property indicator_color2 DeepPink #property indicator_width2 2 #property indicator_color3 DeepSkyBlue #property indicator_width3 2 #property indicator_color4 Red #property indicator_width4 0 #property indicator_color5 Blue #property indicator_width5 0 #property indicator_level1 0 #property indicator_levelcolor White //---- input parameters extern int FastMAPeriod=12; extern int SlowMAPeriod=26;
extern string _ma = "0:SMA 1:EMA 2:SMMA 3:LWMA"; extern int MAMethod = MODE_EMA; extern int SignalMAPeriod=9; extern int SignalMAMethod = MODE_EMA; extern bool ShowSignal = false; extern double SignalDiff = 0.000175; extern bool PopUpAlert=false; extern bool SoundAlert_Once = false; extern bool SoundAlert = false;
//---- buffers double HistogramBuffer[]; double SignalLineBuffer[]; double MACDLineBuffer[];
double AlertUpBuffer[]; double AlertDownBuffer[]; //---- variables double alpha = 0;
double alpha_1 = 0;
Custom indicator initialization function int init() { IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1); //---- indicators SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(0,HistogramBuffer); SetIndexDrawBegin(0,SlowMAPeriod+SignalMAPeriod); SetIndexStyle(1,DRAW_LINE/*,STYLE_DOT*/); SetIndexBuffer(1,SignalLineBuffer); SetIndexDrawBegin(1,SlowMAPeriod+SignalMAPeriod); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,MACDLineBuffer); SetIndexDrawBegin(2,SlowMAPeriod); SetIndexBuffer(3,AlertDownBuffer); SetIndexDrawBegin(3,SlowMAPeriod+SignalMAPeriod); SetIndexBuffer(4,AlertUpBuffer); SetIndexDrawBegin(4,SlowMAPeriod+SignalMAPeriod); if(ShowSignal){ SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,119); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,119); }else{ SetIndexStyle(3,DRAW_NONE); SetIndexStyle(4,DRAW_NONE); } //---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD+("+FastMAPeriod+","+SlowMAPeriod+","+SignalMAPeriod+")"); SetIndexLabel(0,"MACD"); SetIndexLabel(1,"Signal"); SetIndexLabel(2,"Hist"); SetIndexLabel(3,NULL); SetIndexLabel(4,NULL);
//---- //alpha = 2.0 / (SignalMAPeriod + 1.0); //alpha_1 = 1.0 - alpha; //---- if(StringFind(Symbol(),"JPY")!=-1) SignalDiff=SignalDiff*100; Print("SignalDiff = ",SignalDiff); return(0); }
Custor indicator deinitialization function int deinit() { //----  //---- return(0); }
Custom indicator iteration function
int start() { int limit,i; int counted_bars = IndicatorCounted(); //---- 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; for(i=limit; i>=0; i--) { MACDLineBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MAMethod,PRICE_CLOSE,i) -iMA(NULL,0,SlowMAPeriod,0,MAMethod,PRICE_CLOSE,i); } for(i=limit; i>=0; i--) { //SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1]; SignalLineBuffer[i] = iMAOnArray(MACDLineBuffer,0,SignalMAPeriod,0,SignalMAMethod,i);
HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i]; if(MACDLineBuffer[i] >MACDLineBuffer[i+1]+SignalDiff ){ AlertUpBuffer[i]=MACDLineBuffer[i]; }else{
AlertUpBuffer[i]=EMPTY_VALUE; } if(MACDLineBuffer[i] <MACDLineBuffer[i+1]-SignalDiff){ AlertDownBuffer[i]=MACDLineBuffer[i]; }else{ AlertDownBuffer[i]=EMPTY_VALUE; } } //---- static datetime lastBarTime = 0; bool newBar = false;
if( lastBarTime != Time[0] ){ newBar = true; lastBarTime = Time[0]; } if( HistogramBuffer[1] > 0 && HistogramBuffer[2] < 0 ){ if( newBar && PopUpAlert ){ Alert("MACD Cross UP "+Symbol()); } if( ( newBar && SoundAlert_Once ) || SoundAlert ){ PlaySound("alert"); } } if( HistogramBuffer[1] < 0 && HistogramBuffer[2] > 0 ){ if( newBar && PopUpAlert ){ Alert("MACD Cross Down "+Symbol()); } if( ( newBar && SoundAlert_Once ) || SoundAlert ){ PlaySound("alert"); } } return(0); }

補足日時:2012/12/28 12:00
    • good
    • 0

貼り付けてもらったインジケーターを正しく表示させるのに結構苦労しました^^;



さて、

> EMAのMACD(Alertなし)と比べると全然表示が違います。

とあるのは、Signalが違う、という理解でいいですか?

それでO.K.であるなら、理由は下記の通りです。
MT4標準のMACDはsignal lineがSMAで計算されてます。EMAではないのです。
MACDはEMAで計算しているのに、SignalはSMAなのがMT4の奇妙なセンスで、他のインジ
ケーターにも同様な理解に苦しむ設定がまま見られます。

従って、補足で貼り付けてもらったインジケーターにおいて、

extern int SignalMAMethod = MODE_EMA;

の部分を

extern int SignalMAMethod = MODE_SMA;

に書き換える(EをSにするだけ)と質問でのインジケーターと補足のインジケーターは
ビッタリ一致します。

同様にiMACDとかiADXとかiIchimokuとかMT4で標準に用意されている関数は、多くが
一般的定義のインジケーターと異なるため、私はそれらは全く使ってません。

この回答への補足

アドバイスありがとうございます。ただ、Signalラインだけでなく、MACDラインも違います。個人的にどちらもEMA表示を利用している(EMA表示を利用したい)のですが・・・。

補足日時:2013/01/03 00:20
    • good
    • 0

確認のため、画像を貼り付けてみました。



添付画像におけるインジケーターにて、上が質問のものと補足で貼り付けてもらったものを重ねた表示、下が補足のインジケーターのSignalをSMAに変えた場合です。
但し、以下の2点を行ってます。
・補足インジケーターのSignalの色を黄色に変えてます
・比較を正確にするため、表示のMax,Minを固定してます。

。。。とここまで書いて気付きました。もしかして、比較をする時にインジケーターのMax、Minを固定されていないんじゃないでしょうか?
それを確認するには、0ラインの破線が微妙にズレているのではないかと思います。
それでは比較ができないので、下記によりMax,Minを固定する必要があります。
#property indicator_minimum
#property indicator_maximum

話しを戻して、添付画像に見られるように、元々(上)はSignalだけ微妙にズレてますが、下ではビッタリ一致しているのが分かると思います。
「MACD_Cross_Alert.mq4」の回答画像4

この回答への補足

分かり易い画像ありがとうございます。指摘の通り、Max,Minの固定はしていません。これは、固定しないと無理なものなのでしょうか。個人的には、固定したくないのですが・・・。上記の綺麗に重なったチャートは、質問のインヂケーたのSignalが、SMAだと思うのですが、これを(1)EMAに変更する方法を教えていただけないでしょうか。
(EMAに変更したものが、補足のインジケータ:MACD、SignalともEMAのものと綺麗に重なってくれるとOKなのですが、(2)それもMAX,Minを固定しないと無理なのでしょうか・・・)

補足日時:2013/01/08 17:37
    • good
    • 0
この回答へのお礼

私の質問の仕方が、悪いみたいで再度、質問をアップロードしました。ただ、貴殿から教えていただいたMax、Minを設定しないと合致しないのかというのは、気になるところです。

お礼日時:2013/01/12 23:01

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!