on compiling : //+------------------------------------------------------------------+ //…
- User
on compiling :
//+------------------------------------------------------------------+ //| MACD Zero Cross | //| Custom indicator for MetaTrader 5 | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1
#property plot1 ArrowBuffer #property indicator_type1 DRAW_ARROW #property indicator_color1 clrRed #property indicator_width1 2 #property indicator_label1 "Zero Cross"
double ArrowBuffer[];
// MACD parameters input int fast_ema = 12; input int slow_ema = 26; input int signal_sma = 9;
// Internal buffers double macd_main[], macd_signal[], macd_hist[];
int OnInit() { SetIndexBuffer(0, ArrowBuffer, INDICATOR_DATA); ArraySetAsSeries(ArrowBuffer, true);
SetIndexStyle(0, DRAW_ARROW); PlotIndexSetInteger(0, PLOT_ARROW, 233); // Up/down arrow code
IndicatorSetInteger(INDICATOR_DIGITS, _Digits); return(INIT_SUCCEEDED); }
int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { // Calculate MACD if(!iMACD(NULL, 0, fast_ema, slow_ema, signal_sma, PRICE_CLOSE, macd_main, macd_signal)) return(0);
int limit = rates_total - prev_calculated;
for(int i = limit - 1; i >= 1; i--) { double hist_current = macd_main[i] - macd_signal[i]; double hist_previous = macd_main[i+1] - macd_signal[i+1];
// Zero cross from below = Buy Signal if(hist_current > 0 && hist_previous <= 0) ArrowBuffer[i] = Low[i] - (10 * _Point); // Draw below candle // Zero cross from above = Sell Signal else if(hist_current < 0 && hist_previous >= 0) ArrowBuffer[i] = High[i] + (10 * _Point); // Draw above candle else ArrowBuffer[i] = EMPTY_VALUE; }return(rates_total); }
i get errors: 'MACD_Histogram_Zero_Cross.mq5' 0 'plot1' - unknown property MACD_Histogram_Zero_Cross.mq5 12 11 'SetIndexStyle' - undeclared identifier MACD_Histogram_Zero_Cross.mq5 33 4 ',' - unexpected token MACD_Histogram_Zero_Cross.mq5 33 19 '0' - some operator expected MACD_Histogram_Zero_Cross.mq5 33 18 ')' - unexpected token MACD_Histogram_Zero_Cross.mq5 33 31 'iMACD' - wrong parameters count MACD_Histogram_Zero_Cross.mq5 46 8 built-in: int iMACD(const string,ENUM_TIMEFRAMES,int,int,int,int) MACD_Histogram_Zero_Cross.mq5 46 8 'Low' - undeclared identifier MACD_Histogram_Zero_Cross.mq5 58 27 '[' - array required MACD_Histogram_Zero_Cross.mq5 58 30 'High' - undeclared identifier MACD_Histogram_Zero_Cross.mq5 62 27 '[' - array required MACD_Histogram_Zero_Cross.mq5 62 31 10 errors, 0 warnings 10 0
- Assistant
- User
what should i see on the chart after adding the indicator to it
- Assistant
After adding the fixed MACD Zero Cross indicator to your chart, here’s what you should expect to see:
Visual Output:
- Arrow symbols (red arrows by default) will appear on the price chart where the MACD histogram crosses zero.
Specifically:
-
Upward (buy) signals:
- User
id also like to view the actual MACD lines on the chart
- Assistant
- User
lets do this :add a separate indicator window to host these lines using #property indicator_separate_window, but then arrows won't appear on the price chart.
- Assistant