feat(maea): migrate from MQL4 to MQL5 and simplify strategy
Migrate MAEA Expert Advisor from MetaTrader 4 to MetaTrader 5 platform with significant strategy simplification and architectural improvements. Key changes: - Platform: MQL4 → MQL5 - Indicators: Reduced from 5 lines (3 EMAs + 2 borders) to 2 EMAs with zone fill - Strategy: Removed pullback signals and dynamic lot sizing - Lot sizing: Changed from dynamic (0.01/0.02) to fixed 0.01 lot - Stop loss: Changed from Border Lines to opposite EMA (Buy: EMA Low, Sell: EMA High) - Signal logic: Added opposite signal close for reversal protection - New filter: Added minimum zone width filter (100 points) - Documentation: Updated implementation plans and project summary - New files: Added AGENTS.md, MAEA_Indicator.mq5, and opencode.jsonc BREAKING CHANGE: Complete rewrite from MQL4 to MQL5 with simplified strategy. Previous MAEA.mq4 and README.md deleted. New implementation requires MetaTrader 5.
This commit is contained in:
109
MAEA_Indicator.mq5
Normal file
109
MAEA_Indicator.mq5
Normal file
@@ -0,0 +1,109 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MAEA_Indicator.mq5 |
|
||||
//| Moving Average EA |
|
||||
//| Visual indicator for EMA zone breakout |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "MAEA"
|
||||
#property link ""
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
#property indicator_label1 "EMA High"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightBlue
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
#property indicator_label2 "EMA Low"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrOrange
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
#property indicator_label3 "EMA Zone"
|
||||
#property indicator_type3 DRAW_FILLING
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
input int EMAPeriod = 30;
|
||||
input int EMAShift = 0;
|
||||
|
||||
int handleEMAHigh;
|
||||
int handleEMALow;
|
||||
|
||||
double BufferEMAHigh[];
|
||||
double BufferEMALow[];
|
||||
double BufferZone[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
ArraySetAsSeries(BufferEMAHigh, true);
|
||||
ArraySetAsSeries(BufferEMALow, true);
|
||||
ArraySetAsSeries(BufferZone, true);
|
||||
|
||||
SetIndexBuffer(0, BufferEMAHigh, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, BufferEMALow, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, BufferZone, INDICATOR_CALCULATIONS);
|
||||
|
||||
ArraySetAsSeries(BufferEMAHigh, true);
|
||||
ArraySetAsSeries(BufferEMALow, true);
|
||||
ArraySetAsSeries(BufferZone, true);
|
||||
|
||||
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, EMAPeriod + EMAShift);
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, EMAPeriod + EMAShift);
|
||||
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, EMAPeriod + EMAShift);
|
||||
|
||||
handleEMAHigh = iMA(_Symbol, PERIOD_CURRENT, EMAPeriod, EMAShift, MODE_EMA, PRICE_HIGH);
|
||||
handleEMALow = iMA(_Symbol, PERIOD_CURRENT, EMAPeriod, EMAShift, MODE_EMA, PRICE_LOW);
|
||||
|
||||
if(handleEMAHigh == INVALID_HANDLE || handleEMALow == INVALID_HANDLE) {
|
||||
Print("Failed to create EMA handles");
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason) {
|
||||
IndicatorRelease(handleEMAHigh);
|
||||
IndicatorRelease(handleEMALow);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[]) {
|
||||
|
||||
if(rates_total < EMAPeriod + EMAShift) return 0;
|
||||
|
||||
int copied = CopyBuffer(handleEMAHigh, 0, 0, rates_total, BufferEMAHigh);
|
||||
if(copied <= 0) return 0;
|
||||
|
||||
copied = CopyBuffer(handleEMALow, 0, 0, rates_total, BufferEMALow);
|
||||
if(copied <= 0) return 0;
|
||||
|
||||
return rates_total;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user