From 1b93b469a1db14760d2fd062ed018f02458f4636 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 29 Mar 2025 04:11:38 +0330 Subject: [PATCH] last ... --- Documents/BKP/cumulative-delta.1.pine | 75 ++ Documents/BKP/cumulative-delta.pine | 37 + Documents/BKP/x-saherelm.x121.xcdv.mq5 | 573 ++++++++++++ Helpers/x-saherelm.x121.helper.mq5 | 459 +++++++++- Helpers/x-saherelm.x121.xdelta.helper.mq5 | 780 ++++++++++++++++ Helpers/x-saherelm.x121.xmas.helper.mq5 | 2 - Helpers/x-saherelm.x121.xvolume.helper.mq5 | 865 ++++++++++++++++++ ...x-delta.mq5 => x-saherelm.x121.xdelta.mq5} | 35 +- ...volume.mq5 => x-saherelm.x121.xvolume.mq5} | 0 9 files changed, 2811 insertions(+), 15 deletions(-) create mode 100644 Documents/BKP/cumulative-delta.1.pine create mode 100644 Documents/BKP/cumulative-delta.pine create mode 100644 Documents/BKP/x-saherelm.x121.xcdv.mq5 create mode 100644 Helpers/x-saherelm.x121.xdelta.helper.mq5 create mode 100644 Helpers/x-saherelm.x121.xvolume.helper.mq5 rename Indicators/{x-saherelm.x121.x-delta.mq5 => x-saherelm.x121.xdelta.mq5} (95%) rename Indicators/{x-saherelm.x121.x-volume.mq5 => x-saherelm.x121.xvolume.mq5} (100%) diff --git a/Documents/BKP/cumulative-delta.1.pine b/Documents/BKP/cumulative-delta.1.pine new file mode 100644 index 00000000..5ced2ed8 --- /dev/null +++ b/Documents/BKP/cumulative-delta.1.pine @@ -0,0 +1,75 @@ +// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ +// © LonesomeTheBlue + +//@version=4 +study("Cumulative Delta Volume", "CDV") +linestyle = input(defval = 'Candle', title = "Style", options = ['Candle', 'Line']) +hacandle = input(defval = true, title = "Heikin Ashi Candles?") +showma1 = input(defval = false, title = "SMA 1", inline = "ma1") +ma1len = input(defval = 50, title = "", minval = 1, inline = "ma1") +ma1col = input(defval = color.lime, title = "", inline = "ma1") +showma2 = input(defval = false, title = "SMA 2", inline = "ma2") +ma2len = input(defval = 200, title = "", minval = 1, inline = "ma2") +ma2col = input(defval = color.red, title = "", inline = "ma2") +showema1 = input(defval = false, title = "EMA 1", inline = "ema1") +ema1len = input(defval = 50, title = "", minval = 1, inline = "ema1") +ema1col = input(defval = color.lime, title = "", inline = "ema1") +showema2 = input(defval = false, title = "EMA 2", inline = "ema2") +ema2len = input(defval = 200, title = "", minval = 1, inline = "ema2") +ema2col = input(defval = color.red, title = "", inline = "ema2") +colorup = input(defval = color.lime, title = "Body", inline = "bcol") +colordown = input(defval = color.red, title = "", inline = "bcol") +bcolup = input(defval = #74e05e, title = "Border", inline = "bocol") +bcoldown = input(defval = #ffad7d, title = "", inline = "bocol") +wcolup = input(defval = #b5b5b8, title = "Wicks", inline = "wcol") +wcoldown = input(defval = #b5b5b8, title = "", inline = "wcol") + +tw = high - max(open, close) +bw = min(open, close) - low +body = abs(close - open) + +_rate(cond) => + ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body) + ret := nz(ret) == 0 ? 0.5 : ret + ret + +deltaup = volume * _rate(open <= close) +deltadown = volume * _rate(open > close) +delta = close >= open ? deltaup : -deltadown +cumdelta = cum(delta) +float ctl = na +float o = na +float h = na +float l = na +float c = na +if linestyle == 'Candle' + o := cumdelta[1] + h := max(cumdelta, cumdelta[1]) + l := min(cumdelta, cumdelta[1]) + c := cumdelta + ctl +else + ctl := cumdelta + +plot(ctl, title = "CDV Line", color = color.blue, linewidth = 2) + +float haclose = na +float haopen = na +float hahigh = na +float halow = na +haclose := (o + h + l + c) / 4 +haopen := na(haopen[1]) ? (o + c) / 2 : (haopen[1] + haclose[1]) / 2 +hahigh := max(h, max(haopen, haclose)) +halow := min(l, min(haopen, haclose)) + +c_ = hacandle ? haclose : c +o_ = hacandle ? haopen : o +h_ = hacandle ? hahigh : h +l_ = hacandle ? halow : l + +plotcandle(o_, h_, l_, c_, title='CDV Candles', color = o_ <= c_ ? colorup : colordown, bordercolor = o_ <= c_ ? bcolup : bcoldown, wickcolor = o_ <= c_ ? bcolup : bcoldown) + +plot(showma1 and linestyle == "Candle" ? sma(c_, ma1len) : na, title = "SMA 1", color = ma1col) +plot(showma2 and linestyle == "Candle" ? sma(c_, ma2len) : na, title = "SMA 2", color = ma2col) +plot(showema1 and linestyle == "Candle" ? ema(c_, ema1len) : na, title = "EMA 1", color = ema1col) +plot(showema2 and linestyle == "Candle" ? ema(c_, ema2len) : na, title = "EMA 2", color = ema2col) diff --git a/Documents/BKP/cumulative-delta.pine b/Documents/BKP/cumulative-delta.pine new file mode 100644 index 00000000..cc9afc0c --- /dev/null +++ b/Documents/BKP/cumulative-delta.pine @@ -0,0 +1,37 @@ +// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ +// © Ankit_1618 + +//@version=4 +study("Cumulative Volume Delta") + +upper_wick = close>open ? high-close : high-open +lower_wick = close>open ? open-low : close-low +spread = high-low +body_length = spread - (upper_wick + lower_wick) + +percent_upper_wick = upper_wick/spread +percent_lower_wick = lower_wick/spread +percent_body_length = body_length/spread + + +buying_volume = close>open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume +selling_volume = close cumulative_selling_volume ? color.green : cumulative_buying_volume < cumulative_selling_volume ? color.red : color.yellow + +pb = plot(cumulative_buying_volume, color=color.green , transp=70) +ps = plot(cumulative_selling_volume, color=color.red , transp=70) + +fill(pb, ps, color = fill_color) + +volume_strength_wave = cumulative_buying_volume > cumulative_selling_volume ? cumulative_buying_volume : cumulative_selling_volume +ema_volume_strength_wave = ema(volume_strength_wave , cumulation_length) +plot(ema_volume_strength_wave, color=color.gray, transp=80) + +cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume +plot(cumulative_volume_delta, color= cumulative_volume_delta>0 ? color.green : color.red, style=plot.style_columns, transp=61) + diff --git a/Documents/BKP/x-saherelm.x121.xcdv.mq5 b/Documents/BKP/x-saherelm.x121.xcdv.mq5 new file mode 100644 index 00000000..ce81dda4 --- /dev/null +++ b/Documents/BKP/x-saherelm.x121.xcdv.mq5 @@ -0,0 +1,573 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Ocillator +// ------------------------------------------------- +// Name: X121 XCDV +// Description: Detect Comulative Delta Volume ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm X121 XCDV Ocillator" +#property strict + +// +// Definitions ... + +// +#define ShortName "X121_XCDV" + +// +// Imports ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Makret ... +input group "Market"; +input int maLength = 14; // Moving Averge Length +input ENUM_X_PRICE maAppliedTo = X_PRICE_CLOSE; // Moving Averge Applied To +input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method + +// +// Presentation ... +input group "Presentation"; +input int startCalculationForLastBars = 1000; // Calculate Last n Bars +input bool showCDV = true; // Show Delta Line +input bool showMA = true; // Show Delta Histogram + +// +// Buffers Props ... + +// +#property indicator_separate_window + +// +#property indicator_buffers 10 +#property indicator_plots 2 + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +// Buffers ... + +// +#define openBufferIndex 0 +double openBuffer[]; + +// +#define highBufferIndex 1 +double highBuffer[]; + +// +#define lowBufferIndex 2 +double lowBuffer[]; + +// +#define closeBufferIndex 3 +double closeBuffer[]; + +// +#define colorBufferIndex 4 +double colorBuffer[]; + +// +#define barBufferIndex 0 +#property indicator_label1 "X121 XCDV Open;X121 XCDV High;X121 XCDV Low;X121 XCDV Close" +#property indicator_type1 DRAW_COLOR_CANDLES +#property indicator_color1 CLR_NONE, clrLime, clrRed + +// +#define maBufferIndex 5 +double maBuffer[]; + +#property indicator_label2 "MA" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrYellow +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Data Buffers ... + +#define mLastBufferIndex 5 + +#define priceBufferIndex mLastBufferIndex + 1 +double priceBuffer[]; + +#define deltaBufferIndex mLastBufferIndex + 2 +double deltaBuffer[]; + +#define cumulativeDeltaBufferIndex mLastBufferIndex + 3 +double cumulativeDeltaBuffer[]; + +// +// Variables, Properties and etc ... + +// +// this counts Available Bars ... +int limit; + +// +int maxLength; + +// +double lastCDV = 0.0; + +// +// Event Handlers ... + +/** + * Initialize Indicator ... + * + * @return ( int ) + */ +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Initialize Indicator Handlers ... + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + IndicatorSetInteger(INDICATOR_DIGITS, 2); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +/** + * De Initialize Indicator ... + * + * @param reason: Integer, De Initialization Reason ... + */ +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +/** + * Calculate Bars ... + * + * @param rates_total: Integer, Total Bars on Chart ... + * @param prev_calculated: Integer, Total Calculated Bars on Charts ... + * @param time: DateTime Array, History of Open Time ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param low: Double Array, History of Low Prices ... + * @param close: Double Array, History of Close Prices ... + * @param tick_volume: Long, History of Tick Volumes on Bar ... + * @param volume: Long, History of Trade Volumes ... + * @param spread: Double, History of Spread Price ... + * + * @return ( int ) + */ +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[] // +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +/** + * Validate Input Args for Initialization ... + * + * @return ( bool ) + */ +bool ValidateInputs() +{ + // + bool result = false; + + // + result = maLength > 0 && + IsValid(maMethod) && + IsValid(maAppliedTo); + + // + return result; +} + +/** + * Extract Max Length of Inputs ... + * + * @return ( int ) + */ +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(0, maLength); + + // + return result; +} + +/** + * Set Indicator Short Name and also we can define Buffers Labels ... + */ +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +/** + * Define Required Buffers ... + */ +void DefineBuffers() +{ + // + // Plot Buffers ... + + // + // CDV ... + + // + // Raw Candles Color ... + ArraySetAsSeries(colorBuffer, true); + SetIndexBuffer(colorBufferIndex, colorBuffer, INDICATOR_COLOR_INDEX); + + // + ENUM_DRAW_TYPE barDrawType = showCDV ? DRAW_COLOR_CANDLES : DRAW_NONE; + + // + // Set EMPTY_VALUE on Candles Buffer ... + PlotIndexSetDouble(barBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(barBufferIndex, PLOT_SHOW_DATA, showCDV); + PlotIndexSetInteger(barBufferIndex, PLOT_DRAW_TYPE, barDrawType); + + // + // Open ... + ArraySetAsSeries(openBuffer, true); + SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(highBuffer, true); + SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(closeBuffer, true); + SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(lowBuffer, true); + SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA); + + // + // Ma ... + ENUM_DRAW_TYPE maDrawType = showMA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(maBuffer, true); + SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA); + PlotIndexSetDouble(maBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showMA); + PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, maDrawType); + + // + // Data Buffers ... + + // + ArraySetAsSeries(priceBuffer, true); + SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(deltaBuffer, true); + SetIndexBuffer(deltaBufferIndex, deltaBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(cumulativeDeltaBuffer, true); + SetIndexBuffer(cumulativeDeltaBufferIndex, cumulativeDeltaBuffer, INDICATOR_CALCULATIONS); +} + +/** + * Calculate Custom Buffers ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int barsLimit = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : 0; + // + // bool canCalculate = true; + bool canCalculate = + barsLimit == 0 || + bar_index <= barsLimit; + if (canCalculate) + { + // + CalculateValues( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + } + else + { + FillBuffersZero(bar_index); + } +} + +/** + * Fill All Bufers to Zero Vlue for Specified Bar Index ... + * + * @param barIndex: Integer ... + */ +void FillBuffersZero(int barIndex) +{ + // + openBuffer[barIndex] = 0.0; + highBuffer[barIndex] = 0.0; + closeBuffer[barIndex] = 0.0; + lowBuffer[barIndex] = 0.0; + colorBuffer[barIndex] = hideColorIDX; +} + +/** + * Calculate Vales ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateValues( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + XOHCL bar; + bool has = bar.Init( + _Symbol, + _Period, + bar_index // + ); + if (!has) + { + return; + } + + // + double lowShadow = bar.GetLowShadow(); + double highShadow = bar.GetHighShadow(); + double body = bar.GetBody(); + bool isBullish = bar.IsBullish(); + bool hasDir = HasDirection(bar.GetDirection()); + + // + double iRate = 0.5 * (highShadow + lowShadow + (hasDir ? 2 * body : 0)) / (highShadow + lowShadow + body); + iRate = iRate <= 0 + ? 0.5 + : iRate; + + // + double iVRate = tickVolume[bar_index] * iRate; + double iDelta = isBullish + ? iVRate + : -1 * iVRate; + deltaBuffer[bar_index] = iDelta; + + // + double iCumulate = lastCDV + iDelta; + cumulativeDeltaBuffer[bar_index] = iCumulate; + lastCDV = iCumulate; + + // + bool isFirstBar = + startCalculationForLastBars > 0 + ? bar_index == startCalculationForLastBars + : bar_index == ratesTotal; + + // + double iO = 0; + double iH = 0; + double iL = 0; + double iC = 0; + if (!isFirstBar) + { + // + iO = cumulativeDeltaBuffer[bar_index + 1]; + iH = MathMax(cumulativeDeltaBuffer[bar_index], cumulativeDeltaBuffer[bar_index + 1]); + iL = MathMin(cumulativeDeltaBuffer[bar_index], cumulativeDeltaBuffer[bar_index + 1]); + iC = iCumulate; + } + + // + double iClose = (iO + iH + iL + iC) / 4; + double iOpen = isFirstBar + ? (iO + iC) / 2 + : (openBuffer[bar_index + 1] + closeBuffer[bar_index + 1]) / 2; + double iLow = MathMin(iL, MathMin(iOpen, iClose)); + double iHigh = MathMax(iH, MathMax(iOpen, iClose)); + + // + lowBuffer[bar_index] = iLow; + openBuffer[bar_index] = iOpen; + highBuffer[bar_index] = iHigh; + closeBuffer[bar_index] = iClose; + + // + bool isCBullish = iOpen <= iClose; + double iColor = isCBullish + ? bullishColorIDX + : bearishColorIDX; + colorBuffer[bar_index] = iColor; + + // + double iPrice = GetAppliedPrice( + maAppliedTo, + openBuffer, + highBuffer, + lowBuffer, + closeBuffer, + bar_index // + ); + priceBuffer[bar_index] = iPrice; + + // + // Calculate Moving Averages ... + int deltaMAsCount = iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + maLength, + priceBuffer, + maBuffer, + maMethod // + ); + + // + bar.Clean(); +} + +// diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 4cccdc0a..05b42a93 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -26,12 +26,14 @@ #include "../Helpers/x-saherelm.x121.xatr.helper.mq5" #include "../Helpers/x-saherelm.x121.xcc.helper.mq5" #include "../Helpers/x-saherelm.x121.xche.helper.mq5" +#include "../Helpers/x-saherelm.x121.xdelta.helper.mq5" #include "../Helpers/x-saherelm.x121.xdon.helper.mq5" #include "../Helpers/x-saherelm.x121.xhk.helper.mq5" #include "../Helpers/x-saherelm.x121.xich.helper.mq5" #include "../Helpers/x-saherelm.x121.xmas.helper.mq5" #include "../Helpers/x-saherelm.x121.xpv.helper.mq5" #include "../Helpers/x-saherelm.x121.xstr.helper.mq5" +#include "../Helpers/x-saherelm.x121.xvolume.helper.mq5" #include "../Helpers/x-saherelm.x121.xvwap.helper.mq5" // @@ -52,6 +54,8 @@ struct X121Inputs X121XDONInputs xdonInputs; X121X3MAInputs x3maInputs; X121XVWAPInputs xvwapInputs; + X121XDELTAInputs xdeltaInputs; + X121XVOLUMEInputs xvolumeInputs; // // Constructor ... @@ -79,6 +83,8 @@ struct X121Inputs xcheInputs.Clean(); xdonInputs.Clean(); xvwapInputs.Clean(); + xdeltaInputs.Clean(); + xvolumeInputs.Clean(); // ZeroMemory(this); @@ -101,6 +107,8 @@ struct X121Inputs xdonInputs.Default(); x3maInputs.Default(); xvwapInputs.Default(); + xdeltaInputs.Default(); + xvolumeInputs.Default(); } /** @@ -125,7 +133,9 @@ struct X121Inputs xstrInputs.IsValid() && xcheInputs.IsValid() && xdonInputs.IsValid() && - xvwapInputs.IsValid() + xvwapInputs.IsValid() && + xdeltaInputs.IsValid() && + xvolumeInputs.IsValid() // ; @@ -153,6 +163,8 @@ struct X121Inputs int xdonMax = xdonInputs.Max(); int xichMax = xichInputs.Max(); int xvwapMax = xvwapInputs.Max(); + int xdeltaMax = xdeltaInputs.Max(); + int xvolumeMax = xvolumeInputs.Max(); // result = MathMax(xpvMax, xhkMax); @@ -163,6 +175,8 @@ struct X121Inputs result = MathMax(result, xdonMax); result = MathMax(result, xichMax); result = MathMax(result, xvwapMax); + result = MathMax(result, xdeltaMax); + result = MathMax(result, xvolumeMax); // return result; @@ -209,7 +223,9 @@ struct X121Conditions double valesBuffer[]; double strUpBuffer[]; double downTBuffer[]; + double deltaBuffer[]; double masMidBuffer[]; + double deltaMaBuffer[]; double strDownBuffer[]; double vwapMidBuffer[]; double upTrendBuffer[]; @@ -237,6 +253,7 @@ struct X121Conditions double xhkRawLowBuffer[]; double xhkSMOpenBuffer[]; double xhkSMHighBuffer[]; + double deltaStateBuffer[]; double xhkRawOpenBuffer[]; double xhkRawHighBuffer[]; double xhkSMCloseBuffer[]; @@ -258,6 +275,8 @@ struct X121Conditions double donHighUpperBuffer[]; double donHighLowerBuffer[]; double x3maMidStateBuffer[]; + double bullishVolumeBuffer[]; + double bearishVolumeBuffer[]; double fractalsUpperBuffer[]; double fractalsLowerBuffer[]; double vwapFastStateBuffer[]; @@ -266,6 +285,8 @@ struct X121Conditions double donCloseLowerBuffer[]; double x3maFastStateBuffer[]; double x3maSlowStateBuffer[]; + double bullishVolumeMaBuffer[]; + double bearishVolumeMaBuffer[]; // double rsiSlope; @@ -575,12 +596,14 @@ struct X121Conditions Clean(valesBuffer); Clean(strUpBuffer); Clean(downTBuffer); + Clean(deltaBuffer); Clean(volumeBuffer); Clean(masMidBuffer); Clean(strDownBuffer); Clean(vwapMidBuffer); Clean(upTrendBuffer); Clean(x3maMidBuffer); + Clean(deltaMaBuffer); Clean(masUpperBuffer); Clean(masLowerBuffer); Clean(le1StartBuffer); @@ -609,6 +632,7 @@ struct X121Conditions Clean(xhkRawHighBuffer); Clean(xhkSMCloseBuffer); Clean(vwapVolumeBuffer); + Clean(deltaStateBuffer); Clean(senkouSpanABuffer); Clean(senkouSpanBBuffer); Clean(peaksGoldenBuffer); @@ -625,6 +649,8 @@ struct X121Conditions Clean(donHighUpperBuffer); Clean(donHighLowerBuffer); Clean(x3maMidStateBuffer); + Clean(bullishVolumeBuffer); + Clean(bearishVolumeBuffer); Clean(fractalsUpperBuffer); Clean(fractalsLowerBuffer); Clean(vwapFastStateBuffer); @@ -633,6 +659,9 @@ struct X121Conditions Clean(donCloseLowerBuffer); Clean(x3maFastStateBuffer); Clean(x3maSlowStateBuffer); + Clean(bullishVolumeMaBuffer); + Clean(bearishVolumeMaBuffer); + // ArraySetAsSeries(maBuffer, true); ArraySetAsSeries(rsiBuffer, true); @@ -661,8 +690,10 @@ struct X121Conditions ArraySetAsSeries(valesBuffer, true); ArraySetAsSeries(strUpBuffer, true); ArraySetAsSeries(downTBuffer, true); + ArraySetAsSeries(deltaBuffer, true); ArraySetAsSeries(volumeBuffer, true); ArraySetAsSeries(masMidBuffer, true); + ArraySetAsSeries(deltaMaBuffer, true); ArraySetAsSeries(strDownBuffer, true); ArraySetAsSeries(vwapMidBuffer, true); ArraySetAsSeries(upTrendBuffer, true); @@ -690,6 +721,7 @@ struct X121Conditions ArraySetAsSeries(xhkRawLowBuffer, true); ArraySetAsSeries(xhkSMOpenBuffer, true); ArraySetAsSeries(xhkSMHighBuffer, true); + ArraySetAsSeries(deltaStateBuffer, true); ArraySetAsSeries(chikouSpanBuffer, true); ArraySetAsSeries(xhkRawOpenBuffer, true); ArraySetAsSeries(xhkRawHighBuffer, true); @@ -711,6 +743,8 @@ struct X121Conditions ArraySetAsSeries(donHighUpperBuffer, true); ArraySetAsSeries(donHighLowerBuffer, true); ArraySetAsSeries(x3maMidStateBuffer, true); + ArraySetAsSeries(bullishVolumeBuffer, true); + ArraySetAsSeries(bearishVolumeBuffer, true); ArraySetAsSeries(fractalsUpperBuffer, true); ArraySetAsSeries(fractalsLowerBuffer, true); ArraySetAsSeries(vwapFastStateBuffer, true); @@ -719,6 +753,8 @@ struct X121Conditions ArraySetAsSeries(donCloseLowerBuffer, true); ArraySetAsSeries(x3maFastStateBuffer, true); ArraySetAsSeries(x3maSlowStateBuffer, true); + ArraySetAsSeries(bullishVolumeMaBuffer, true); + ArraySetAsSeries(bearishVolumeMaBuffer, true); // cheMin = 0; @@ -2132,6 +2168,8 @@ class XCX121Helper : public XCBase XCX121XDONHelper *xdonHelper; XCX121X3MAHelper *x3maHelper; XCX121XVWAPHelper *xvwapHelper; + XCX121XDELTAHelper *xdeltaHelper; + XCX121XVOLUMEHelper *xvolumeHelper; // // Constructors ... @@ -2156,6 +2194,8 @@ class XCX121Helper : public XCBase xcheInputs.Clean(); x3maInputs.Clean(); xvwapInputs.Clean(); + xdeltaInputs.Clean(); + xvolumeInputs.Clean(); // delete xccHelper; @@ -2169,6 +2209,8 @@ class XCX121Helper : public XCBase delete xdonHelper; delete x3maHelper; delete xvwapHelper; + delete xdeltaHelper; + delete xvolumeHelper; // ZeroMemory(xccHelper); @@ -2182,6 +2224,8 @@ class XCX121Helper : public XCBase ZeroMemory(xdonHelper); ZeroMemory(x3maHelper); ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); } // @@ -2247,6 +2291,8 @@ class XCX121Helper : public XCBase xdonInputs = inputs.xdonInputs; x3maInputs = inputs.x3maInputs; xvwapInputs = inputs.xvwapInputs; + xdeltaInputs = inputs.xdeltaInputs; + xvolumeInputs = inputs.xvolumeInputs; // // Initial Helpers ... @@ -2261,6 +2307,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2274,6 +2336,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2287,6 +2365,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2300,6 +2394,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2313,6 +2423,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2326,6 +2452,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2339,6 +2481,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2352,6 +2510,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2365,6 +2539,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2378,6 +2568,22 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2391,6 +2597,80 @@ class XCX121Helper : public XCBase ); if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // + return result; + } + + // + // XDELTA ... + xdeltaHelper = new XCX121XDELTAHelper(); + result = xdeltaHelper.Init( + symbol, + period, + xdeltaInputs // + ); + if (!result) + { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // + return result; + } + + // + // XVOLUME ... + xvolumeHelper = new XCX121XVOLUMEHelper(); + result = xvolumeHelper.Init( + symbol, + period, + xvolumeInputs // + ); + if (!result) + { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } @@ -2409,6 +2689,22 @@ class XCX121Helper : public XCBase result = mRSIHandler != INVALID_HANDLE; if (!result) { + // + ZeroMemory(xccHelper); + ZeroMemory(xpvHelper); + ZeroMemory(xhkHelper); + ZeroMemory(xmasHelper); + ZeroMemory(xatrHelper); + ZeroMemory(xichHelper); + ZeroMemory(xstrHelper); + ZeroMemory(xcheHelper); + ZeroMemory(xdonHelper); + ZeroMemory(x3maHelper); + ZeroMemory(xvwapHelper); + ZeroMemory(xdeltaHelper); + ZeroMemory(xvolumeHelper); + + // return result; } } @@ -2640,6 +2936,50 @@ class XCX121Helper : public XCBase return result; } + // + // XDELTA ... + bool GetDELTAConditions( + X121XDELTAConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = false; + + // + result = xdeltaHelper.GetConditions( + conditions, + barIndex, + loopback // + ); + + // + return result; + } + + // + // XVOLUME ... + bool GetVOLUMEConditions( + X121XVOLUMEConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = false; + + // + result = xvolumeHelper.GetConditions( + conditions, + barIndex, + loopback // + ); + + // + return result; + } + // void Free() { @@ -2936,6 +3276,61 @@ class XCX121Helper : public XCBase return result; } + // + // XDELTA ... + X121XDELTAConditions xdeltaConditions; + result = GetDELTAConditions( + xdeltaConditions, + barIndex, + loopback // + ); + if (!result) + { + // + xpvConditions.Clean(); + xhkConditions.Clean(); + xichConditions.Clean(); + xmasConditions.Clean(); + xatrConditions.Clean(); + xstrConditions.Clean(); + xcheConditions.Clean(); + xdonConditions.Clean(); + x3maConditions.Clean(); + xvwapConditions.Clean(); + xdeltaConditions.Clean(); + + // + return result; + } + + // + // XVOLUME ... + X121XVOLUMEConditions xvolumeConditions; + result = GetVOLUMEConditions( + xvolumeConditions, + barIndex, + loopback // + ); + if (!result) + { + // + xpvConditions.Clean(); + xhkConditions.Clean(); + xichConditions.Clean(); + xmasConditions.Clean(); + xatrConditions.Clean(); + xstrConditions.Clean(); + xcheConditions.Clean(); + xdonConditions.Clean(); + x3maConditions.Clean(); + xvwapConditions.Clean(); + xdeltaConditions.Clean(); + xvolumeConditions.Clean(); + + // + return result; + } + // // Fill Volume Buffer ... for (int i = barIndex; i < barIndex + loopback; i++) @@ -3639,6 +4034,66 @@ class XCX121Helper : public XCBase conditions.senkouMax = MathMax(xichConditions.senkouSpanABuffer[cIDX], xichConditions.senkouSpanBBuffer[cIDX]); conditions.senkouMin = MathMin(xichConditions.senkouSpanABuffer[cIDX], xichConditions.senkouSpanBBuffer[cIDX]); + // + // XDELTA ... + + // + // Buffers ... + + // + Copy( + xdeltaConditions.deltaBuffer, + conditions.deltaBuffer // + ); + + // + Copy( + xdeltaConditions.deltaMaBuffer, + conditions.deltaMaBuffer // + ); + + // + Copy( + xdeltaConditions.deltaStateBuffer, + conditions.deltaStateBuffer // + ); + + // + // Conditions ... + + // + // XVOLUME ... + + // + // Buffers ... + + // + Copy( + xvolumeConditions.bullishVolumeBuffer, + conditions.bullishVolumeBuffer // + ); + + // + Copy( + xvolumeConditions.bullishVolumeMaBuffer, + conditions.bullishVolumeMaBuffer // + ); + + // + Copy( + xvolumeConditions.bearishVolumeBuffer, + conditions.bearishVolumeBuffer // + ); + + // + Copy( + xvolumeConditions.bearishVolumeMaBuffer, + conditions.bearishVolumeMaBuffer // + ); + + // + // Conditions ... + // // Slopes ... @@ -4152,6 +4607,8 @@ class XCX121Helper : public XCBase X121XCHEInputs xcheInputs; X121X3MAInputs x3maInputs; X121XVWAPInputs xvwapInputs; + X121XDELTAInputs xdeltaInputs; + X121XVOLUMEInputs xvolumeInputs; // int mRSIHandler; diff --git a/Helpers/x-saherelm.x121.xdelta.helper.mq5 b/Helpers/x-saherelm.x121.xdelta.helper.mq5 new file mode 100644 index 00000000..be52df88 --- /dev/null +++ b/Helpers/x-saherelm.x121.xdelta.helper.mq5 @@ -0,0 +1,780 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XCX121XDELTASHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.x-helper.class.mq5" + +// +// Definitions ... +enum ENUM_X121_XDELTA_BUFFERS +{ + // + X121_XDELTA_VOLUME_LINE = 0, + X121_XDELTA_HISTOGRAM_LINE = 1, + X121_XDELTA_MA_LINE = 3, + X121_XDELTA_STATE_LINE = 5, +}; + +// +// Input Models ... +struct X121XDELTAInputs +{ + // + // Props ... + + // + // Makret ... + int maLength; // Moving Averge Length + ENUM_X_MA_METHOD maMethod; // Moving Averge Method + + // + // Presentation ... + int startCalculationForLastBars; // Calculate Last n Bars + bool showDeltaLine; // Show Delta Line + bool showDeltaHistogram; // Show Delta Histogram + bool showDeltaMa; // Show Delta Moving Average + + // + // Constructor(s) ... + X121XDELTAInputs() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup Model ... + */ + void Clean() + { + // + // Makret ... + maLength = 0; // Moving Averge Length + maMethod = X_MA_MODE_NONE; // Moving Averge Method + + // + // Presentation ... + startCalculationForLastBars = 0; // Calculate Last n Bars + showDeltaLine = false; // Show Delta Line + showDeltaHistogram = false; // Show Delta Histogram + showDeltaMa = false; // Show Delta Moving Average + + // + ZeroMemory(this); + } + + /** + * Default Inputs ... + */ + void Default() + { + // + // Makret ... + maLength = 14; // Moving Averge Length + maMethod = X_MA_MODE_EMA; // Moving Averge Method + + // + // Presentation ... + startCalculationForLastBars = 1000; // Calculate Last n Bars + showDeltaLine = true; // Show Delta Line + showDeltaHistogram = true; // Show Delta Histogram + showDeltaMa = true; // Show Delta Moving Average + } + + /** + * Validate Model ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + // + maLength > 0 && + IsValid(maMethod) + // + ; + + // + return result; + } + + /** + * Retrieve Max Input Length ... + * + * @return ( int ) + */ + int Max() + { + // + int result = 0; + + // + result = MathMax(result, maLength); + + // + return result; + } + + // +}; + +// +// Conditions ... +struct X121XDELTAConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double deltaBuffer[]; + double deltaMaBuffer[]; + double deltaStateBuffer[]; + + // + // Conditions ... + + // + // Constructor ... + X121XDELTAConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + // Commons ... + time = NULL; + symbol = NULL; + period = NULL; + + // + // Buffers ... + + // + Clean(deltaBuffer); + Clean(deltaMaBuffer); + Clean(deltaStateBuffer); + + // + ArraySetAsSeries(deltaBuffer, true); + ArraySetAsSeries(deltaMaBuffer, true); + ArraySetAsSeries(deltaStateBuffer, true); + + // + // Conditions ... + + // + ZeroMemory(this); + } + + /** + * Generate Conditions Scores ... + * + * @param bullishScore: Double, Directional Scores Reference ... + * @param bearishScore: Double, Directional Scores Reference ... + */ + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // TODO: Implement if Required ... + } + + /** + * Generate Summary String for Represent Conditions State ... + * + * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... + * @param onlyConditions: Boolean, Just Generate Only Conditions ... + * @param includeScores: Boolean, Attach Scores Representations on Result ... + * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... + * @param separator: String, Separate Lines ... + * + * @return ( string ) + */ + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + /** + * Retrieve nique Tag Identifier ... + * + * @return ( string ) + */ + string GetTag() + { + return GetTypeName(this); + } + + // +}; + +// +// Class ... +class XCX121XDELTAHelper : public XCBaseHelper +{ + // + // Public ... + public: + // + // Props ... + + // + // Constructors ... + XCX121XDELTAHelper() + : XCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XCX121XDELTAHelper() + { + // + mInputs.Clean(); + + // + Clean(deltaBuffer); + Clean(deltaMaBuffer); + Clean(deltaStateBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + X121XDELTAInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + ArraySetAsSeries(deltaBuffer, true); + ArraySetAsSeries(deltaMaBuffer, true); + ArraySetAsSeries(deltaStateBuffer, true); + + // + mInputs = inputs; + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.x121.xdelta", + // + // Inputs ... + // + // Market ... + "", + mInputs.maLength, + mInputs.maMethod, + // + // Presentation ... + "", + // + mInputs.startCalculationForLastBars, + mInputs.showDeltaLine, + mInputs.showDeltaHistogram, + mInputs.showDeltaMa + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + X121XDELTAInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + X121XDELTAInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Readers ... + + // + // Bullish ... + + // + double GetDelta( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(deltaBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return deltaBuffer[barIndex]; + } + + // + int CopyDelta( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + deltaBuffer, + buffer, + forceClean + // + ); + } + + // + double GetDeltaState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(deltaStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return deltaStateBuffer[barIndex]; + } + + // + int CopyDeltaState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + deltaStateBuffer, + buffer, + forceClean + // + ); + } + + // + double GetDeltaMa( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(deltaMaBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return deltaMaBuffer[barIndex]; + } + + // + int CopyDeltaMa( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + deltaMaBuffer, + buffer, + forceClean + // + ); + } + + // + bool GetConditions( + X121XDELTAConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + mSymbol, + mPeriod, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Buffers ... + + // + CopyDelta( + zIndex, + loopback, + conditions.deltaBuffer // + ); + + // + CopyDeltaState( + zIndex, + loopback, + conditions.deltaStateBuffer // + ); + + // + CopyDeltaMa( + zIndex, + loopback, + conditions.deltaMaBuffer // + ); + + // + // Conditions ... + + // + int cIDX = 1; + int pIDX = cIDX + 1; + + // + // SAR ... + + // + Cleanup(); + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + + // + return result; + } + + // + // Protected ... + protected: + // + // Private ... + private: + // + // Props ... + X121XDELTAInputs mInputs; // Inputs ... + + // + // Buffers ... + double deltaBuffer[]; + double deltaMaBuffer[]; + double deltaStateBuffer[]; + + // + void Calculate( + int maxRequiredBars = 100 // + ) + { + // + // Buffers ... + + // + CopyBuffer( + mHandler, + X121_XDELTA_VOLUME_LINE, + 0, + maxRequiredBars, + deltaBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_XDELTA_MA_LINE, + 0, + maxRequiredBars, + deltaMaBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_XDELTA_STATE_LINE, + 0, + maxRequiredBars, + deltaStateBuffer + // + ); + } + + // + void Cleanup( + int maxAllowed = 100 // + ) + { + // + CleanupArray( + deltaBuffer, + maxAllowed // + ); + + // + CleanupArray( + deltaMaBuffer, + maxAllowed // + ); + + // + CleanupArray( + deltaStateBuffer, + maxAllowed // + ); + } + + // +}; + +// diff --git a/Helpers/x-saherelm.x121.xmas.helper.mq5 b/Helpers/x-saherelm.x121.xmas.helper.mq5 index b9d671eb..3893423d 100644 --- a/Helpers/x-saherelm.x121.xmas.helper.mq5 +++ b/Helpers/x-saherelm.x121.xmas.helper.mq5 @@ -27,8 +27,6 @@ // // Definitions ... -// -// Definitions ... enum ENUM_X121_XMAS_BUFFERS { // diff --git a/Helpers/x-saherelm.x121.xvolume.helper.mq5 b/Helpers/x-saherelm.x121.xvolume.helper.mq5 new file mode 100644 index 00000000..cef02d52 --- /dev/null +++ b/Helpers/x-saherelm.x121.xvolume.helper.mq5 @@ -0,0 +1,865 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XCX121XVOLUMESHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.x-helper.class.mq5" + +// +// Definitions ... +enum ENUM_X121_XVOLUME_BUFFERS +{ + // + X121_XVOLUME_BULLISH_LINE = 0, + X121_XVOLUME_BULLISH_MA_LINE = 1, + X121_XVOLUME_BEARISH_LINE = 2, + X121_XVOLUME_BEARISH_MA_LINE = 3, +}; + +// +// Input Models ... +struct X121XVOLUMEInputs +{ + // + // Props ... + + // + // Makret ... + int maLength; // Moving Averge Length + ENUM_X_MA_METHOD maMethod; // Moving Averge Method + + // + // Presentation ... + int startCalculationForLastBars; // Calculate Last n Bars + bool showBullishVolume; // Show Bullish Volume + bool showBullishVolumeMa; // Show Bullish Volume Moving Average + bool showBearishVolume; // Show Bearish Volume + bool showBearishVolumeMa; // Show Bearish Volume Moving Average + + // + // Constructor(s) ... + X121XVOLUMEInputs() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup Model ... + */ + void Clean() + { + // + // Makret ... + maLength = 0; // Moving Averge Length + maMethod = X_MA_MODE_NONE; // Moving Averge Method + + // + // Presentation ... + startCalculationForLastBars = 0; // Calculate Last n Bars + showBullishVolume = false; // Show Bullish Volume + showBullishVolumeMa = false; // Show Bullish Volume Moving Average + showBearishVolume = false; // Show Bearish Volume + showBearishVolumeMa = false; // Show Bearish Volume Moving Average + + // + ZeroMemory(this); + } + + /** + * Default Inputs ... + */ + void Default() + { + // + // Makret ... + maLength = 14; // Moving Averge Length + maMethod = X_MA_MODE_EMA; // Moving Averge Method + + // + // Presentation ... + startCalculationForLastBars = 1000; // Calculate Last n Bars + showBullishVolume = true; // Show Bullish Volume + showBullishVolumeMa = true; // Show Bullish Volume Moving Average + showBearishVolume = true; // Show Bearish Volume + showBearishVolumeMa = true; // Show Bearish Volume Moving Average + } + + /** + * Validate Model ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + // + maLength > 0 && + IsValid(maMethod) + // + ; + + // + return result; + } + + /** + * Retrieve Max Input Length ... + * + * @return ( int ) + */ + int Max() + { + // + int result = 0; + + // + result = MathMax(result, maLength); + + // + return result; + } + + // +}; + +// +// Conditions ... +struct X121XVOLUMEConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double bullishVolumeBuffer[]; + double bullishVolumeMaBuffer[]; + double bearishVolumeBuffer[]; + double bearishVolumeMaBuffer[]; + + // + // Conditions ... + + // + // Constructor ... + X121XVOLUMEConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + // Commons ... + time = NULL; + symbol = NULL; + period = NULL; + + // + // Buffers ... + + // + Clean(bullishVolumeBuffer); + Clean(bullishVolumeMaBuffer); + Clean(bearishVolumeBuffer); + Clean(bearishVolumeMaBuffer); + + // + ArraySetAsSeries(bullishVolumeBuffer, true); + ArraySetAsSeries(bullishVolumeMaBuffer, true); + ArraySetAsSeries(bearishVolumeBuffer, true); + ArraySetAsSeries(bearishVolumeMaBuffer, true); + + // + // Conditions ... + + // + ZeroMemory(this); + } + + /** + * Generate Conditions Scores ... + * + * @param bullishScore: Double, Directional Scores Reference ... + * @param bearishScore: Double, Directional Scores Reference ... + */ + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // TODO: Implement if Required ... + } + + /** + * Generate Summary String for Represent Conditions State ... + * + * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... + * @param onlyConditions: Boolean, Just Generate Only Conditions ... + * @param includeScores: Boolean, Attach Scores Representations on Result ... + * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... + * @param separator: String, Separate Lines ... + * + * @return ( string ) + */ + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + /** + * Retrieve nique Tag Identifier ... + * + * @return ( string ) + */ + string GetTag() + { + return GetTypeName(this); + } + + // +}; + +// +// Class ... +class XCX121XVOLUMEHelper : public XCBaseHelper +{ + // + // Public ... + public: + // + // Props ... + + // + // Constructors ... + XCX121XVOLUMEHelper() + : XCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XCX121XVOLUMEHelper() + { + // + mInputs.Clean(); + + // + Clean(bullishVolumeBuffer); + Clean(bullishVolumeMaBuffer); + Clean(bearishVolumeBuffer); + Clean(bearishVolumeMaBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + X121XVOLUMEInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + ArraySetAsSeries(bullishVolumeBuffer, true); + ArraySetAsSeries(bullishVolumeMaBuffer, true); + ArraySetAsSeries(bearishVolumeBuffer, true); + ArraySetAsSeries(bearishVolumeMaBuffer, true); + + // + mInputs = inputs; + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.x121.xvolume", + // + // Inputs ... + // + // Market ... + "", + mInputs.maLength, + mInputs.maMethod, + // + // Presentation ... + "", + // + mInputs.startCalculationForLastBars, + mInputs.showBullishVolume, + mInputs.showBullishVolumeMa, + mInputs.showBearishVolume, + mInputs.showBearishVolumeMa + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + X121XVOLUMEInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + X121XVOLUMEInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Readers ... + + // + // Bullish ... + + // + double GetBullishVolume( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(bullishVolumeBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return bullishVolumeBuffer[barIndex]; + } + + // + int CopyBullishVolume( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + bullishVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + double GetBullishVolumeMa( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(bullishVolumeMaBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return bullishVolumeMaBuffer[barIndex]; + } + + // + int CopyBullishVolumeMa( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + bullishVolumeMaBuffer, + buffer, + forceClean + // + ); + } + + // + // Bearish ... + + // + double GetBearishVolume( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(bearishVolumeBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return bearishVolumeBuffer[barIndex]; + } + + // + int CopyBearishVolume( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + bearishVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + double GetBearishVolumeMa( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(bearishVolumeMaBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return bearishVolumeMaBuffer[barIndex]; + } + + // + int CopyBearishVolumeMa( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + bearishVolumeMaBuffer, + buffer, + forceClean + // + ); + } + + // + bool GetConditions( + X121XVOLUMEConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + mSymbol, + mPeriod, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Buffers ... + + // + CopyBullishVolume( + zIndex, + loopback, + conditions.bullishVolumeBuffer // + ); + + // + CopyBullishVolumeMa( + zIndex, + loopback, + conditions.bullishVolumeMaBuffer // + ); + + // + CopyBearishVolume( + zIndex, + loopback, + conditions.bearishVolumeBuffer // + ); + + // + CopyBearishVolumeMa( + zIndex, + loopback, + conditions.bearishVolumeMaBuffer // + ); + + // + // Conditions ... + + // + int cIDX = 1; + int pIDX = cIDX + 1; + + // + // SAR ... + + // + Cleanup(); + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + + // + return result; + } + + // + // Protected ... + protected: + // + // Private ... + private: + // + // Props ... + X121XVOLUMEInputs mInputs; // Inputs ... + + // + // Buffers ... + double bullishVolumeBuffer[]; + double bullishVolumeMaBuffer[]; + double bearishVolumeBuffer[]; + double bearishVolumeMaBuffer[]; + + // + void Calculate( + int maxRequiredBars = 100 // + ) + { + // + // Buffers ... + + // + CopyBuffer( + mHandler, + X121_XVOLUME_BULLISH_LINE, + 0, + maxRequiredBars, + bullishVolumeBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_XVOLUME_BULLISH_MA_LINE, + 0, + maxRequiredBars, + bullishVolumeMaBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_XVOLUME_BEARISH_LINE, + 0, + maxRequiredBars, + bearishVolumeBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_XVOLUME_BEARISH_MA_LINE, + 0, + maxRequiredBars, + bearishVolumeMaBuffer + // + ); + } + + // + void Cleanup( + int maxAllowed = 100 // + ) + { + // + CleanupArray( + bullishVolumeBuffer, + maxAllowed // + ); + + // + CleanupArray( + bullishVolumeMaBuffer, + maxAllowed // + ); + + // + CleanupArray( + bearishVolumeBuffer, + maxAllowed // + ); + + // + CleanupArray( + bearishVolumeMaBuffer, + maxAllowed // + ); + } + + // +}; + +// diff --git a/Indicators/x-saherelm.x121.x-delta.mq5 b/Indicators/x-saherelm.x121.xdelta.mq5 similarity index 95% rename from Indicators/x-saherelm.x121.x-delta.mq5 rename to Indicators/x-saherelm.x121.xdelta.mq5 index ec4031cc..b422765f 100644 --- a/Indicators/x-saherelm.x121.x-delta.mq5 +++ b/Indicators/x-saherelm.x121.xdelta.mq5 @@ -53,7 +53,7 @@ input bool showDeltaMa = true; // Show Delta Moving Average #property indicator_separate_window // -#property indicator_buffers 5 +#property indicator_buffers 6 #property indicator_plots 3 // @@ -107,6 +107,10 @@ double deltaMaBuffer[]; #define rawDeltaBufferIndex mLastBufferIndex + 1 double rawDeltaBuffer[]; +// +#define deltaStateBufferIndex mLastBufferIndex + 2 +double deltaStateBuffer[]; + // // Variables, Properties and etc ... @@ -343,6 +347,10 @@ void DefineBuffers() // ArraySetAsSeries(rawDeltaBuffer, true); SetIndexBuffer(rawDeltaBufferIndex, rawDeltaBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(deltaStateBuffer, true); + SetIndexBuffer(deltaStateBufferIndex, deltaStateBuffer, INDICATOR_CALCULATIONS); } /** @@ -407,8 +415,9 @@ void FillBuffersZero(int barIndex) // rawDeltaBuffer[barIndex] = 0.0; deltaLineBuffer[barIndex] = 0.0; + deltaStateBuffer[barIndex] = 0.0; deltaHistogramBuffer[barIndex] = 0.0; - deltaMaBuffer[barIndex] = EMPTY_VALUE; + deltaMaBuffer[barIndex] = 0.0; deltaHistogramColorBuffer[barIndex] = hideColorIDX; } @@ -470,11 +479,9 @@ void CalculateValues( if (isFirstBar) { // + rawDeltaBuffer[bar_index] = iDelta; deltaLineBuffer[bar_index] = iDelta; deltaHistogramBuffer[bar_index] = iDelta; - - // - rawDeltaBuffer[bar_index] = iDelta; } else { @@ -485,21 +492,25 @@ void CalculateValues( rawDeltaBuffer[bar_index] = iDelta; deltaLineBuffer[bar_index] = iDelta; deltaHistogramBuffer[bar_index] = iDelta; - - // - // deltaLineBuffer[bar_index] = deltaLineBuffer[bar_index + 1] + iDelta; - // deltaHistogramBuffer[bar_index] = deltaHistogramBuffer[bar_index + 1] + iDelta; - - // // - // rawDeltaBuffer[bar_index] = rawDeltaBuffer[bar_index + 1] + iDelta; } // + // Setting iDelta State ... + double iState = iDelta > 0 + ? bullishColorIDX + : iDelta < 0 + ? bearishColorIDX + : hideColorIDX; + // + // Setting iDelta Color ... double iDeltaColor = iDelta > 0 ? bullishColorIDX : iDelta < 0 ? bearishColorIDX : hideColorIDX; + + // + deltaStateBuffer[bar_index] = iState; deltaHistogramColorBuffer[bar_index] = iDeltaColor; // diff --git a/Indicators/x-saherelm.x121.x-volume.mq5 b/Indicators/x-saherelm.x121.xvolume.mq5 similarity index 100% rename from Indicators/x-saherelm.x121.x-volume.mq5 rename to Indicators/x-saherelm.x121.xvolume.mq5