//------------------------------------------------------------------ #property copyright "www.forex-tsd.com" #property link "www.forex-tsd.com" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 2 #property indicator_label1 "MACD" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 LimeGreen,PaleVioletRed #property indicator_width1 2 #property indicator_label2 "Signal" #property indicator_type2 DRAW_LINE #property indicator_color2 Gold // // // // // enum enPrices { pr_close, // Close pr_open, // Open pr_high, // High pr_low, // Low pr_median, // Median pr_typical, // Typical pr_weighted, // Weighted pr_haclose, // Heiken ashi close pr_haopen , // Heiken ashi open pr_hahigh, // Heiken ashi high pr_halow, // Heiken ashi low pr_hamedian, // Heiken ashi median pr_hatypical, // Heiken ashi typical pr_haweighted, // Heiken ashi weighted pr_haaverage // Heiken ashi average }; input int InpFastEMA = 12; // Fast EMA period input int InpSlowEMA = 26; // Slow EMA period input int InpSignalEMA = 9; // Signal EMA period input enPrices InpAppliedPrice = pr_close; // Price to use input bool ColorOnSlope = false; // Change MACD color on slope change // // // // // double macd[]; double macdColor[]; double signal[]; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // void OnInit() { SetIndexBuffer(0,macd ,INDICATOR_DATA); SetIndexBuffer(1,macdColor,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,signal ,INDICATOR_DATA); IndicatorSetString(INDICATOR_SHORTNAME,"MACD original("+string(InpFastEMA)+","+string(InpSlowEMA)+","+string(InpSignalEMA)+")"); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // double emas[][2]; #define _fast 0 #define _slow 1 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 (ArrayRange(emas,0)!=rates_total) ArrayResize(emas,rates_total); // // // // // double alphafa = 2.0 / (1.0 +InpFastEMA); double alphasl = 2.0 / (1.0 +InpSlowEMA); double alphasi = 2.0 / (1.0 +InpSignalEMA); for (int i=(int)MathMax(prev_calculated-1,0); imacd[i-1]) macdColor[i] = 0; if (macd[i]signal[i]) macdColor[i] = 0; if (macd[i]=pr_haclose && pricet<=pr_haaverage) { if (ArrayRange(workHa,0)!= bars) ArrayResize(workHa,bars); // // // // // double haOpen; if (i>0) haOpen = (workHa[i-1][2] + workHa[i-1][3])/2.0; else haOpen = open[i]+close[i]; double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0; double haHigh = MathMax(high[i], MathMax(haOpen,haClose)); double haLow = MathMin(low[i] , MathMin(haOpen,haClose)); if(haOpen