Fix compilation errors - convert to MQL4 syntax

- Remove MQL5-specific indicator properties
- Replace iMA handles with direct iMA function calls
- Replace PlotIndexSetString with SetIndexLabel
- Replace IndicatorRelease with MQL4 equivalent
- Replace CopyBuffer with direct iMA calls
- Replace MqlDateTime with TimeHour and TimeDayOfWeek
- Fix all MQL4/MQL5 compatibility issues
This commit is contained in:
Kunthawat Greethong
2026-01-02 13:14:34 +07:00
parent 7c7c118c5f
commit cd0b2e35a2

121
MAEA.mq4
View File

@@ -8,45 +8,7 @@
#property version "1.00"
#property strict
#property indicator_chart_window
//--- Indicator buffers
#property indicator_buffers 5
#property indicator_plots 5
//--- Plot settings for EMA High
#property indicator_label1 "EMA High"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLightBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- Plot settings for EMA Medium
#property indicator_label2 "EMA Medium"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrYellow
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//--- Plot settings for EMA Low
#property indicator_label3 "EMA Low"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrOrange
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//--- Plot settings for High Border
#property indicator_label4 "High Border"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrPurple
#property indicator_style4 STYLE_DASH
#property indicator_width4 1
//--- Plot settings for Low Border
#property indicator_label5 "Low Border"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrPurple
#property indicator_style5 STYLE_DASH
#property indicator_width5 1
//+------------------------------------------------------------------+
//| Input Parameters |
@@ -85,16 +47,6 @@ double EMALowBuffer[];
double HighBorderBuffer[];
double LowBorderBuffer[];
// EMA handles
int EMAHighHandle;
int EMAMediumHandle;
int EMALowHandle;
// D1 EMA handles for MTF filter
int D1_EMAHighHandle;
int D1_EMAMediumHandle;
int D1_EMALowHandle;
// State tracking
bool PullbackBuy = false;
bool PullbackSell = false;
@@ -130,34 +82,18 @@ int OnInit()
SetIndexBuffer(4, LowBorderBuffer);
// Set indicator labels
PlotIndexSetString(0, PLOT_LABEL, "EMA High");
PlotIndexSetString(1, PLOT_LABEL, "EMA Medium");
PlotIndexSetString(2, PLOT_LABEL, "EMA Low");
PlotIndexSetString(3, PLOT_LABEL, "High Border");
PlotIndexSetString(4, PLOT_LABEL, "Low Border");
SetIndexLabel(0, "EMA High");
SetIndexLabel(1, "EMA Medium");
SetIndexLabel(2, "EMA Low");
SetIndexLabel(3, "High Border");
SetIndexLabel(4, "Low Border");
// Initialize EMA handles
EMAHighHandle = iMA(Symbol(), PERIOD_CURRENT, EMAPeriod, 0, MODE_EMA, PRICE_HIGH);
EMAMediumHandle = iMA(Symbol(), PERIOD_CURRENT, EMAPeriod, 0, MODE_EMA, PRICE_CLOSE);
EMALowHandle = iMA(Symbol(), PERIOD_CURRENT, EMAPeriod, 0, MODE_EMA, PRICE_LOW);
// Initialize D1 EMA handles for MTF filter
D1_EMAHighHandle = iMA(Symbol(), PERIOD_D1, EMAPeriod, 0, MODE_EMA, PRICE_HIGH);
D1_EMAMediumHandle = iMA(Symbol(), PERIOD_D1, EMAPeriod, 0, MODE_EMA, PRICE_CLOSE);
D1_EMALowHandle = iMA(Symbol(), PERIOD_D1, EMAPeriod, 0, MODE_EMA, PRICE_LOW);
// Check handles
if(EMAHighHandle == INVALID_HANDLE || EMAMediumHandle == INVALID_HANDLE || EMALowHandle == INVALID_HANDLE)
{
Print("Error creating EMA handles");
return(INIT_FAILED);
}
if(UseMTFFilter && (D1_EMAHighHandle == INVALID_HANDLE || D1_EMAMediumHandle == INVALID_HANDLE || D1_EMALowHandle == INVALID_HANDLE))
{
Print("Error creating D1 EMA handles");
return(INIT_FAILED);
}
// Set indicator styles
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, clrLightBlue);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2, clrYellow);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2, clrOrange);
SetIndexStyle(3, DRAW_LINE, STYLE_DASH, 1, clrPurple);
SetIndexStyle(4, DRAW_LINE, STYLE_DASH, 1, clrPurple);
// Parse news filter arrays
ParseNewsFilterArrays();
@@ -174,14 +110,6 @@ int OnInit()
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Release indicator handles
if(EMAHighHandle != INVALID_HANDLE) IndicatorRelease(EMAHighHandle);
if(EMAMediumHandle != INVALID_HANDLE) IndicatorRelease(EMAMediumHandle);
if(EMALowHandle != INVALID_HANDLE) IndicatorRelease(EMALowHandle);
if(D1_EMAHighHandle != INVALID_HANDLE) IndicatorRelease(D1_EMAHighHandle);
if(D1_EMAMediumHandle != INVALID_HANDLE) IndicatorRelease(D1_EMAMediumHandle);
if(D1_EMALowHandle != INVALID_HANDLE) IndicatorRelease(D1_EMALowHandle);
Print("MAEA deinitialized");
}
@@ -232,10 +160,10 @@ int OnCalculate(const int rates_total,
// Calculate EMA values and border lines
for(int i = start; i < rates_total; i++)
{
// Get EMA values
double emaHigh = GetEMAValue(EMAHighHandle, i);
double emaMedium = GetEMAValue(EMAMediumHandle, i);
double emaLow = GetEMAValue(EMALowHandle, i);
// Get EMA values using iMA function (MQL4 style)
double emaHigh = iMA(Symbol(), PERIOD_CURRENT, EMAPeriod, 0, MODE_EMA, PRICE_HIGH, i);
double emaMedium = iMA(Symbol(), PERIOD_CURRENT, EMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
double emaLow = iMA(Symbol(), PERIOD_CURRENT, EMAPeriod, 0, MODE_EMA, PRICE_LOW, i);
// Calculate range
double range = emaMedium - emaLow;
@@ -283,12 +211,9 @@ int OnCalculate(const int rates_total,
//+------------------------------------------------------------------+
//| Get EMA value from handle |
//+------------------------------------------------------------------+
double GetEMAValue(int handle, int shift)
double GetEMAValue(int timeframe, int applied_price, int shift)
{
double value[];
ArraySetAsSeries(value, true);
CopyBuffer(handle, 0, shift, 1, value);
return(value[0]);
return iMA(Symbol(), timeframe, EMAPeriod, 0, MODE_EMA, applied_price, shift);
}
//+------------------------------------------------------------------+
@@ -479,8 +404,8 @@ bool CheckVolumeFilter(const long &tick_volume[], int rates_total)
bool CheckMTFFilter()
{
double d1Close = iClose(Symbol(), PERIOD_D1, 0);
double d1EMAHigh = GetEMAValue(D1_EMAHighHandle, 0);
double d1EMALow = GetEMAValue(D1_EMALowHandle, 0);
double d1EMAHigh = GetEMAValue(PERIOD_D1, PRICE_HIGH, 0);
double d1EMALow = GetEMAValue(PERIOD_D1, PRICE_LOW, 0);
if(d1Close > d1EMAHigh)
{
@@ -504,13 +429,11 @@ bool CheckMTFFilter()
//+------------------------------------------------------------------+
bool CheckNewsFilter(datetime currentTime)
{
MqlDateTime timeStruct;
TimeToStruct(currentTime, timeStruct);
// Convert to Thailand timezone (UTC+7)
// MT4 server time is usually UTC, so add 7 hours
int thailandHour = (timeStruct.hour + 7) % 24;
int thailandDay = timeStruct.day_of_week;
datetime thailandTime = currentTime + 7 * 3600; // 7 hours in seconds
int thailandHour = TimeHour(thailandTime);
int thailandDay = TimeDayOfWeek(thailandTime);
// Check if current hour is in avoid list
for(int i = 0; i < ArraySize(AvoidHoursArray); i++)