DEV Community

Gbenga Mcdave
Gbenga Mcdave

Posted on

Debug this code pls

//+------------------------------------------------------------------+
//| CombinedIndicator.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+

property copyright "Copyright 2024, MetaQuotes Ltd."

property link "https://www.mql5.com"

property version "1.00"

property indicator_chart_window

property indicator_buffers 2

property indicator_plots 2

property script_show_inputs

//--- plot Oscillator

property indicator_label1 "Oscillator"

property indicator_type1 DRAW_LINE

property indicator_color1 clrBlue

property indicator_style1 STYLE_SOLID

property indicator_width1 1

//--- plot Signal

property indicator_label2 "Signal"

property indicator_type2 DRAW_LINE

property indicator_color2 clrRed

property indicator_style2 STYLE_SOLID

property indicator_width2 1

//--- input parameters
input int InpFastPeriod=12; // Fast Period
input int InpSlowPeriod=26; // Slow Period
input int InpSignalPeriod=9; // Signal Period
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame

//--- indicator buffers
double ExtOscillatorBuffer[];
double ExtSignalBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOscillatorBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);

//--- Get the current chart ID
long chartID = ChartID();

//--- Set the chart time frame
ChartSetInteger(chartID, CHART_PERIOD_PROPERTY, (int)TimeFrame);

//--- Redraw the chart
ChartRedraw(chartID);

//---
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[])
{
//---
int limit = rates_total - prev_calculated;
if(limit>0)
{
for(int i=limit-1; i>=0; i--)
{
double oscillator = iMACD(NULL, 0, InpFastPeriod, InpSlowPeriod, InpSignalPeriod, PRICE_CLOSE, MODE_MAIN, i);
double signal = iMACD(NULL, 0, InpFastPeriod, InpSlowPeriod, InpSignalPeriod, PRICE_CLOSE, MODE_SIGNAL, i);
ExtOscillatorBuffer[i] = oscillator;
ExtSignalBuffer[i] = signal;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+ pls help correct this code , i want the ouput to be seen in the indicate in meta 5

Top comments (0)