From e45e31c029f8ab23e92928a0063d09278520fc28 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Mon, 25 Aug 2025 19:28:49 +0200 Subject: [PATCH] new files added --- Indicators/MyIndicators/AD.mq5 | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Indicators/MyIndicators/AD.mq5 diff --git a/Indicators/MyIndicators/AD.mq5 b/Indicators/MyIndicators/AD.mq5 new file mode 100644 index 0000000..06cd9e8 --- /dev/null +++ b/Indicators/MyIndicators/AD.mq5 @@ -0,0 +1,79 @@ +//+------------------------------------------------------------------+ +//| AD.mq5 | +//| Copyright 2025, xxxxxxxx | +//| | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, xxxxxxxx" +#property link "" +#property version "1.01" // Corrected volume source handling +#property description "Accumulation/Distribution Line" + +//--- Indicator Window and Plot Properties --- +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_plots 1 +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLightSeaGreen +#property indicator_label1 "A/D" + +//--- Input Parameters --- +input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; // Volume type + +//--- Indicator Buffers --- +double BufferAD[]; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function. | +//+------------------------------------------------------------------+ +void OnInit() + { + SetIndexBuffer(0, BufferAD, INDICATOR_DATA); + ArraySetAsSeries(BufferAD, false); + + IndicatorSetInteger(INDICATOR_DIGITS, 0); + IndicatorSetString(INDICATOR_SHORTNAME, "A/D"); + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 1); + } + +//+------------------------------------------------------------------+ +//| Accumulation/Distribution calculation 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 < 2) + return(0); + +//--- Main calculation loop + for(int i = 0; i < rates_total; i++) + { + double mfm = 0; // Money Flow Multiplier + double range = high[i] - low[i]; + + if(range > 0) + { + mfm = ((close[i] - low[i]) - (high[i] - close[i])) / range; + } + + // --- FIX: Use ternary operator to select volume source --- + long current_volume = (InpVolumeType == VOLUME_TICK) ? tick_volume[i] : volume[i]; + double mfv = mfm * current_volume; // Money Flow Volume + + if(i > 0) + BufferAD[i] = BufferAD[i-1] + mfv; + else + BufferAD[i] = mfv; // First value + } + + return(rates_total); + } +//+------------------------------------------------------------------+ +//+------------------------------------------------------------------+