//+------------------------------------------------------------------+ //| MTF_MACD_Bar.mq4 | //| FXナビ | //| http://www.fxnav.net | //+------------------------------------------------------------------+ /******************************************************************** 著作権は「株式会社キーストン」が有しております。 無断再配布、再編を禁止します。 使用した事によって発生した損害は、一切補償しません。 *********************************************************************/ #property copyright "FXキーストン" #property link "https://www.fxnav.net" #property version "1.0" #property strict #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 clrGreen #property indicator_color2 clrLime #property indicator_color3 clrRed #property indicator_color4 clrDeepPink #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 #property indicator_minimum 0 #property indicator_maximum 1 enum histogram{ histogram1=1, //通常のMACD histogram2=2 //MACDヒストグラム }; input ENUM_TIMEFRAMES TimeFrame = 0; //マルチタイムフレーム input int FastPeriod = 12; //短期期間 input int SlowPeriod = 26; //長期期間 input int SignalPeriod = 9; //シグナル期間 input histogram histogramMACD = 1; //MACDの種類 double Up1[], Up2[]; double Down1[], Down2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0, Up1); SetIndexBuffer(1, Up2); SetIndexBuffer(2, Down1); SetIndexBuffer(3, Down2); SetIndexStyle(0, DRAW_HISTOGRAM); SetIndexStyle(1, DRAW_HISTOGRAM); SetIndexStyle(2, DRAW_HISTOGRAM); SetIndexStyle(3, DRAW_HISTOGRAM); SetIndexLabel(0, NULL); SetIndexLabel(1, NULL); SetIndexLabel(2, NULL); SetIndexLabel(3, NULL); string TimeFrameStr = ""; switch(TimeFrame) { case 1 : TimeFrameStr="M1"; break; case 5 : TimeFrameStr="M5"; break; case 15 : TimeFrameStr="M15"; break; case 30 : TimeFrameStr="M30"; break; case 60 : TimeFrameStr="H1"; break; case 240 : TimeFrameStr="H4"; break; case 1440 : TimeFrameStr="D1"; break; case 10080 : TimeFrameStr="W1"; break; case 43200 : TimeFrameStr="MN1"; break; default : TimeFrameStr="Current"; } IndicatorShortName("MTF_MACD_Bar (" + TimeFrameStr + ")"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]){ //--- if(TimeFrame != 0 && _Period > TimeFrame) return(rates_total); int limit = 0; int counts = Bars - IndicatorCounted() -1; if(counts > 0) limit = MathMin(iBars(NULL, TimeFrame), Bars) - SlowPeriod -1; else limit = 0; datetime TimeArray[]; ArrayCopySeries(TimeArray, MODE_TIME, Symbol(), TimeFrame); if(counts > 0) limit = Bars -1; else limit = 0; for(int t=0, y=0; t macd) Down2[t] = 1; else Down1[t] = 1; } } else{ if(macd1 <= macd){ if(0 <= macd) Up2[t] = 1; else Up1[t] = 1; } else{ if(0 > macd) Down2[t] = 1; else Down1[t] = 1; } } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+