From 17d228e31bb5515dc50c3c642c3a35409f81faa5 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 24 Oct 2025 16:27:11 +0200 Subject: [PATCH] refactor: remove old files --- Include/MyIncludes/MAMA_FAMA_Calculator.mqh | 250 -------------------- Include/MyIncludes/MESA_Calculator.mqh | 232 ------------------ Indicators/MyIndicators/FAMA.mq5 | Bin 8014 -> 0 bytes Indicators/MyIndicators/MAMA.mq5 | 100 -------- Indicators/MyIndicators/MAMA_FAMA_Pro.md | 64 ----- Indicators/MyIndicators/MAMA_FAMA_Pro.mq5 | 124 ---------- 6 files changed, 770 deletions(-) delete mode 100644 Include/MyIncludes/MAMA_FAMA_Calculator.mqh delete mode 100644 Include/MyIncludes/MESA_Calculator.mqh delete mode 100644 Indicators/MyIndicators/FAMA.mq5 delete mode 100644 Indicators/MyIndicators/MAMA.mq5 delete mode 100644 Indicators/MyIndicators/MAMA_FAMA_Pro.md delete mode 100644 Indicators/MyIndicators/MAMA_FAMA_Pro.mq5 diff --git a/Include/MyIncludes/MAMA_FAMA_Calculator.mqh b/Include/MyIncludes/MAMA_FAMA_Calculator.mqh deleted file mode 100644 index 2e588c7..0000000 --- a/Include/MyIncludes/MAMA_FAMA_Calculator.mqh +++ /dev/null @@ -1,250 +0,0 @@ -//+------------------------------------------------------------------+ -//| MAMA_FAMA_Calculator.mqh | -//| Calculation engine for Standard and Heikin Ashi MAMA/FAMA. | -//| (Based on the official MotiveWave pseudo-code) | -//| Copyright 2025, xxxxxxxx | -//+------------------------------------------------------------------+ -#property copyright "Copyright 2025, xxxxxxxx" - -#include - -//+==================================================================+ -//| | -//| CLASS 1: CMAMACalculator (Base Class) | -//| | -//+==================================================================+ -class CMAMACalculator - { -protected: - double m_fast_limit; - double m_slow_limit; - - //--- Internal buffers for state-dependent calculation - double m_price[]; - double m_smooth[]; - double m_detrender[]; - double m_i1[]; - double m_q1[]; - double m_jI[]; - double m_jQ[]; - double m_i2[]; - double m_q2[]; - double m_re[]; - double m_im[]; - double m_period[]; - double m_smooth_period[]; - double m_phase[]; - double m_alpha[]; - - virtual bool PreparePriceSeries(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]); - -public: - CMAMACalculator(void); - virtual ~CMAMACalculator(void) {}; - - bool Init(double fast_limit, double slow_limit); - void Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &mama_out[], double &fama_out[]); - }; - -//+------------------------------------------------------------------+ -//| CMAMACalculator: Constructor | -//+------------------------------------------------------------------+ -CMAMACalculator::CMAMACalculator(void) : m_fast_limit(0.5), m_slow_limit(0.05) - { - } - -//+------------------------------------------------------------------+ -//| CMAMACalculator: Initialization | -//+------------------------------------------------------------------+ -bool CMAMACalculator::Init(double fast_limit, double slow_limit) - { - m_fast_limit = fast_limit; - m_slow_limit = slow_limit; - return true; - } - -//+------------------------------------------------------------------+ -//| CMAMACalculator: Main Calculation Method | -//+------------------------------------------------------------------+ -void CMAMACalculator::Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &mama_out[], double &fama_out[]) - { - int warmup_period = 10; - if(rates_total < warmup_period) - return; - -//--- Resize all internal buffers - ArrayResize(m_price, rates_total); - ArrayResize(m_smooth, rates_total); - ArrayResize(m_detrender, rates_total); - ArrayResize(m_i1, rates_total); - ArrayResize(m_q1, rates_total); - ArrayResize(m_jI, rates_total); - ArrayResize(m_jQ, rates_total); - ArrayResize(m_i2, rates_total); - ArrayResize(m_q2, rates_total); - ArrayResize(m_re, rates_total); - ArrayResize(m_im, rates_total); - ArrayResize(m_period, rates_total); - ArrayResize(m_smooth_period, rates_total); - ArrayResize(m_phase, rates_total); - ArrayResize(m_alpha, rates_total); - - if(!PreparePriceSeries(rates_total, price_type, open, high, low, close)) - return; - - for(int i = 0; i < rates_total; i++) - { - if(i < warmup_period) - { - mama_out[i] = m_price[i]; - fama_out[i] = m_price[i]; - m_period[i] = 20; - m_smooth_period[i] = 20; - continue; - } - - double prev_period = (i > 0) ? m_period[i-1] : 20; - double prev_smooth_period = (i > 0) ? m_smooth_period[i-1] : 20; - double prev_phase = (i > 0) ? m_phase[i-1] : 0; - double prev_i2 = (i > 0) ? m_i2[i-1] : 0; - double prev_q2 = (i > 0) ? m_q2[i-1] : 0; - double prev_re = (i > 0) ? m_re[i-1] : 0; - double prev_im = (i > 0) ? m_im[i-1] : 0; - double prev_mama = (i > 0) ? mama_out[i-1] : m_price[i]; - double prev_fama = (i > 0) ? fama_out[i-1] : m_price[i]; - - m_smooth[i] = (4*m_price[i] + 3*m_price[i-1] + 2*m_price[i-2] + m_price[i-3]) / 10.0; - m_detrender[i] = (0.0962*m_smooth[i] + 0.5769*m_smooth[i-2] - 0.5769*m_smooth[i-4] - 0.0962*m_smooth[i-6]) * (0.075*prev_period + 0.54); - m_q1[i] = (0.0962*m_detrender[i] + 0.5769*m_detrender[i-2] - 0.5769*m_detrender[i-4] - 0.0962*m_detrender[i-6]) * (0.075*prev_period + 0.54); - m_i1[i] = m_detrender[i-3]; - m_jI[i] = (0.0962*m_i1[i] + 0.5769*m_i1[i-2] - 0.5769*m_i1[i-4] - 0.0962*m_i1[i-6]) * (0.075*prev_period + 0.54); - m_jQ[i] = (0.0962*m_q1[i] + 0.5769*m_q1[i-2] - 0.5769*m_q1[i-4] - 0.0962*m_q1[i-6]) * (0.075*prev_period + 0.54); - m_i2[i] = m_i1[i] - m_jQ[i]; - m_q2[i] = m_q1[i] + m_jI[i]; - m_i2[i] = 0.2*m_i2[i] + 0.8*prev_i2; - m_q2[i] = 0.2*m_q2[i] + 0.8*prev_q2; - m_re[i] = m_i2[i]*prev_i2 + m_q2[i]*prev_q2; - m_im[i] = m_i2[i]*prev_q2 - m_q2[i]*prev_i2; - m_re[i] = 0.2*m_re[i] + 0.8*prev_re; - m_im[i] = 0.2*m_im[i] + 0.8*prev_im; - if(m_im[i]!=0.0 && m_re[i]!=0.0) - m_period[i] = 360.0/(MathArctan(m_im[i]/m_re[i])*180.0/M_PI); - else - m_period[i] = prev_period; - if(m_period[i]>1.5*prev_period) - m_period[i]=1.5*prev_period; - if(m_period[i]<0.67*prev_period) - m_period[i]=0.67*prev_period; - if(m_period[i]<6) - m_period[i]=6; - if(m_period[i]>50) - m_period[i]=50; - m_period[i] = 0.2*m_period[i] + 0.8*prev_period; - m_smooth_period[i] = 0.33*m_period[i] + 0.67*prev_smooth_period; - if(m_i1[i]!=0.0) - m_phase[i] = (MathArctan(m_q1[i]/m_i1[i])*180.0/M_PI); - else - m_phase[i] = prev_phase; - double delta_phase = prev_phase - m_phase[i]; - if(delta_phase<1.0) - delta_phase=1.0; - m_alpha[i] = m_fast_limit/delta_phase; - if(m_alpha[i]m_fast_limit) - m_alpha[i]=m_fast_limit; - mama_out[i] = m_alpha[i]*m_price[i] + (1-m_alpha[i])*prev_mama; - fama_out[i] = 0.5*m_alpha[i]*mama_out[i] + (1-0.5*m_alpha[i])*prev_fama; - } - } - -//+------------------------------------------------------------------+ -//| CMAMACalculator: Prepares the standard source price series. | -//+------------------------------------------------------------------+ -bool CMAMACalculator::PreparePriceSeries(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]) - { - switch(price_type) - { - case PRICE_OPEN: - ArrayCopy(m_price, open, 0, 0, rates_total); - break; - case PRICE_HIGH: - ArrayCopy(m_price, high, 0, 0, rates_total); - break; - case PRICE_LOW: - ArrayCopy(m_price, low, 0, 0, rates_total); - break; - case PRICE_MEDIAN: - for(int i=0; i - -//+==================================================================+ -//| | -//| CLASS 1: CMESACalculator (Standard) | -//| | -//+==================================================================+ -class CMESACalculator - { -protected: - double m_fast_limit; - double m_slow_limit; - -#define DECLARE_BUFFER(name) double m_##name[] - DECLARE_BUFFER(price); - DECLARE_BUFFER(smooth); - DECLARE_BUFFER(detrender); - DECLARE_BUFFER(i1); - DECLARE_BUFFER(q1); - DECLARE_BUFFER(jI); - DECLARE_BUFFER(jQ); - DECLARE_BUFFER(i2); - DECLARE_BUFFER(q2); - DECLARE_BUFFER(re); - DECLARE_BUFFER(im); - DECLARE_BUFFER(period); - DECLARE_BUFFER(smooth_period); - DECLARE_BUFFER(phase); - DECLARE_BUFFER(alpha); - DECLARE_BUFFER(mama); - DECLARE_BUFFER(fama); -#undef DECLARE_BUFFER - - virtual bool PreparePriceSeries(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]); - -public: - CMESACalculator(void); - virtual ~CMESACalculator(void) {}; - - bool Init(double fast_limit, double slow_limit); - void Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &mama_out[], double &fama_out[]); - }; - -//+------------------------------------------------------------------+ -//| CMESACalculator: Constructor | -//+------------------------------------------------------------------+ -CMESACalculator::CMESACalculator(void) : m_fast_limit(0.5), m_slow_limit(0.05) - { - } - -//+------------------------------------------------------------------+ -//| CMESACalculator: Initialization | -//+------------------------------------------------------------------+ -bool CMESACalculator::Init(double fast_limit, double slow_limit) - { - m_fast_limit = fast_limit; - m_slow_limit = slow_limit; - return true; - } - -//+------------------------------------------------------------------+ -//| CMESACalculator: Main Calculation Method | -//+------------------------------------------------------------------+ -void CMESACalculator::Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &mama_out[], double &fama_out[]) - { - int warmup_period = 10; - if(rates_total < warmup_period) - return; - -#define RESIZE_BUFFER(name) ArrayResize(m_##name, rates_total, 0) - RESIZE_BUFFER(price); - RESIZE_BUFFER(smooth); - RESIZE_BUFFER(detrender); - RESIZE_BUFFER(i1); - RESIZE_BUFFER(q1); - RESIZE_BUFFER(jI); - RESIZE_BUFFER(jQ); - RESIZE_BUFFER(i2); - RESIZE_BUFFER(q2); - RESIZE_BUFFER(re); - RESIZE_BUFFER(im); - RESIZE_BUFFER(period); - RESIZE_BUFFER(smooth_period); - RESIZE_BUFFER(phase); - RESIZE_BUFFER(alpha); - RESIZE_BUFFER(mama); - RESIZE_BUFFER(fama); -#undef RESIZE_BUFFER - - if(!PreparePriceSeries(rates_total, price_type, open, high, low, close)) - return; - -#define nz(arr, idx) ( (i >= idx) ? arr[i-idx] : 0 ) - - for(int i = 0; i < rates_total; i++) - { - if(i < warmup_period) - { - m_mama[i] = m_price[i]; - m_fama[i] = m_price[i]; - m_period[i] = 20; - m_smooth_period[i] = 20; - continue; - } - - m_smooth[i] = (4 * m_price[i] + 3 * nz(m_price,1) + 2 * nz(m_price,2) + nz(m_price,3)) / 10.0; - m_detrender[i] = (0.0962 * m_smooth[i] + 0.5769 * nz(m_smooth,2) - 0.5769 * nz(m_smooth,4) - 0.0962 * nz(m_smooth,6)) * (0.075 * nz(m_period,1) + 0.54); - m_q1[i] = (0.0962 * m_detrender[i] + 0.5769 * nz(m_detrender,2) - 0.5769 * nz(m_detrender,4) - 0.0962 * nz(m_detrender,6)) * (0.075 * nz(m_period,1) + 0.54); - m_i1[i] = nz(m_detrender,3); - m_jI[i] = (0.0962 * m_i1[i] + 0.5769 * nz(m_i1,2) - 0.5769 * nz(m_i1,4) - 0.0962 * nz(m_i1,6)) * (0.075 * nz(m_period,1) + 0.54); - m_jQ[i] = (0.0962 * m_q1[i] + 0.5769 * nz(m_q1,2) - 0.5769 * nz(m_q1,4) - 0.0962 * nz(m_q1,6)) * (0.075 * nz(m_period,1) + 0.54); - m_i2[i] = m_i1[i] - m_jQ[i]; - m_q2[i] = m_q1[i] + m_jI[i]; - m_i2[i] = 0.2 * m_i2[i] + 0.8 * nz(m_i2,1); - m_q2[i] = 0.2 * m_q2[i] + 0.8 * nz(m_q2,1); - m_re[i] = m_i2[i] * nz(m_i2,1) + m_q2[i] * nz(m_q2,1); - m_im[i] = m_i2[i] * nz(m_q2,1) - m_q2[i] * nz(m_i2,1); - m_re[i] = 0.2 * m_re[i] + 0.8 * nz(m_re,1); - m_im[i] = 0.2 * m_im[i] + 0.8 * nz(m_im,1); - if(m_im[i] != 0.0 && m_re[i] != 0.0) - m_period[i] = 360.0 / (MathArctan(m_im[i] / m_re[i]) * 180.0 / M_PI); - else - m_period[i] = nz(m_period,1); - if(m_period[i] > 1.5 * nz(m_period,1)) - m_period[i] = 1.5 * nz(m_period,1); - if(m_period[i] < 0.67 * nz(m_period,1)) - m_period[i] = 0.67 * nz(m_period,1); - if(m_period[i] < 6) - m_period[i] = 6; - if(m_period[i] > 50) - m_period[i] = 50; - m_period[i] = 0.2 * m_period[i] + 0.8 * nz(m_period,1); - m_smooth_period[i] = 0.33 * m_period[i] + 0.67 * nz(m_smooth_period,1); - if(m_i1[i] != 0.0) - m_phase[i] = (MathArctan(m_q1[i] / m_i1[i]) * 180.0 / M_PI); - else - m_phase[i] = nz(m_phase,1); - double delta_phase = nz(m_phase,1) - m_phase[i]; - if(delta_phase < 1.0) - delta_phase = 1.0; - m_alpha[i] = m_fast_limit / delta_phase; - if(m_alpha[i] < m_slow_limit) - m_alpha[i] = m_slow_limit; - if(m_alpha[i] > m_fast_limit) - m_alpha[i] = m_fast_limit; - m_mama[i] = m_alpha[i] * m_price[i] + (1 - m_alpha[i]) * nz(m_mama,1); - m_fama[i] = 0.5 * m_alpha[i] * m_mama[i] + (1 - 0.5 * m_alpha[i]) * nz(m_fama,1); - } - -#undef nz - - ArrayCopy(mama_out, m_mama, 0, 0, rates_total); - ArrayCopy(fama_out, m_fama, 0, 0, rates_total); - } - -//+------------------------------------------------------------------+ -//| CMESACalculator: Prepares the source price series. | -//+------------------------------------------------------------------+ -bool CMESACalculator::PreparePriceSeries(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]) - { - switch(price_type) - { - case PRICE_CLOSE: - ArrayCopy(m_price, close, 0, 0, rates_total); - break; - case PRICE_OPEN: - ArrayCopy(m_price, open, 0, 0, rates_total); - break; - case PRICE_HIGH: - ArrayCopy(m_price, high, 0, 0, rates_total); - break; - case PRICE_LOW: - ArrayCopy(m_price, low, 0, 0, rates_total); - break; - case PRICE_MEDIAN: - for(int i=0; iC&IG*W&6ij>+;8Wczr2M_{e`Kz_Tv0Z;84TOIkcyGp= zy*uxvagtUBogCl!c4ubazIi*l`RDH~*^;O7`3hW5(QL`JxDS5q%bt9TPf5<@ zjqJkz^?Qz|EJGQ|m5ik)uca$f_}r0ge0F6M_iuAoh-a1N>l2J&tRv~*dy4TmX+=i1 zCd-a@P4SP}zYzMG0JotG;E&guJj2{=<8N`lHu_Bv9T6WPR^NY3_F<`yYbclab%6PB z;6hs(^LF&;z>lF^q~2Q`4YcOl1Xheg8+d9e65pUlS7WT=yFZV+G>?&dkByHJwBe@( z|5I2POC9%JJQ3mgJjS+0yNr#d%;Xg=L(c)LWqOYkpD7SD#I3hkV8kuFpCN8y@fEPT zlEcie6Zr+dR;31%>R>|y?OW*4zZs?FURS=>xM-PbVA|y5WbU7Fe*qsJZ6`-MC!M86 zL$6K5+J`mckGEIMpV+*R@gvwVD^4nMit+u35guXu-(kGVV9d-R3&(SN#B?kN_;hd$ zma;X`Y$WF_wwj#DPl&3D*lKdD@l}?x$lPedYIkmNM|06U! zM;K`hJ-@^ovdLxoGD6=w9}n|u296LxV|?tdjdma7B;I7=IX)aaFUGSCUD{Ru`TiD< z?`u4^-VceTrVP3)jAc6-jmO3`Fds{7jS<^3J# zn3_Pj4@9YpdF^nRt)~2jxoRo;!F%~ebz++1xu^JQl7MV`wndxQ%G2c+68i zQ?G4R@iS;y;5k-9Ti$aWO2Eo@Gkz1T2e7&cA6)IoGWrbMTo>Z@{@*Y9+{n$=D%Bo#MRgE|gWQ;9$# z8=83>-=8;kR7|Qjm5yA0o5}P9`o?NCme2g1YhVR`%TV<*csoU|RrG!j-Ymlm&pl)Y zGw5pWZx8d9&6gq{uXN@nh|ODM_L)^*HH7HHXt*M=b{k{lHVUpf$B2_L`gQyT^7KH* z!SOspOYg-znB{b}W*%z5jJeKgGKu0)lb4Ff88BkySXCs`{Y-1lm5~XmMz55Ke2P_N z2kc}_{(b{340Eokeq9M`Qh2wxMr_=SDqvTni?*%}fZQd#->$FZRC<}lQ$L@t@5hSf8So;T$gm%PAM1q*T3u`2KPj|SLOaWN&dU9e3K->c z#k0<4o;k%?YhaA5Be-5ri%f~Ks>3S7*T+P4aXsR`A&aJYV|6%%PK_}dW7?r|m~1%& zF07&!`~8*5@FEK}RAgmbRke|~V-|=7)%L%s{!}#PXm&2bI{wfVU^UhMLbHx+r2bb@ z7$liGgUGPnAU{~)vI2>(5f91hCwIu};MF*9br*Ar%HayLJ!sGWfvsdI*Q>|lr$^Ji zSCg%th2&~p7dueAbY<+@8b++M>%eS?5A}32rFq$rr=Mc>c*@nm>CfU$fvUc|U7js* zE?HM{ckE>S=HBZ0>>87fFWjdiP1onN#?wWf89a`)F5=`V<>OehUFPH1;@)eBdG6dZ zHukm?KbrwoC3Va+Phw^|H}{J(ZTI2UJg?U=QsZI+yklfR8PhfUht}h?Z{sIx0)KW_ z2AZtyZFkO$;Rzm3hbFk3=4Kz?Z1D!D_w`kXLbzP+vG z%w1ZBobs)+Ia_YFimKNKkJNXu$`u!Y4%dzs8fN3J=MGc@|>KbMdQ{KZTSB) z?ySi=V_pN#S5PG?DAkUdX - -//--- Plot 1: MAMA Line -#property indicator_label1 "MAMA" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrRed -#property indicator_style1 STYLE_SOLID -#property indicator_width1 2 - -//--- Input Parameters --- -input ENUM_APPLIED_PRICE InpSourcePrice = PRICE_CLOSE; // Source Price -input double InpFastLimit = 0.5; // Fast Limit -input double InpSlowLimit = 0.05; // Slow Limit - -//--- Indicator Buffers --- -double BufferMAMA[]; -double BufferPrice[]; - -//--- Global calculator object --- -CMESACalculator *g_calculator; - -//--- Forward declaration -int PriceSeries(ENUM_APPLIED_PRICE,int,const double&[],const double&[],const double&[],const double&[],double&[]); - -//+------------------------------------------------------------------+ -//| Custom indicator initialization function. | -//+------------------------------------------------------------------+ -int OnInit() - { - SetIndexBuffer(0, BufferMAMA, INDICATOR_DATA); - ArraySetAsSeries(BufferMAMA, false); - - PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 10); - IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("MAMA(%.2f, %.2f)", InpFastLimit, InpSlowLimit)); - - g_calculator = new CMESACalculator(); - if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpFastLimit, InpSlowLimit)) - { - Print("Failed to initialize MESA Calculator."); - return(INIT_FAILED); - } - return(INIT_SUCCEEDED); - } - -//+------------------------------------------------------------------+ -//| Custom indicator deinitialization function. | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) - { - if(CheckPointer(g_calculator) != POINTER_INVALID) - delete g_calculator; - } - -//+------------------------------------------------------------------+ -//| 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(CheckPointer(g_calculator) != POINTER_INVALID) - { - //--- Corrected: Pass all required parameters to the Calculate method - double dummy_fama[]; - g_calculator.Calculate(rates_total, InpSourcePrice, open, high, low, close, BufferMAMA, dummy_fama); - } - return(rates_total); - } - -//+------------------------------------------------------------------+ -//| Helper function to get the selected price series. | -//+------------------------------------------------------------------+ -int PriceSeries(ENUM_APPLIED_PRICE type, int rates_total, const double &open[], const double &high[], const double &low[], const double &close[], double &dest_buffer[]) - { -// This helper is not strictly needed anymore as logic is in the calculator, -// but we keep it for potential future use or consistency. -// The main indicator now passes the raw OHLC to the calculator. - return rates_total; - } -//+------------------------------------------------------------------+ -//+------------------------------------------------------------------+ diff --git a/Indicators/MyIndicators/MAMA_FAMA_Pro.md b/Indicators/MyIndicators/MAMA_FAMA_Pro.md deleted file mode 100644 index 477e1ab..0000000 --- a/Indicators/MyIndicators/MAMA_FAMA_Pro.md +++ /dev/null @@ -1,64 +0,0 @@ -# MESA Adaptive Moving Average (MAMA & FAMA) Professional - -## 1. Summary (Introduction) - -The MESA Adaptive Moving Average (MAMA), developed by John F. Ehlers, is a highly sophisticated, adaptive moving average that dynamically adjusts its speed based on the market's measured cyclicality. It is almost always plotted with its companion line, **FAMA (Following Adaptive Moving Average)**, to provide clear crossover signals. - -Our `MAMA_FAMA_Pro` implementation is a unified, professional indicator that offers a choice between two distinct, popular algorithms: - -1. **Ehlers Official:** The original, complex algorithm based on the Hilbert Transform for precise cycle measurement. -2. **LazyBear Simple:** A simplified, highly responsive version popularized on platforms like TradingView. - -Both algorithms can be calculated using either **standard** or **Heikin Ashi** price data, providing maximum flexibility in a single tool. - -## 2. Mathematical Foundations and Calculation Logic - -The MAMA algorithm translates price movements into wave-like components to measure their cyclical properties and adapt its smoothing factor (`alpha`) accordingly. - -### Required Components - -* **Source Price:** The price series used for calculation. -* **Fast Limit (`alpha_fast`):** The maximum allowable value for `alpha`. -* **Slow Limit (`alpha_slow`):** The minimum allowable value for `alpha`. - -### Calculation Steps (Algorithm) - -1. **Price Pre-processing:** The source price is first lightly smoothed. -2. **Cycle Measurement:** The algorithm analyzes the price wave to measure its cyclical properties. - * The **Ehlers Official** version uses a full Hilbert Transform to decompose the price into In-Phase (I) and Quadrature (Q) components to precisely measure the dominant cycle period. - * The **LazyBear Simple** version uses a simplified approximation of this process. -3. **Adaptive Alpha Calculation:** The rate of change of the phase angle is used to calculate a dynamic `alpha`, constrained by the `Fast Limit` and `Slow Limit`. A rapid phase change (trending market) results in a larger `alpha` (faster average). -4. **Final MAMA and FAMA Calculation:** - * $\text{MAMA}_i = \alpha_i \cdot \text{Price}_i + (1 - \alpha_i) \cdot \text{MAMA}_{i-1}$ - * $\text{FAMA}_i = (\alpha_i/2) \cdot \text{MAMA}_i + (1 - \alpha_i/2) \cdot \text{FAMA}_{i-1}$ - -## 3. MQL5 Implementation Details - -Our MQL5 implementation is built upon a clean, robust, and reusable object-oriented framework. - -* **Modular Engine Architecture (`MAMA_Engines.mqh`):** - The entire logic is encapsulated within a single, powerful include file. This file contains an abstract base class (`CMAMACalculatorBase`) and two separate, concrete engine classes that inherit from it: `CMAMA_Ehlers_Engine` and `CMAMA_LazyBear_Engine`. This ensures both algorithms are available through a common interface but are maintained as distinct, definition-true implementations. - -* **Object-Oriented Inheritance for HA:** Each engine class has a corresponding `_HA` child class that inherits all the complex logic and only overrides the initial data preparation step to use smoothed Heikin Ashi prices. This eliminates code duplication and ensures all four variations (Ehlers Std, Ehlers HA, LB Std, LB HA) are robust and consistent. - -* **Stability via Full Recalculation:** MAMA is a highly recursive and state-dependent indicator. To ensure perfect accuracy and prevent calculation errors, our implementation employs a "brute-force" **full recalculation** on every tick. - -## 4. Parameters - -* **Algorithm (`InpAlgorithm`):** Allows the user to select between the two calculation methods: - * `ALGO_EHLERS_OFFICIAL`: The complex, original algorithm. - * `ALGO_LAZYBEAR_SIMPLE`: The simplified, more responsive version. -* **Source Price (`InpSourcePrice`):** The price data used for the calculation. This unified dropdown menu allows you to select from all standard and Heikin Ashi price types. -* **Fast Limit (`InpFastLimit`):** Sets the upper bound for the adaptive smoothing constant `alpha`. Default is `0.5`. -* **Slow Limit (`InpSlowLimit`):** Sets the lower bound for `alpha`. Default is `0.05`. - -## 5. Usage and Interpretation - -* **Crossover Signals:** The primary use is for generating trading signals based on the crossover of the two lines. - * A **Buy Signal** is generated when MAMA (fast line, red) crosses **above** FAMA (slow line, green). - * A **Sell Signal** is generated when MAMA crosses **below** FAMA. -* **Trend Identification:** When MAMA is above FAMA, the trend is considered bullish. When MAMA is below FAMA, the trend is considered bearish. -* **Choosing an Algorithm:** - * **Ehlers Official:** Tends to be smoother and more robust in its cycle analysis. It may produce fewer signals but can be more reliable in filtering out noise. - * **LazyBear Simple:** Tends to be faster and more responsive to immediate price changes. It may produce more signals, which can be beneficial in fast-moving markets but may also lead to more whipsaws. -* **Heikin Ashi Variant:** Using a Heikin Ashi price source results in even smoother MAMA/FAMA lines and can help to filter out additional market noise, potentially leading to fewer, but higher-quality, crossover signals. diff --git a/Indicators/MyIndicators/MAMA_FAMA_Pro.mq5 b/Indicators/MyIndicators/MAMA_FAMA_Pro.mq5 deleted file mode 100644 index 4223518..0000000 --- a/Indicators/MyIndicators/MAMA_FAMA_Pro.mq5 +++ /dev/null @@ -1,124 +0,0 @@ -//+------------------------------------------------------------------+ -//| MAMA_FAMA_Pro.mq5 | -//| Copyright 2025, xxxxxxxx| -//+------------------------------------------------------------------+ -#property copyright "Copyright 2025, xxxxxxxx" -#property version "4.00" -#property description "Definition-true MESA Adaptive Moving Average (MAMA) and FAMA by John Ehlers." -#property description "Supports Standard and Heikin Ashi price sources." - -#property indicator_chart_window -#property indicator_buffers 2 // MAMA and FAMA -#property indicator_plots 2 - -//--- Include the calculator engine --- -#include - -//--- Plot 1: MAMA Line -#property indicator_label1 "MAMA" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrRed -#property indicator_style1 STYLE_SOLID -#property indicator_width1 1 - -//--- Plot 2: FAMA Line -#property indicator_label2 "FAMA" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrGreen -#property indicator_style2 STYLE_SOLID -#property indicator_width2 1 - -//--- Custom Enum for Price Source, including Heikin Ashi --- -enum ENUM_APPLIED_PRICE_HA_ALL - { -//--- Heikin Ashi Prices (negative values for easy identification) - PRICE_HA_CLOSE = -1, - PRICE_HA_OPEN = -2, - PRICE_HA_HIGH = -3, - PRICE_HA_LOW = -4, - PRICE_HA_MEDIAN = -5, - PRICE_HA_TYPICAL = -6, - PRICE_HA_WEIGHTED = -7, -//--- Standard Prices (using built-in ENUM_APPLIED_PRICE values) - PRICE_CLOSE_STD = PRICE_CLOSE, - PRICE_OPEN_STD = PRICE_OPEN, - PRICE_HIGH_STD = PRICE_HIGH, - PRICE_LOW_STD = PRICE_LOW, - PRICE_MEDIAN_STD = PRICE_MEDIAN, - PRICE_TYPICAL_STD = PRICE_TYPICAL, - PRICE_WEIGHTED_STD= PRICE_WEIGHTED - }; - -//--- Input Parameters --- -input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; // Source Price -input double InpFastLimit = 0.5; // Fast Limit -input double InpSlowLimit = 0.05; // Slow Limit - -//--- Indicator Buffers --- -double BufferMAMA[]; -double BufferFAMA[]; - -//--- Global calculator object (as a base class pointer) --- -CMAMACalculator *g_calculator; - -//+------------------------------------------------------------------+ -//| Custom indicator initialization function. | -//+------------------------------------------------------------------+ -int OnInit() - { - SetIndexBuffer(0, BufferMAMA, INDICATOR_DATA); - SetIndexBuffer(1, BufferFAMA, INDICATOR_DATA); - ArraySetAsSeries(BufferMAMA, false); - ArraySetAsSeries(BufferFAMA, false); - - PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 10); - PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 10); - - if(InpSourcePrice <= PRICE_HA_CLOSE) - { - g_calculator = new CMAMACalculator_HA(); - IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("MAMA/FAMA HA(%.2f,%.2f)", InpFastLimit, InpSlowLimit)); - } - else - { - g_calculator = new CMAMACalculator(); - IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("MAMA/FAMA(%.2f,%.2f)", InpFastLimit, InpSlowLimit)); - } - - if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpFastLimit, InpSlowLimit)) - { - Print("Failed to initialize MAMA Calculator."); - return(INIT_FAILED); - } - return(INIT_SUCCEEDED); - } - -//+------------------------------------------------------------------+ -//| Custom indicator deinitialization function. | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) - { - if(CheckPointer(g_calculator) != POINTER_INVALID) - delete g_calculator; - } - -//+------------------------------------------------------------------+ -//| Custom indicator iteration function. | -//+------------------------------------------------------------------+ -int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[]) - { - if(CheckPointer(g_calculator) == POINTER_INVALID) - return 0; - - ENUM_APPLIED_PRICE price_type; - if(InpSourcePrice <= PRICE_HA_CLOSE) - price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); - else - price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; - - g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferMAMA, BufferFAMA); - - return(rates_total); - } -//+------------------------------------------------------------------+ -//+------------------------------------------------------------------+