diff --git a/Indicators/MyIndicators/CutlerRSI_Pro.mq5 b/Indicators/MyIndicators/CutlerRSI_Pro.mq5 index a607342..3ff2c27 100644 --- a/Indicators/MyIndicators/CutlerRSI_Pro.mq5 +++ b/Indicators/MyIndicators/CutlerRSI_Pro.mq5 @@ -1,11 +1,9 @@ //+------------------------------------------------------------------+ //| CutlerRSI_Pro.mq5| //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property link "" -#property version "3.02" // Added selectable display mode for signal line +#property version "3.10" // Refactored to use MovingAverage_Engine #property description "Professional Cutler's RSI (SMA-based) with an optional signal line and" #property description "selectable price source (Standard and Heikin Ashi)." @@ -51,46 +49,41 @@ input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; input group "Signal Line Settings" input ENUM_DISPLAY_MODE InpDisplayMode = DISPLAY_RSI_AND_SIGNAL; input int InpPeriodMA = 14; -input ENUM_MA_METHOD InpMethodMA = MODE_SMA; +// UPDATED: Use ENUM_MA_TYPE +input ENUM_MA_TYPE InpMethodMA = SMA; //--- Indicator Buffers --- double BufferCutlerRSI[]; double BufferSignalMA[]; -//--- Global calculator object (as a base class pointer) --- +//--- Global calculator object --- CCutlerRSICalculator *g_calculator; -//+------------------------------------------------------------------+ -//| Custom indicator initialization function. | //+------------------------------------------------------------------+ int OnInit() { -//--- Map the buffers and set as non-timeseries SetIndexBuffer(0, BufferCutlerRSI, INDICATOR_DATA); SetIndexBuffer(1, BufferSignalMA, INDICATOR_DATA); ArraySetAsSeries(BufferCutlerRSI, false); ArraySetAsSeries(BufferSignalMA, false); -//--- Dynamically create the appropriate calculator instance - if(InpSourcePrice <= PRICE_HA_CLOSE) // Heikin Ashi source selected + if(InpSourcePrice <= PRICE_HA_CLOSE) { g_calculator = new CCutlerRSICalculator_HA(); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("CutlerRSI HA(%d,%d)", InpPeriodRSI, InpPeriodMA)); } - else // Standard price source selected + else { - g_calculator = new CCutlerRSICalculator_Std(); + g_calculator = new CCutlerRSICalculator(); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("CutlerRSI(%d,%d)", InpPeriodRSI, InpPeriodMA)); } -//--- Check if creation was successful and initialize if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriodRSI, InpPeriodMA, InpMethodMA)) { Print("Failed to create or initialize CutlerRSI Calculator object."); return(INIT_FAILED); } -//--- Set indicator display properties IndicatorSetInteger(INDICATOR_DIGITS, 2); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriodRSI); PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, InpPeriodRSI + InpPeriodMA - 1); @@ -98,18 +91,13 @@ int OnInit() return(INIT_SUCCEEDED); } -//+------------------------------------------------------------------+ -//| Custom indicator deinitialization function. | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { -//--- Free the calculator object to prevent memory leaks if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; } -//+------------------------------------------------------------------+ -//| Custom indicator calculation function. | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, @@ -122,30 +110,24 @@ int OnCalculate(const int rates_total, const long &volume[], const int &spread[]) { -//--- Ensure the calculator object is valid if(CheckPointer(g_calculator) == POINTER_INVALID) return 0; -//--- Convert our custom enum to the standard ENUM_APPLIED_PRICE ENUM_APPLIED_PRICE price_type; if(InpSourcePrice <= PRICE_HA_CLOSE) price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); else price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; -//--- Delegate the entire calculation to our calculator object - g_calculator.Calculate(rates_total, open, high, low, close, price_type, BufferCutlerRSI, BufferSignalMA); + g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferCutlerRSI, BufferSignalMA); -//--- Hide signal line buffer if not needed if(InpDisplayMode == DISPLAY_RSI_ONLY) { - for(int i = 0; i < rates_total; i++) - { + int start = (prev_calculated > 0) ? prev_calculated - 1 : 0; + for(int i = start; i < rates_total; i++) BufferSignalMA[i] = EMPTY_VALUE; - } } -//--- Return rates_total for a full recalculation, ensuring stability return(rates_total); } //+------------------------------------------------------------------+