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