Please can someone help me correct the errors in this code. Thanks in advance
//+------------------------------------------------------------------+
//| MultiCross_Histogram.mq4 |
//| |
//+------------------------------------------------------------------+
#property copyright "Custom Indicator"
#property link ""
#property strict
// Indicator properties
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2
#property indicator_level1 0
// Input Parameters
input int RSI_Period = 3; // RSI Period
input int Momentum_Period = 3; // Momentum Period
input int DeM_Period = 3; // DeMarker Period
input int OsMA_Fast = 3; // OsMA Fast EMA
input int OsMA_Slow = 8; // OsMA Slow EMA
input int OsMA_Signal = 2; // OsMA Signal SMA
input bool Enable_Popups = true; // Popup Alerts
input bool Enable_Sounds = true; // Sound Alerts
input string Sound_File = "alert.wav"; // Sound File Name
input bool Enable_Email = false; // Email Alerts
// Buffers
double ExtBufferUp[];
double ExtBufferDown[];
datetime LastAlertTime = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
// Indicator lines mapping
SetIndexBuffer(0, ExtBufferUp);
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexLabel(0, "Bullish Cross");
SetIndexBuffer(1, ExtBufferDown);
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexLabel(1, "Bearish Cross");
IndicatorShortName("MultiCross_Histogram(" + RSI_Period + "," + Momentum_Period + "," + DeM_Period + ")");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
for(int i = limit; i >= 0; i--) {
// Initialize bars to 0
ExtBufferUp[i] = 0.0;
ExtBufferDown[i] = 0.0;
// Ensure we are not looking at the very first bars that might not have enough data
if(i > Bars - MathMax(MathMax(RSI_Period, Momentum_Period), DeM_Period)) continue;
// --- CALCULATE VALUES ---
double rsi_val_current = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
double rsi_val_previous = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i+1);
double mom_val_current = iMomentum(NULL, 0, Momentum_Period, PRICE_CLOSE, i);
double mom_val_previous = iMomentum(NULL, 0, Momentum_Period, PRICE_CLOSE, i+1);
double dem_val_current = iDeMarker(NULL, 0, DeM_Period, i);
double dem_val_previous = iDeMarker(NULL, 0, DeM_Period, i+1);
double osma_val_current = iOsMA(NULL, 0, OsMA_Fast, OsMA_Slow, OsMA_Signal, i);
double osma_val_previous = iOsMA(NULL, 0, OsMA_Fast, OsMA_Slow, OsMA_Signal, i+1);
// --- BULLISH LOGIC ---
bool rsi_bull_cross = (rsi_val_current > 55) && (rsi_val_previous <= 55);
bool mom_bull_cross = (mom_val_current > 100) && (mom_val_previous <= 100);
bool dem_bull_cross = (dem_val_current > 0.5) && (dem_val_previous <= 0.5);
bool osma_bull_cross = (osma_val_current > 0) && (osma_val_previous <= 0);
if(rsi_bull_cross && mom_bull_cross && dem_bull_cross && osma_bull_cross) {
ExtBufferUp[i] = 1.0;
DoAlert("Bullish", i);
}
// --- BEARISH LOGIC ---
bool rsi_bear_cross = (rsi_val_current < 45) && (rsi_val_previous >= 45);
bool mom_bear_cross = (mom_val_current < 100) && (mom_val_previous >= 100);
bool dem_bear_cross = (dem_val_current < 0.5) && (dem_val_previous >= 0.5);
bool osma_bear_cross = (osma_val_current < 0) && (osma_val_previous >= 0);
if(rsi_bear_cross && mom_bear_cross && dem_bear_cross && osma_bear_cross) {
ExtBufferDown[i] = -1.0;
DoAlert("Bearish", i);
}
}
return(0);
}
//+------------------------------------------------------------------+
//| Alert Handler |
//+------------------------------------------------------------------+
void DoAlert(string signalType, int shift) {
// Prevent duplicate alerts on the same bar
if(Time[shift] <= LastAlertTime) return;
// Alerts only fire on the currently forming bar (shift 0)
if(shift == 0) {
string message = Symbol() + " " + Period() + ": " + signalType + " MultiCross Signal!";
if(Enable_Popups) Alert(message);
if(Enable_Sounds) PlaySound(Sound_File);
if(Enable_Email) SendMail("MultiCross Alert", message);
LastAlertTime = Time[shift];
}
}
//+------------------------------------------------------------------+
//| MultiCross_Histogram.mq4 |
//| |
//+------------------------------------------------------------------+
#property copyright "Custom Indicator"
#property link ""
#property strict
// Indicator properties
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2
#property indicator_level1 0
// Input Parameters
input int RSI_Period = 3; // RSI Period
input int Momentum_Period = 3; // Momentum Period
input int DeM_Period = 3; // DeMarker Period
input int OsMA_Fast = 3; // OsMA Fast EMA
input int OsMA_Slow = 8; // OsMA Slow EMA
input int OsMA_Signal = 2; // OsMA Signal SMA
input bool Enable_Popups = true; // Popup Alerts
input bool Enable_Sounds = true; // Sound Alerts
input string Sound_File = "alert.wav"; // Sound File Name
input bool Enable_Email = false; // Email Alerts
// Buffers
double ExtBufferUp[];
double ExtBufferDown[];
datetime LastAlertTime = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
// Indicator lines mapping
SetIndexBuffer(0, ExtBufferUp);
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexLabel(0, "Bullish Cross");
SetIndexBuffer(1, ExtBufferDown);
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexLabel(1, "Bearish Cross");
IndicatorShortName("MultiCross_Histogram(" + RSI_Period + "," + Momentum_Period + "," + DeM_Period + ")");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
for(int i = limit; i >= 0; i--) {
// Initialize bars to 0
ExtBufferUp[i] = 0.0;
ExtBufferDown[i] = 0.0;
// Ensure we are not looking at the very first bars that might not have enough data
if(i > Bars - MathMax(MathMax(RSI_Period, Momentum_Period), DeM_Period)) continue;
// --- CALCULATE VALUES ---
double rsi_val_current = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
double rsi_val_previous = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i+1);
double mom_val_current = iMomentum(NULL, 0, Momentum_Period, PRICE_CLOSE, i);
double mom_val_previous = iMomentum(NULL, 0, Momentum_Period, PRICE_CLOSE, i+1);
double dem_val_current = iDeMarker(NULL, 0, DeM_Period, i);
double dem_val_previous = iDeMarker(NULL, 0, DeM_Period, i+1);
double osma_val_current = iOsMA(NULL, 0, OsMA_Fast, OsMA_Slow, OsMA_Signal, i);
double osma_val_previous = iOsMA(NULL, 0, OsMA_Fast, OsMA_Slow, OsMA_Signal, i+1);
// --- BULLISH LOGIC ---
bool rsi_bull_cross = (rsi_val_current > 55) && (rsi_val_previous <= 55);
bool mom_bull_cross = (mom_val_current > 100) && (mom_val_previous <= 100);
bool dem_bull_cross = (dem_val_current > 0.5) && (dem_val_previous <= 0.5);
bool osma_bull_cross = (osma_val_current > 0) && (osma_val_previous <= 0);
if(rsi_bull_cross && mom_bull_cross && dem_bull_cross && osma_bull_cross) {
ExtBufferUp[i] = 1.0;
DoAlert("Bullish", i);
}
// --- BEARISH LOGIC ---
bool rsi_bear_cross = (rsi_val_current < 45) && (rsi_val_previous >= 45);
bool mom_bear_cross = (mom_val_current < 100) && (mom_val_previous >= 100);
bool dem_bear_cross = (dem_val_current < 0.5) && (dem_val_previous >= 0.5);
bool osma_bear_cross = (osma_val_current < 0) && (osma_val_previous >= 0);
if(rsi_bear_cross && mom_bear_cross && dem_bear_cross && osma_bear_cross) {
ExtBufferDown[i] = -1.0;
DoAlert("Bearish", i);
}
}
return(0);
}
//+------------------------------------------------------------------+
//| Alert Handler |
//+------------------------------------------------------------------+
void DoAlert(string signalType, int shift) {
// Prevent duplicate alerts on the same bar
if(Time[shift] <= LastAlertTime) return;
// Alerts only fire on the currently forming bar (shift 0)
if(shift == 0) {
string message = Symbol() + " " + Period() + ": " + signalType + " MultiCross Signal!";
if(Enable_Popups) Alert(message);
if(Enable_Sounds) PlaySound(Sound_File);
if(Enable_Email) SendMail("MultiCross Alert", message);
LastAlertTime = Time[shift];
}
}