diff --git a/BKPS/Indicators 14030517/x-saherelm.xcc.ex5 b/BKPS/Indicators 14030517/x-saherelm.xcc.ex5 new file mode 100644 index 0000000..2f0d46c Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xcc.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xcc.mq5 b/BKPS/Indicators 14030517/x-saherelm.xcc.mq5 new file mode 100644 index 0000000..ebc4517 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xcc.mq5 @@ -0,0 +1,437 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Candle Styles +// --------------------------------------------------- +// Name: XCC +// Description: Candle Styles ... +// +// +// 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 XCC Indicator" +#property strict + +// +// START Constants ... +// + +// +// Indicator Short Name ... +#define ShortName "XCC" + +// +// Holds an SnapShot of Charts Configuration ... +struct XChartStyle +{ + // + // chart's ID ... + long chartId; + // + // chart's mode ... + ENUM_CHART_MODE mode; + // + // show bid line ... + bool showBidLine; + // + // show ask line ... + bool showAskLine; + // + // show grids on chart ... + bool showGrid; + // + // show volumes ... + bool showVolumes; + // + // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ... + bool showTradeLevels; + // + // chart autoscroll ... + bool autoScroll; + // + // chart quick navigation state ... + bool quickNavigation; + // + // chart's foreground color ... + color foreGroundColor; + // + // chart's background color ... + color backGroundColor; + // + // Up Color ... + color upColor; + // + // Down Color ... + color downColor; + // + // Bullish color ... + color bullishColor; + // + // Bearish color ... + color bearishColor; + // + // grid color ... + color gridColor; + // + // bid line color ... + color bidLineColor; + // + // ask line color ... + color askLineColor; + // + // line mode and doji candlestick color ... + color lineColor; + // + // Color of stop order levels (Stop Loss and Take Profit) ... + color stopColor; + // + // volumes color ... + color volumesColor; +}; + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input group "Chart Style"; +input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode +input color upColor = clrLime; // Up Color +input color downColor = clrRed; // Down Color +input color lineColor = clrLime; // Line mode and Doji candlestick Color +input color bearishColor = clrRed; // Bullish Color +input color bullishColor = clrLime; // Bearish Color +input color volumesColor = clrGreen; // Volumes Color + +// +input group "Presentation"; +input bool showCandles = true; // Show Candles + +// +// END Inputs ... +// + +// +// START Includes and Imports ... +// + +// +// Includes Draw Library ... +#include "../Libraries/x-saherelm.draw.lib.mq5" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Includes and Imports ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +int maxLength; + +// +XChartStyle chartStyle; +XChartStyle clearStyle; + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + drawPrefix = ShortName; + + // + // 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(); + + // + // Apply Chart Style ... + ApplyCustomChartStyle(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // 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); + + // + // this counts Available Bars ... + int limit; + + // + 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); + } + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = true; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index // Selected Bar Index +) +{ +} + +// +// Apply Custom Chart Style ... +void ApplyCustomChartStyle() +{ + // + // Read Current Chart Config and Store it ... + ReadChartStyle(); + + // + // After Reading Current Chart Style ... + // we have to Save Configs and Change Styles ... + clearStyle = chartStyle; + + // + clearStyle.upColor = CLR_NONE; + clearStyle.downColor = CLR_NONE; + clearStyle.lineColor = CLR_NONE; + clearStyle.bullishColor = CLR_NONE; + clearStyle.bearishColor = CLR_NONE; + + // + // Decide to Show or not Candles based on User Input ... + if (showCandles) + { + SetChartStyle(chartStyle); + } + else + { + SetChartStyle(clearStyle); + } +} + +// +// Read Previous Chart Style ... +void ReadChartStyle() +{ + // + // Retrieve Current Chart ID ... + long chartId = ChartID(); + chartStyle.chartId = chartId; + + // + // Retrieve Chart Mode ... + chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE); + + // + chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE); + chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE); + chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID); + chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES); + chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS); + chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL); + chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION); + + // + chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND); + chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND); + chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP); + chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN); + chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL); + chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR); + chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID); + chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID); + chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK); + chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL); + chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE); + chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME); + + // + chartStyle.mode = mode; + chartStyle.upColor = upColor; + chartStyle.downColor = downColor; + chartStyle.lineColor = lineColor; + chartStyle.bearishColor = bearishColor; + chartStyle.bullishColor = bullishColor; + chartStyle.volumesColor = volumesColor; +} + +// +// Set Chart Style ... +void SetChartStyle( + XChartStyle &mChartStyle // Chart Style to Apply +) +{ + // + ApplyChartStyle( + mChartStyle.chartId, + mChartStyle.mode, + mChartStyle.showBidLine, + mChartStyle.showAskLine, + mChartStyle.showGrid, + mChartStyle.showVolumes, + mChartStyle.showTradeLevels, + mChartStyle.autoScroll, + mChartStyle.quickNavigation, + mChartStyle.foreGroundColor, + mChartStyle.backGroundColor, + mChartStyle.upColor, + mChartStyle.downColor, + mChartStyle.bullishColor, + mChartStyle.bearishColor, + mChartStyle.gridColor, + mChartStyle.bidLineColor, + mChartStyle.askLineColor, + mChartStyle.lineColor, + mChartStyle.stopColor, + mChartStyle.volumesColor); +} + +// +// END Functions ... +// diff --git a/BKPS/Indicators 14030517/x-saherelm.xchche.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchche.ex5 new file mode 100644 index 0000000..dfa7ca8 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchche.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchche.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchche.mq5 new file mode 100644 index 0000000..75d0c75 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchche.mq5 @@ -0,0 +1,1192 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHCHE +// Description: XCHCHE Cycles ... +// +// 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 XCHCHE Indicator" +#property strict + +// +#define ShortName "XCHCHE" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 35; // Length +input int loopback = 26; // Loopback +input double multiplier1 = 3.0; // 1st Multiplier +input double multiplier2 = 3.5; // 2nd Multiplier + +// +input group "Calculation"; +input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to +input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// Current ... +input bool showCurrentLE1 = true; // Show Current Cycle Long Exit 1 +input bool showCurrentLE2 = true; // Show Current Cycle Long Exit 2 +input bool showCurrentSE1 = true; // Show Current Cycle Short Exit 1 +input bool showCurrentSE2 = true; // Show Current Cycle Short Exit 2 + +// +// Short ... +input bool showShortLE1 = true; // Show Short Cycle Long Exit 1 +input bool showShortLE2 = true; // Show Short Cycle Long Exit 2 +input bool showShortSE1 = true; // Show Short Cycle Short Exit 1 +input bool showShortSE2 = true; // Show Short Cycle Short Exit 2 + +// +// Medium ... +input bool showMediumLE1 = true; // Show Medium Cycle Long Exit 1 +input bool showMediumLE2 = true; // Show Medium Cycle Long Exit 2 +input bool showMediumSE1 = true; // Show Medium Cycle Short Exit 1 +input bool showMediumSE2 = true; // Show Medium Cycle Short Exit 2 + +// +// Long ... +input bool showLongLE1 = true; // Show Long Cycle Long Exit 1 +input bool showLongLE2 = true; // Show Long Cycle Long Exit 2 +input bool showLongSE1 = true; // Show Long Cycle Short Exit 1 +input bool showLongSE2 = true; // Show Long Cycle Short Exit 2 + +// +// Hind ... +input bool showHindLE1 = true; // Show Hind Cycle Long Exit 1 +input bool showHindLE2 = true; // Show Hind Cycle Long Exit 2 +input bool showHindSE1 = true; // Show Hind Cycle Short Exit 1 +input bool showHindSE2 = true; // Show Hind Cycle Short Exit 2 + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 20 +#property indicator_plots 20 + +// +// Current ... + +// +// Long Exit 1 ... +#define cLE1BufferIndex 0 +double cLE1Buffer[]; + +// +#property indicator_label1 "XCHCHE C LE 1" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT + +// +// Short Exit 1 ... +#define cSE1BufferIndex 1 +double cSE1Buffer[]; + +// +#property indicator_label2 "XCHCHE C SE 1" +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT +#property indicator_color2 clrRed + +// +// Long Exit 2 ... +#define cLE2BufferIndex 2 +double cLE2Buffer[]; + +// +#property indicator_label3 "XCHCHE C LE 2" +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT +#property indicator_color3 clrAqua + +// +// Short Exit 2 ... +#define cSE2BufferIndex 3 +double cSE2Buffer[]; + +// +#property indicator_label4 "XCHCHE C SE 2" +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DOT +#property indicator_color4 clrMagenta + +// +// Short ... + +// +// Long Exit 1 ... +#define sLE1BufferIndex 4 +double sLE1Buffer[]; + +// +#property indicator_label5 "XCHCHE S LE 1" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLime +#property indicator_style5 STYLE_DOT + +// +// Short Exit 1 ... +#define sSE1BufferIndex 5 +double sSE1Buffer[]; + +// +#property indicator_label6 "XCHCHE S SE 1" +#property indicator_type6 DRAW_LINE +#property indicator_style6 STYLE_DOT +#property indicator_color6 clrRed + +// +// Long Exit 2 ... +#define sLE2BufferIndex 6 +double sLE2Buffer[]; + +// +#property indicator_label7 "XCHCHE S LE 2" +#property indicator_type7 DRAW_LINE +#property indicator_style7 STYLE_DOT +#property indicator_color7 clrAqua + +// +// Short Exit 2 ... +#define sSE2BufferIndex 7 +double sSE2Buffer[]; + +// +#property indicator_label8 "XCHCHE S SE 2" +#property indicator_type8 DRAW_LINE +#property indicator_style8 STYLE_DOT +#property indicator_color8 clrMagenta + +// +// Medium ... + +// +// Long Exit 1 ... +#define mLE1BufferIndex 8 +double mLE1Buffer[]; + +// +#property indicator_label9 "XCHCHE M LE 1" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLime +#property indicator_style9 STYLE_DOT + +// +// Short Exit 1 ... +#define mSE1BufferIndex 9 +double mSE1Buffer[]; + +// +#property indicator_label10 "XCHCHE M SE 1" +#property indicator_type10 DRAW_LINE +#property indicator_style10 STYLE_DOT +#property indicator_color10 clrRed + +// +// Long Exit 2 ... +#define mLE2BufferIndex 10 +double mLE2Buffer[]; + +// +#property indicator_label11 "XCHCHE M LE 2" +#property indicator_type11 DRAW_LINE +#property indicator_style11 STYLE_DOT +#property indicator_color11 clrAqua + +// +// Short Exit 2 ... +#define mSE2BufferIndex 11 +double mSE2Buffer[]; + +// +#property indicator_label12 "XCHCHE M SE 2" +#property indicator_type12 DRAW_LINE +#property indicator_style12 STYLE_DOT +#property indicator_color12 clrMagenta + +// +// Long ... + +// +// Long Exit 1 ... +#define lLE1BufferIndex 12 +double lLE1Buffer[]; + +// +#property indicator_label13 "XCHCHE L LE 1" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrLime +#property indicator_style13 STYLE_DOT + +// +// Short Exit 1 ... +#define lSE1BufferIndex 13 +double lSE1Buffer[]; + +// +#property indicator_label14 "XCHCHE L SE 1" +#property indicator_type14 DRAW_LINE +#property indicator_style14 STYLE_DOT +#property indicator_color14 clrRed + +// +// Long Exit 2 ... +#define lLE2BufferIndex 14 +double lLE2Buffer[]; + +// +#property indicator_label15 "XCHCHE L LE 2" +#property indicator_type15 DRAW_LINE +#property indicator_style15 STYLE_DOT +#property indicator_color15 clrAqua + +// +// Short Exit 2 ... +#define lSE2BufferIndex 15 +double lSE2Buffer[]; + +// +#property indicator_label16 "XCHCHE L SE 2" +#property indicator_type16 DRAW_LINE +#property indicator_style16 STYLE_DOT +#property indicator_color16 clrMagenta + +// +// Hind ... + +// +// Long Exit 1 ... +#define hLE1BufferIndex 16 +double hLE1Buffer[]; + +// +#property indicator_label17 "XCHCHE H LE 1" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrLime +#property indicator_style17 STYLE_DOT + +// +// Short Exit 1 ... +#define hSE1BufferIndex 17 +double hSE1Buffer[]; + +// +#property indicator_label18 "XCHCHE H SE 1" +#property indicator_type18 DRAW_LINE +#property indicator_style18 STYLE_DOT +#property indicator_color18 clrRed + +// +// Long Exit 2 ... +#define hLE2BufferIndex 18 +double hLE2Buffer[]; + +// +#property indicator_label19 "XCHCHE H LE 2" +#property indicator_type19 DRAW_LINE +#property indicator_style19 STYLE_DOT +#property indicator_color19 clrAqua + +// +// Short Exit 2 ... +#define hSE2BufferIndex 19 +double hSE2Buffer[]; + +// +#property indicator_label20 "XCHCHE H SE 2" +#property indicator_type20 DRAW_LINE +#property indicator_style20 STYLE_DOT +#property indicator_color20 clrMagenta + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +#define hi1Idx 0 +#define lo1Idx 1 +#define hi2Idx 2 +#define lo2Idx 3 +#define trend1Idx 4 +#define trend2Idx 5 + +// +// Current ... +int mCSMLength = length; +double cWork[][6]; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +double sWork[][6]; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +double mWork[][6]; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +double lWork[][6]; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +double hWork[][6]; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + if (Bars(_Symbol, _Period) < rates_total) + { + return (prev_calculated); + } + + // + if (ArrayRange(cWork, 0) != rates_total) + { + // + ArrayResize(cWork, rates_total); + ArrayResize(sWork, rates_total); + ArrayResize(mWork, rates_total); + ArrayResize(lWork, rates_total); + ArrayResize(hWork, rates_total); + } + + // + // this counts Available Bars ... + int limit; + + // + limit = prev_calculated - 1; + if (limit < 0) + { + limit = 0; + } + + // + // Main Loop ... + for (int i = limit; i < rates_total && !IsStopped(); i++) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + low, + close // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + loopback >= 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // Long Exit 1 ... + ENUM_DRAW_TYPE cLE1DrawType = showCurrentLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLE1BufferIndex, cLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cLE1BufferIndex, PLOT_SHOW_DATA, showCurrentLE1); + PlotIndexSetInteger(cLE1BufferIndex, PLOT_DRAW_TYPE, cLE1DrawType); + + // + // Long Exit 2 ... + ENUM_DRAW_TYPE cLE2DrawType = showCurrentLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLE2BufferIndex, cLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cLE2BufferIndex, PLOT_SHOW_DATA, showCurrentLE2); + PlotIndexSetInteger(cLE2BufferIndex, PLOT_DRAW_TYPE, cLE2DrawType); + + // + // Short Exit 1 ... + ENUM_DRAW_TYPE cSE1DrawType = showCurrentSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cSE1BufferIndex, cSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cSE1BufferIndex, PLOT_SHOW_DATA, showCurrentSE1); + PlotIndexSetInteger(cSE1BufferIndex, PLOT_DRAW_TYPE, cSE1DrawType); + + // + // Short Exit 2 ... + ENUM_DRAW_TYPE cSE2DrawType = showCurrentSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cSE2BufferIndex, cSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cSE2BufferIndex, PLOT_SHOW_DATA, showCurrentSE2); + PlotIndexSetInteger(cSE2BufferIndex, PLOT_DRAW_TYPE, cSE2DrawType); + + // + // Short ... + + // + // Long Exit 1 ... + ENUM_DRAW_TYPE sLE1DrawType = showCurrentLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLE1BufferIndex, sLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sLE1BufferIndex, PLOT_SHOW_DATA, showCurrentLE1); + PlotIndexSetInteger(sLE1BufferIndex, PLOT_DRAW_TYPE, sLE1DrawType); + + // + // Long Exit 2 ... + ENUM_DRAW_TYPE sLE2DrawType = showCurrentLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLE2BufferIndex, sLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sLE2BufferIndex, PLOT_SHOW_DATA, showCurrentLE2); + PlotIndexSetInteger(sLE2BufferIndex, PLOT_DRAW_TYPE, sLE2DrawType); + + // + // Short Exit 1 ... + ENUM_DRAW_TYPE sSE1DrawType = showCurrentSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sSE1BufferIndex, sSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sSE1BufferIndex, PLOT_SHOW_DATA, showCurrentSE1); + PlotIndexSetInteger(sSE1BufferIndex, PLOT_DRAW_TYPE, sSE1DrawType); + + // + // Short Exit 2 ... + ENUM_DRAW_TYPE sSE2DrawType = showCurrentSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sSE2BufferIndex, sSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sSE2BufferIndex, PLOT_SHOW_DATA, showCurrentSE2); + PlotIndexSetInteger(sSE2BufferIndex, PLOT_DRAW_TYPE, sSE2DrawType); + + // + // Medium ... + + // + // Long Exit 1 ... + ENUM_DRAW_TYPE mLE1DrawType = showCurrentLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLE1BufferIndex, mLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mLE1BufferIndex, PLOT_SHOW_DATA, showCurrentLE1); + PlotIndexSetInteger(mLE1BufferIndex, PLOT_DRAW_TYPE, mLE1DrawType); + + // + // Long Exit 2 ... + ENUM_DRAW_TYPE mLE2DrawType = showCurrentLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLE2BufferIndex, mLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mLE2BufferIndex, PLOT_SHOW_DATA, showCurrentLE2); + PlotIndexSetInteger(mLE2BufferIndex, PLOT_DRAW_TYPE, mLE2DrawType); + + // + // Short Exit 1 ... + ENUM_DRAW_TYPE mSE1DrawType = showCurrentSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mSE1BufferIndex, mSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mSE1BufferIndex, PLOT_SHOW_DATA, showCurrentSE1); + PlotIndexSetInteger(mSE1BufferIndex, PLOT_DRAW_TYPE, mSE1DrawType); + + // + // Short Exit 2 ... + ENUM_DRAW_TYPE mSE2DrawType = showCurrentSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mSE2BufferIndex, mSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mSE2BufferIndex, PLOT_SHOW_DATA, showCurrentSE2); + PlotIndexSetInteger(mSE2BufferIndex, PLOT_DRAW_TYPE, mSE2DrawType); + + // + // Long ... + + // + // Long Exit 1 ... + ENUM_DRAW_TYPE lLE1DrawType = showCurrentLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLE1BufferIndex, lLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lLE1BufferIndex, PLOT_SHOW_DATA, showCurrentLE1); + PlotIndexSetInteger(lLE1BufferIndex, PLOT_DRAW_TYPE, lLE1DrawType); + + // + // Long Exit 2 ... + ENUM_DRAW_TYPE lLE2DrawType = showCurrentLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLE2BufferIndex, lLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lLE2BufferIndex, PLOT_SHOW_DATA, showCurrentLE2); + PlotIndexSetInteger(lLE2BufferIndex, PLOT_DRAW_TYPE, lLE2DrawType); + + // + // Short Exit 1 ... + ENUM_DRAW_TYPE lSE1DrawType = showCurrentSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lSE1BufferIndex, lSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lSE1BufferIndex, PLOT_SHOW_DATA, showCurrentSE1); + PlotIndexSetInteger(lSE1BufferIndex, PLOT_DRAW_TYPE, lSE1DrawType); + + // + // Short Exit 2 ... + ENUM_DRAW_TYPE lSE2DrawType = showCurrentSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lSE2BufferIndex, lSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lSE2BufferIndex, PLOT_SHOW_DATA, showCurrentSE2); + PlotIndexSetInteger(lSE2BufferIndex, PLOT_DRAW_TYPE, lSE2DrawType); + + // + // Hind ... + + // + // Long Exit 1 ... + ENUM_DRAW_TYPE hLE1DrawType = showCurrentLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLE1BufferIndex, hLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hLE1BufferIndex, PLOT_SHOW_DATA, showCurrentLE1); + PlotIndexSetInteger(hLE1BufferIndex, PLOT_DRAW_TYPE, hLE1DrawType); + + // + // Long Exit 2 ... + ENUM_DRAW_TYPE hLE2DrawType = showCurrentLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLE2BufferIndex, hLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hLE2BufferIndex, PLOT_SHOW_DATA, showCurrentLE2); + PlotIndexSetInteger(hLE2BufferIndex, PLOT_DRAW_TYPE, hLE2DrawType); + + // + // Short Exit 1 ... + ENUM_DRAW_TYPE hSE1DrawType = showCurrentSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hSE1BufferIndex, hSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hSE1BufferIndex, PLOT_SHOW_DATA, showCurrentSE1); + PlotIndexSetInteger(hSE1BufferIndex, PLOT_DRAW_TYPE, hSE1DrawType); + + // + // Short Exit 2 ... + ENUM_DRAW_TYPE hSE2DrawType = showCurrentSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hSE2BufferIndex, hSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hSE2BufferIndex, PLOT_SHOW_DATA, showCurrentSE2); + PlotIndexSetInteger(hSE2BufferIndex, PLOT_DRAW_TYPE, hSE2DrawType); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mCSMLength, + cWork, + cLE1Buffer, + cLE2Buffer, + cSE1Buffer, + cSE2Buffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mSSMLength, + sWork, + sLE1Buffer, + sLE2Buffer, + sSE1Buffer, + sSE2Buffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mMSMLength, + mWork, + mLE1Buffer, + mLE2Buffer, + mSE1Buffer, + mSE2Buffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mLSMLength, + lWork, + lLE1Buffer, + lLE2Buffer, + lSE1Buffer, + lSE2Buffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mHSMLength, + hWork, + hLE1Buffer, + hLE2Buffer, + hSE1Buffer, + hSE2Buffer // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + // + int _length, // Calculation Length + double &work[][], // Working Array + // + double &le1[], + double &le2[], + double &se1[], + double &se2[] // +) +{ + // + // Cleanup Buffers ... + le1[bar_index] = se1[bar_index] = EMPTY_VALUE; + le2[bar_index] = se2[bar_index] = EMPTY_VALUE; + + // + int start = MathMax(bar_index - loopback, 0); + + // + // Calculate ATR Value ... + double atrValue = 0; + for (int k = 1; k <= _length && (bar_index - k - 1) >= 0; k++) + { + // + atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) - + MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]); + } + atrValue /= (double)_length; + + // + // Retrieve Highest High and Lowest Lows ... + double loopbackMax = high[ArrayMaximum(high, start, loopback)]; + double loopbackMin = low[ArrayMinimum(low, start, loopback)]; + + // + // Fill Multi Dimesional Working Array ... + work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue; + work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue; + work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue; + work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue; + work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0; + work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0; + + // + if (bar_index > 0) + { + // + // Calculate Trends ... + if (close[bar_index] > work[bar_index - 1][lo1Idx]) + { + work[bar_index][trend1Idx] = 1; + } + + // + if (close[bar_index] < work[bar_index - 1][hi1Idx]) + { + work[bar_index][trend1Idx] = -1; + } + + // + if (close[bar_index] > work[bar_index - 1][lo2Idx]) + { + work[bar_index][trend2Idx] = 1; + } + + // + if (close[bar_index] < work[bar_index - 1][hi2Idx]) + { + work[bar_index][trend2Idx] = -1; + } + + // + // Calculate Exit Values ... + + // + // Exit 1 ... + + // + // Long ... + if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1) + { + // + if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx]) + { + work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx]; + } + + // + le1[bar_index] = work[bar_index][hi1Idx]; + + // // + // if (le1[bar_index - 1] == EMPTY_VALUE) + // { + // longExit1StartBuffer[bar_index] = le1[bar_index]; + // } + } + + // + // Short ... + if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1) + { + // + if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx]) + { + work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx]; + } + + // + se1[bar_index] = work[bar_index][lo1Idx]; + + // // + // if (se1[bar_index - 1] == EMPTY_VALUE) + // { + // shortExit1StartBuffer[bar_index] = se1[bar_index]; + // } + } + + // + // Exit 2 ... + + // + // Long ... + if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1) + { + if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx]) + { + work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx]; + } + + // + le2[bar_index] = work[bar_index][hi2Idx]; + + // // + // if (le2[bar_index - 1] == EMPTY_VALUE) + // { + // longExit2StartBuffer[bar_index] = le2[bar_index]; + // } + } + + // + // Short ... + if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1) + { + // + if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx]) + { + work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx]; + } + + // + se2[bar_index] = work[bar_index][lo2Idx]; + + // // + // if (se2[bar_index - 1] == EMPTY_VALUE) + // { + // shortExit2StartBuffer[bar_index] = se2[bar_index]; + // } + } + } +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchdon.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchdon.ex5 new file mode 100644 index 0000000..3ccd099 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchdon.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchdon.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchdon.mq5 new file mode 100644 index 0000000..64f53ec --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchdon.mq5 @@ -0,0 +1,1603 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHDON +// Description: Donchain on Cycles ... +// +// +// 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 XCHDON Indicator" +#property strict + +// +#define ShortName "XCHDON" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 52; // Market Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Presentation"; + +// +input bool showUpper = true; // Show Upper Band +input bool showLower = true; // Show Lower Band + +// +input bool showOpen = true; // Show Open +input bool showHigh = true; // Show High +input bool showClose = true; // Show Close +input bool showLow = true; // Show Low + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 40 +#property indicator_plots 40 + +// +// Current ... + +// +// Open ... + +// +#define cOpenUpperBufferIndex 0 +double cOpenUpperBuffer[]; + +// +#property indicator_label1 "XCHDON C O U" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrCornflowerBlue +#property indicator_width1 1 + +// +#define cOpenLowerBufferIndex 1 +double cOpenLowerBuffer[]; + +// +#property indicator_label2 "XCHDON C O L" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrCornflowerBlue +#property indicator_width2 1 + +// +// High ... + +// +#define cHighUpperBufferIndex 2 +double cHighUpperBuffer[]; + +// +#property indicator_label3 "XCHDON C H U" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAquamarine +#property indicator_width3 1 + +// +#define cHighLowerBufferIndex 3 +double cHighLowerBuffer[]; + +// +#property indicator_label4 "XCHDON C H L" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrAquamarine +#property indicator_width4 1 + +// +// Low ... + +// +#define cLowUpperBufferIndex 4 +double cLowUpperBuffer[]; + +// +#property indicator_label5 "XCHDON C L U" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrDarkOrchid +#property indicator_width5 1 + +// +#define cLowLowerBufferIndex 5 +double cLowLowerBuffer[]; + +// +#property indicator_label6 "XCHDON C L L" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrDarkOrchid +#property indicator_width6 1 + +// +// Close ... + +// +#define cCloseUpperBufferIndex 6 +double cCloseUpperBuffer[]; + +// +#property indicator_label7 "XCHDON C C U" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrCoral +#property indicator_width7 1 + +// +#define cCloseLowerBufferIndex 7 +double cCloseLowerBuffer[]; + +// +#property indicator_label8 "XCHDON C C L" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrCoral +#property indicator_width8 1 + +// +// Short ... + +// +// Open ... + +// +#define sOpenUpperBufferIndex 8 +double sOpenUpperBuffer[]; + +// +#property indicator_label9 "XCHDON S O U" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrCornflowerBlue +#property indicator_width9 1 + +// +#define sOpenLowerBufferIndex 9 +double sOpenLowerBuffer[]; + +// +#property indicator_label10 "XCHDON S O L" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrCornflowerBlue +#property indicator_width10 1 + +// +// High ... + +// +#define sHighUpperBufferIndex 10 +double sHighUpperBuffer[]; + +// +#property indicator_label11 "XCHDON S H U" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAquamarine +#property indicator_width11 1 + +// +#define sHighLowerBufferIndex 11 +double sHighLowerBuffer[]; + +// +#property indicator_label12 "XCHDON S H L" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrAquamarine +#property indicator_width12 1 + +// +// Low ... + +// +#define sLowUpperBufferIndex 12 +double sLowUpperBuffer[]; + +// +#property indicator_label13 "XCHDON S L U" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkOrchid +#property indicator_width13 1 + +// +#define sLowLowerBufferIndex 13 +double sLowLowerBuffer[]; + +// +#property indicator_label14 "XCHDON S L L" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrDarkOrchid +#property indicator_width14 1 + +// +// Close ... + +// +#define sCloseUpperBufferIndex 14 +double sCloseUpperBuffer[]; + +// +#property indicator_label15 "XCHDON S C U" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrCoral +#property indicator_width15 1 + +// +#define sCloseLowerBufferIndex 15 +double sCloseLowerBuffer[]; + +// +#property indicator_label16 "XCHDON S C L" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrCoral +#property indicator_width16 1 + +// +// Medium ... + +// +// Open ... + +// +#define mOpenUpperBufferIndex 16 +double mOpenUpperBuffer[]; + +// +#property indicator_label17 "XCHDON M O U" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrCornflowerBlue +#property indicator_width17 1 + +// +#define mOpenLowerBufferIndex 17 +double mOpenLowerBuffer[]; + +// +#property indicator_label18 "XCHDON M O L" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrCornflowerBlue +#property indicator_width18 1 + +// +// High ... + +// +#define mHighUpperBufferIndex 18 +double mHighUpperBuffer[]; + +// +#property indicator_label19 "XCHDON M H U" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrAquamarine +#property indicator_width19 1 + +// +#define mHighLowerBufferIndex 19 +double mHighLowerBuffer[]; + +// +#property indicator_label20 "XCHDON M H L" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrAquamarine +#property indicator_width20 1 + +// +// Low ... + +// +#define mLowUpperBufferIndex 20 +double mLowUpperBuffer[]; + +// +#property indicator_label21 "XCHDON M L U" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrDarkOrchid +#property indicator_width21 1 + +// +#define mLowLowerBufferIndex 21 +double mLowLowerBuffer[]; + +// +#property indicator_label22 "XCHDON M L L" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDarkOrchid +#property indicator_width22 1 + +// +// Close ... + +// +#define mCloseUpperBufferIndex 22 +double mCloseUpperBuffer[]; + +// +#property indicator_label23 "XCHDON M C U" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrCoral +#property indicator_width23 1 + +// +#define mCloseLowerBufferIndex 23 +double mCloseLowerBuffer[]; + +// +#property indicator_label24 "XCHDON M C L" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrCoral +#property indicator_width24 1 + +// +// Long ... + +// +// Open ... + +// +#define lOpenUpperBufferIndex 24 +double lOpenUpperBuffer[]; + +// +#property indicator_label25 "XCHDON L O U" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrCornflowerBlue +#property indicator_width25 1 + +// +#define lOpenLowerBufferIndex 25 +double lOpenLowerBuffer[]; + +// +#property indicator_label26 "XCHDON L O L" +#property indicator_type26 DRAW_LINE +#property indicator_color26 clrCornflowerBlue +#property indicator_width26 1 + +// +// High ... + +// +#define lHighUpperBufferIndex 26 +double lHighUpperBuffer[]; + +// +#property indicator_label27 "XCHDON L H U" +#property indicator_type27 DRAW_LINE +#property indicator_color27 clrAquamarine +#property indicator_width27 1 + +// +#define lHighLowerBufferIndex 27 +double lHighLowerBuffer[]; + +// +#property indicator_label28 "XCHDON L H L" +#property indicator_type28 DRAW_LINE +#property indicator_color28 clrAquamarine +#property indicator_width28 1 + +// +// Low ... + +// +#define lLowUpperBufferIndex 28 +double lLowUpperBuffer[]; + +// +#property indicator_label29 "XCHDON L L U" +#property indicator_type29 DRAW_LINE +#property indicator_color29 clrDarkOrchid +#property indicator_width29 1 + +// +#define lLowLowerBufferIndex 29 +double lLowLowerBuffer[]; + +// +#property indicator_label30 "XCHDON L L L" +#property indicator_type30 DRAW_LINE +#property indicator_color30 clrDarkOrchid +#property indicator_width30 1 + +// +// Close ... + +// +#define lCloseUpperBufferIndex 30 +double lCloseUpperBuffer[]; + +// +#property indicator_label31 "XCHDON L C U" +#property indicator_type31 DRAW_LINE +#property indicator_color31 clrCoral +#property indicator_width31 1 + +// +#define lCloseLowerBufferIndex 31 +double lCloseLowerBuffer[]; + +// +#property indicator_label32 "XCHDON L C L" +#property indicator_type32 DRAW_LINE +#property indicator_color32 clrCoral +#property indicator_width32 1 + +// +// Hind ... + +// +// Open ... + +// +#define hOpenUpperBufferIndex 32 +double hOpenUpperBuffer[]; + +// +#property indicator_label33 "XCHDON H O U" +#property indicator_type33 DRAW_LINE +#property indicator_color33 clrCornflowerBlue +#property indicator_width33 1 + +// +#define hOpenLowerBufferIndex 33 +double hOpenLowerBuffer[]; + +// +#property indicator_label34 "XCHDON H O L" +#property indicator_type34 DRAW_LINE +#property indicator_color34 clrCornflowerBlue +#property indicator_width34 1 + +// +// High ... + +// +#define hHighUpperBufferIndex 34 +double hHighUpperBuffer[]; + +// +#property indicator_label35 "XCHDON H H U" +#property indicator_type35 DRAW_LINE +#property indicator_color35 clrAquamarine +#property indicator_width35 1 + +// +#define hHighLowerBufferIndex 35 +double hHighLowerBuffer[]; + +// +#property indicator_label36 "XCHDON H H L" +#property indicator_type36 DRAW_LINE +#property indicator_color36 clrAquamarine +#property indicator_width36 1 + +// +// Low ... + +// +#define hLowUpperBufferIndex 36 +double hLowUpperBuffer[]; + +// +#property indicator_label37 "XCHDON H L U" +#property indicator_type37 DRAW_LINE +#property indicator_color37 clrDarkOrchid +#property indicator_width37 1 + +// +#define hLowLowerBufferIndex 37 +double hLowLowerBuffer[]; + +// +#property indicator_label38 "XCHDON H L L" +#property indicator_type38 DRAW_LINE +#property indicator_color38 clrDarkOrchid +#property indicator_width38 1 + +// +// Close ... + +// +#define hCloseUpperBufferIndex 38 +double hCloseUpperBuffer[]; + +// +#property indicator_label39 "XCHDON H C U" +#property indicator_type39 DRAW_LINE +#property indicator_color39 clrCoral +#property indicator_width39 1 + +// +#define hCloseLowerBufferIndex 39 +double hCloseLowerBuffer[]; + +// +#property indicator_label40 "XCHDON H C L" +#property indicator_type40 DRAW_LINE +#property indicator_color40 clrCoral +#property indicator_width40 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + if (rates_total < maxLength - 1) + { + return prev_calculated; + } + + // + int start = prev_calculated == 0 + ? maxLength + : prev_calculated - 1; + + // + // Main Loop ... + for (int i = start; i < rates_total; i++) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume + // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length > 2 + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT ... + + // + // Open ... + + // + // UPPER ... + bool canShowCOpenUpper = showUpper && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenUpperBufferIndex, cOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_DRAW_TYPE, cOpenUpperDrawType); + + // + // LOWER ... + bool canShowCOpenLower = showLower && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenLowerBufferIndex, cOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_DRAW_TYPE, cOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowCCloseUpper = showUpper && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseUpperBufferIndex, cCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_DRAW_TYPE, cCloseUpperDrawType); + + // + // LOWER ... + bool canShowCCloseLower = showLower && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseLowerBufferIndex, cCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_DRAW_TYPE, cCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowCHighUpper = showUpper && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighUpperBufferIndex, cHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_DRAW_TYPE, cHighUpperDrawType); + + // + // LOWER ... + bool canShowCHighLower = showLower && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighLowerBufferIndex, cHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_DRAW_TYPE, cHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowCLowUpper = showUpper && showLow && showCurrent; + ENUM_DRAW_TYPE cLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowUpperBufferIndex, cLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_DRAW_TYPE, cLowUpperDrawType); + + // + // LOWER ... + bool canShowCLowLower = showLower && showLow && showCurrent; + ENUM_DRAW_TYPE cLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowLowerBufferIndex, cLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_DRAW_TYPE, cLowLowerDrawType); + + // + // SHORT ... + + // + // Open ... + + // + // UPPER ... + bool canShowSOpenUpper = showUpper && showOpen && showShort; + ENUM_DRAW_TYPE sOpenUpperDrawType = canShowSOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenUpperBufferIndex, sOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowSOpenUpper); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_DRAW_TYPE, sOpenUpperDrawType); + + // + // LOWER ... + bool canShowSOpenLower = showLower && showOpen && showShort; + ENUM_DRAW_TYPE sOpenLowerDrawType = canShowSOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenLowerBufferIndex, sOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowSOpenLower); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_DRAW_TYPE, sOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowSCloseUpper = showUpper && showClose && showShort; + ENUM_DRAW_TYPE sCloseUpperDrawType = canShowSCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseUpperBufferIndex, sCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowSCloseUpper); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_DRAW_TYPE, sCloseUpperDrawType); + + // + // LOWER ... + bool canShowSCloseLower = showLower && showClose && showShort; + ENUM_DRAW_TYPE sCloseLowerDrawType = canShowSCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseLowerBufferIndex, sCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowSCloseLower); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_DRAW_TYPE, sCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowSHighUpper = showUpper && showHigh && showShort; + ENUM_DRAW_TYPE sHighUpperDrawType = canShowSHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighUpperBufferIndex, sHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_SHOW_DATA, canShowSHighUpper); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_DRAW_TYPE, sHighUpperDrawType); + + // + // LOWER ... + bool canShowSHighLower = showLower && showHigh && showShort; + ENUM_DRAW_TYPE sHighLowerDrawType = canShowSHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighLowerBufferIndex, sHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_SHOW_DATA, canShowSHighLower); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_DRAW_TYPE, sHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowSLowUpper = showUpper && showLow && showShort; + ENUM_DRAW_TYPE sLowUpperDrawType = canShowSLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowUpperBufferIndex, sLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_SHOW_DATA, canShowSLowUpper); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_DRAW_TYPE, sLowUpperDrawType); + + // + // LOWER ... + bool canShowSLowLower = showLower && showLow && showShort; + ENUM_DRAW_TYPE sLowLowerDrawType = canShowSLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowLowerBufferIndex, sLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_SHOW_DATA, canShowSLowLower); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_DRAW_TYPE, sLowLowerDrawType); + + // + // MEDIUM ... + + // + // Open ... + + // + // UPPER ... + bool canShowMOpenUpper = showUpper && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenUpperDrawType = canShowMOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenUpperBufferIndex, mOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowMOpenUpper); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_DRAW_TYPE, mOpenUpperDrawType); + + // + // LOWER ... + bool canShowMOpenLower = showLower && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenLowerDrawType = canShowMOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenLowerBufferIndex, mOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowMOpenLower); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_DRAW_TYPE, mOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowMCloseUpper = showUpper && showClose && showMedium; + ENUM_DRAW_TYPE mCloseUpperDrawType = canShowMCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseUpperBufferIndex, mCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowMCloseUpper); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_DRAW_TYPE, mCloseUpperDrawType); + + // + // LOWER ... + bool canShowMCloseLower = showLower && showClose && showMedium; + ENUM_DRAW_TYPE mCloseLowerDrawType = canShowMCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseLowerBufferIndex, mCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowMCloseLower); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_DRAW_TYPE, mCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowMHighUpper = showUpper && showHigh && showMedium; + ENUM_DRAW_TYPE mHighUpperDrawType = canShowMHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighUpperBufferIndex, mHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_SHOW_DATA, canShowMHighUpper); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_DRAW_TYPE, mHighUpperDrawType); + + // + // LOWER ... + bool canShowMHighLower = showLower && showHigh && showMedium; + ENUM_DRAW_TYPE mHighLowerDrawType = canShowMHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighLowerBufferIndex, mHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_SHOW_DATA, canShowMHighLower); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_DRAW_TYPE, mHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowMLowUpper = showUpper && showLow && showMedium; + ENUM_DRAW_TYPE mLowUpperDrawType = canShowMLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowUpperBufferIndex, mLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_SHOW_DATA, canShowMLowUpper); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_DRAW_TYPE, mLowUpperDrawType); + + // + // LOWER ... + bool canShowMLowLower = showLower && showLow && showMedium; + ENUM_DRAW_TYPE mLowLowerDrawType = canShowMLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowLowerBufferIndex, mLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_SHOW_DATA, canShowMLowLower); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_DRAW_TYPE, mLowLowerDrawType); + + // + // LONG ... + + // + // Open ... + + // + // UPPER ... + bool canShowLOpenUpper = showUpper && showOpen && showLong; + ENUM_DRAW_TYPE lOpenUpperDrawType = canShowLOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenUpperBufferIndex, lOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowLOpenUpper); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_DRAW_TYPE, lOpenUpperDrawType); + + // + // LOWER ... + bool canShowLOpenLower = showLower && showOpen && showLong; + ENUM_DRAW_TYPE lOpenLowerDrawType = canShowLOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenLowerBufferIndex, lOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowLOpenLower); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_DRAW_TYPE, lOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowLCloseUpper = showUpper && showClose && showLong; + ENUM_DRAW_TYPE lCloseUpperDrawType = canShowLCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseUpperBufferIndex, lCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowLCloseUpper); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_DRAW_TYPE, lCloseUpperDrawType); + + // + // LOWER ... + bool canShowLCloseLower = showLower && showClose && showLong; + ENUM_DRAW_TYPE lCloseLowerDrawType = canShowLCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseLowerBufferIndex, lCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowLCloseLower); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_DRAW_TYPE, lCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowLHighUpper = showUpper && showHigh && showLong; + ENUM_DRAW_TYPE lHighUpperDrawType = canShowLHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighUpperBufferIndex, lHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_SHOW_DATA, canShowLHighUpper); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_DRAW_TYPE, lHighUpperDrawType); + + // + // LOWER ... + bool canShowLHighLower = showLower && showHigh && showLong; + ENUM_DRAW_TYPE lHighLowerDrawType = canShowLHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighLowerBufferIndex, lHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_SHOW_DATA, canShowLHighLower); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_DRAW_TYPE, lHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowLLowUpper = showUpper && showLow && showLong; + ENUM_DRAW_TYPE lLowUpperDrawType = canShowLLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowUpperBufferIndex, lLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_SHOW_DATA, canShowLLowUpper); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_DRAW_TYPE, lLowUpperDrawType); + + // + // LOWER ... + bool canShowLLowLower = showLower && showLow && showLong; + ENUM_DRAW_TYPE lLowLowerDrawType = canShowLLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowLowerBufferIndex, lLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_SHOW_DATA, canShowLLowLower); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_DRAW_TYPE, lLowLowerDrawType); + + // + // HIND ... + + // + // Open ... + + // + // UPPER ... + bool canShowHOpenUpper = showUpper && showOpen && showHind; + ENUM_DRAW_TYPE hOpenUpperDrawType = canShowHOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenUpperBufferIndex, hOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowHOpenUpper); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_DRAW_TYPE, hOpenUpperDrawType); + + // + // LOWER ... + bool canShowHOpenLower = showLower && showOpen && showHind; + ENUM_DRAW_TYPE hOpenLowerDrawType = canShowHOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenLowerBufferIndex, hOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowHOpenLower); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_DRAW_TYPE, hOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowHCloseUpper = showUpper && showClose && showHind; + ENUM_DRAW_TYPE hCloseUpperDrawType = canShowHCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseUpperBufferIndex, hCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowHCloseUpper); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_DRAW_TYPE, hCloseUpperDrawType); + + // + // LOWER ... + bool canShowHCloseLower = showLower && showClose && showHind; + ENUM_DRAW_TYPE hCloseLowerDrawType = canShowHCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseLowerBufferIndex, hCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowHCloseLower); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_DRAW_TYPE, hCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowHHighUpper = showUpper && showHigh && showHind; + ENUM_DRAW_TYPE hHighUpperDrawType = canShowHHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighUpperBufferIndex, hHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_SHOW_DATA, canShowHHighUpper); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_DRAW_TYPE, hHighUpperDrawType); + + // + // LOWER ... + bool canShowHHighLower = showLower && showHigh && showHind; + ENUM_DRAW_TYPE hHighLowerDrawType = canShowHHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighLowerBufferIndex, hHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_SHOW_DATA, canShowHHighLower); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_DRAW_TYPE, hHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowHLowUpper = showUpper && showLow && showHind; + ENUM_DRAW_TYPE hLowUpperDrawType = canShowHLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowUpperBufferIndex, hLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_SHOW_DATA, canShowHLowUpper); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_DRAW_TYPE, hLowUpperDrawType); + + // + // LOWER ... + bool canShowHLowLower = showLower && showLow && showHind; + ENUM_DRAW_TYPE hLowLowerDrawType = canShowHLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowLowerBufferIndex, hLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_SHOW_DATA, canShowHLowLower); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_DRAW_TYPE, hLowLowerDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + // + cOpenUpperBuffer, + cOpenLowerBuffer, + cHighUpperBuffer, + cHighLowerBuffer, + cLowUpperBuffer, + cLowLowerBuffer, + cCloseUpperBuffer, + cCloseLowerBuffer // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + // + sOpenUpperBuffer, + sOpenLowerBuffer, + sHighUpperBuffer, + sHighLowerBuffer, + sLowUpperBuffer, + sLowLowerBuffer, + sCloseUpperBuffer, + sCloseLowerBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + // + mOpenUpperBuffer, + mOpenLowerBuffer, + mHighUpperBuffer, + mHighLowerBuffer, + mLowUpperBuffer, + mLowLowerBuffer, + mCloseUpperBuffer, + mCloseLowerBuffer // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + // + lOpenUpperBuffer, + lOpenLowerBuffer, + lHighUpperBuffer, + lHighLowerBuffer, + lLowUpperBuffer, + lLowLowerBuffer, + lCloseUpperBuffer, + lCloseLowerBuffer // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + // + hOpenUpperBuffer, + hOpenLowerBuffer, + hHighUpperBuffer, + hHighLowerBuffer, + hLowUpperBuffer, + hLowLowerBuffer, + hCloseUpperBuffer, + hCloseLowerBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, + // + double &_ouBuffer[], + double &_olBuffer[], + double &_huBuffer[], + double &_hlBuffer[], + double &_luBuffer[], + double &_llBuffer[], + double &_cuBuffer[], + double &_clBuffer[] // +) +{ + // + double iUpper = 0; + double iLower = 0; + + // + // OPEN ... + + // + iUpper = open[ArrayMaximum(open, bar_index - _length + 1, _length)]; + iLower = open[ArrayMinimum(open, bar_index - _length + 1, _length)]; + + // + _ouBuffer[bar_index] = iUpper; + _olBuffer[bar_index] = iLower; + + // + // HIGH ... + + // + iUpper = high[ArrayMaximum(high, bar_index - _length + 1, _length)]; + iLower = high[ArrayMinimum(high, bar_index - _length + 1, _length)]; + + // + _huBuffer[bar_index] = iUpper; + _hlBuffer[bar_index] = iLower; + + // + // LOW ... + + // + iUpper = low[ArrayMaximum(low, bar_index - _length + 1, _length)]; + iLower = low[ArrayMinimum(low, bar_index - _length + 1, _length)]; + + // + _luBuffer[bar_index] = iUpper; + _llBuffer[bar_index] = iLower; + + // + // CLOSE ... + + // + iUpper = close[ArrayMaximum(close, bar_index - _length + 1, _length)]; + iLower = close[ArrayMinimum(close, bar_index - _length + 1, _length)]; + + // + _cuBuffer[bar_index] = iUpper; + _clBuffer[bar_index] = iLower; +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchhk.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchhk.ex5 new file mode 100644 index 0000000..7fb5d47 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchhk.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchhk.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchhk.mq5 new file mode 100644 index 0000000..ff6fae8 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchhk.mq5 @@ -0,0 +1,1070 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHHK +// Description: Smoothed HikenAshi Cycles ... +// +// 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 XCHHK Indicator" +#property strict + +// +#define ShortName "XCHHK" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; + +// +input int cSmoothingLength = 14; // Smoothing Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool ignoreShadows = false; // Ignore Bar Shadows + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 29 +#property indicator_plots 25 + +// +// Current ... + +// +#define cOpenBufferIndex 0 +double cOpenBuffer[]; + +// +#define cHighBufferIndex 1 +double cHighBuffer[]; + +// +#define cLowBufferIndex 2 +double cLowBuffer[]; + +// +#define cCloseBufferIndex 3 +double cCloseBuffer[]; + +// +#define cColorBufferIndex 4 +double cColorBuffer[]; + +// +#define cBufferIndex 0 +#property indicator_label1 "C Open;C High;C Low;C Close" +#property indicator_type1 DRAW_COLOR_CANDLES +#property indicator_color1 CLR_NONE, clrAqua, clrMagenta + +// +// Short ... + +// +#define sOpenBufferIndex 5 +double sOpenBuffer[]; + +// +#define sHighBufferIndex 6 +double sHighBuffer[]; + +// +#define sLowBufferIndex 7 +double sLowBuffer[]; + +// +#define sCloseBufferIndex 8 +double sCloseBuffer[]; + +// +#define sColorBufferIndex 9 +double sColorBuffer[]; + +// +#define sBufferIndex 1 +#property indicator_label2 "S Open;S High;S Low;S Close" +#property indicator_type2 DRAW_COLOR_CANDLES +#property indicator_color2 CLR_NONE, clrAqua, clrMagenta + +// +// Medium ... + +// +#define mOpenBufferIndex 10 +double mOpenBuffer[]; + +// +#define mHighBufferIndex 11 +double mHighBuffer[]; + +// +#define mLowBufferIndex 12 +double mLowBuffer[]; + +// +#define mCloseBufferIndex 13 +double mCloseBuffer[]; + +// +#define mColorBufferIndex 14 +double mColorBuffer[]; + +// +#define mBufferIndex 2 +#property indicator_label3 "M Open;M High;M Low;M Close" +#property indicator_type3 DRAW_COLOR_CANDLES +#property indicator_color3 CLR_NONE, clrAqua, clrMagenta + +// +// Long ... + +// +#define lOpenBufferIndex 15 +double lOpenBuffer[]; + +// +#define lHighBufferIndex 16 +double lHighBuffer[]; + +// +#define lLowBufferIndex 17 +double lLowBuffer[]; + +// +#define lCloseBufferIndex 18 +double lCloseBuffer[]; + +// +#define lColorBufferIndex 19 +double lColorBuffer[]; + +// +#define lBufferIndex 3 +#property indicator_label4 "L Open;L High;L Low;L Close" +#property indicator_type4 DRAW_COLOR_CANDLES +#property indicator_color4 CLR_NONE, clrAqua, clrMagenta + +// +// Hind ... + +// +#define hOpenBufferIndex 20 +double hOpenBuffer[]; + +// +#define hHighBufferIndex 21 +double hHighBuffer[]; + +// +#define hLowBufferIndex 22 +double hLowBuffer[]; + +// +#define hCloseBufferIndex 23 +double hCloseBuffer[]; + +// +#define hColorBufferIndex 24 +double hColorBuffer[]; + +// +#define hBufferIndex 4 +#property indicator_label5 "H Open;H High;H Low;H Close" +#property indicator_type5 DRAW_COLOR_CANDLES +#property indicator_color5 CLR_NONE, clrAqua, clrMagenta + +// +// Data Buffers ... + +// +#define openBufferIndex 25 +double openBuffer[]; + +// +#define highBufferIndex 26 +double highBuffer[]; + +// +#define lowBufferIndex 27 +double lowBuffer[]; + +// +#define closeBufferIndex 28 +double closeBuffer[]; + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCSMLength = cSmoothingLength; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // 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); + + // + // this counts Available Bars ... + int limit; + + // + 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--) + { + CalculateHK(i, prev_calculated, rates_total, open, high, close, low); + } + + // + CalculateCycles(rates_total, prev_calculated); + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + cSmoothingLength > 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Data Buffers ... + + // + // Open ... + ArraySetAsSeries(openBuffer, true); + SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_CALCULATIONS); + + // + // High ... + ArraySetAsSeries(highBuffer, true); + SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_CALCULATIONS); + + // + // Low ... + ArraySetAsSeries(lowBuffer, true); + SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_CALCULATIONS); + + // + // Close ... + ArraySetAsSeries(closeBuffer, true); + SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_CALCULATIONS); + + // + // Current ... + + // + // Color ... + ArraySetAsSeries(cColorBuffer, true); + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(cBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(cBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(cColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(cOpenBuffer, true); + PlotIndexSetInteger(cOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cOpenBufferIndex, cOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(cHighBuffer, true); + PlotIndexSetInteger(cHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cHighBufferIndex, cHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(cCloseBuffer, true); + PlotIndexSetInteger(cCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cCloseBufferIndex, cCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(cLowBuffer, true); + PlotIndexSetInteger(cLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cLowBufferIndex, cLowBuffer, INDICATOR_DATA); + + // + // Short ... + + // + // Color ... + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(sBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(sBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(sColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(sOpenBuffer, true); + PlotIndexSetInteger(sOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sOpenBufferIndex, sOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(sHighBuffer, true); + PlotIndexSetInteger(sHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sHighBufferIndex, sHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(sCloseBuffer, true); + PlotIndexSetInteger(sCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sCloseBufferIndex, sCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(sLowBuffer, true); + PlotIndexSetInteger(sLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sLowBufferIndex, sLowBuffer, INDICATOR_DATA); + + // + // Medium ... + + // + // Color ... + ArraySetAsSeries(mColorBuffer, true); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(mBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(mBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(mColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(mOpenBuffer, true); + PlotIndexSetInteger(mOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mOpenBufferIndex, mOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(mHighBuffer, true); + PlotIndexSetInteger(mHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mHighBufferIndex, mHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(mCloseBuffer, true); + PlotIndexSetInteger(mCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mCloseBufferIndex, mCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(mLowBuffer, true); + PlotIndexSetInteger(mLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mLowBufferIndex, mLowBuffer, INDICATOR_DATA); + + // + // Long ... + + // + // Color ... + ArraySetAsSeries(lColorBuffer, true); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(lBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(lBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(lColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(lOpenBuffer, true); + PlotIndexSetInteger(lOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lOpenBufferIndex, lOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(lHighBuffer, true); + PlotIndexSetInteger(lHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lHighBufferIndex, lHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(lCloseBuffer, true); + PlotIndexSetInteger(lCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lCloseBufferIndex, lCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(lLowBuffer, true); + PlotIndexSetInteger(lLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lLowBufferIndex, lLowBuffer, INDICATOR_DATA); + + // + // Hind ... + + // + // Color ... + ArraySetAsSeries(hColorBuffer, true); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(hBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(hBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(hColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(hOpenBuffer, true); + PlotIndexSetInteger(hOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hOpenBufferIndex, hOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(hHighBuffer, true); + PlotIndexSetInteger(hHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hHighBufferIndex, hHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(hCloseBuffer, true); + PlotIndexSetInteger(hCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hCloseBufferIndex, hCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(hLowBuffer, true); + PlotIndexSetInteger(hLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hLowBufferIndex, hLowBuffer, INDICATOR_DATA); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Hiken Ashi ... +void CalculateHK( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + double mPrevHKOpenValue; + double mPrevHKCloseValue; + + // + if (ArraySize(open) <= bar_index + 1) + { + // + mPrevHKOpenValue = 0; + mPrevHKCloseValue = 0; + } + else + { + // + mPrevHKOpenValue = openBuffer[bar_index + 1]; + mPrevHKCloseValue = closeBuffer[bar_index + 1]; + } + + // + double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2; + double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4; + double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue)); + double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue)); + + // + openBuffer[bar_index] = mHKOpenValue; + highBuffer[bar_index] = mHKHighValue; + lowBuffer[bar_index] = mHKLowValue; + closeBuffer[bar_index] = mHKCloseValue; +} + +// +void CalculateCycles( + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Current ... + CalculateCycle( + cOpenBuffer, + cHighBuffer, + cLowBuffer, + cCloseBuffer, + cColorBuffer, + mCSMLength, + showCurrent, + ratesTotal, + prevCalculated // + ); + + // + // Short ... + CalculateCycle( + sOpenBuffer, + sHighBuffer, + sLowBuffer, + sCloseBuffer, + sColorBuffer, + mSSMLength, + showShort, + ratesTotal, + prevCalculated // + ); + + // + // Medium ... + CalculateCycle( + mOpenBuffer, + mHighBuffer, + mLowBuffer, + mCloseBuffer, + mColorBuffer, + mMSMLength, + showMedium, + ratesTotal, + prevCalculated // + ); + + // + // Long ... + CalculateCycle( + lOpenBuffer, + lHighBuffer, + lLowBuffer, + lCloseBuffer, + lColorBuffer, + mLSMLength, + showLong, + ratesTotal, + prevCalculated // + ); + + // + // Hind ... + CalculateCycle( + hOpenBuffer, + hHighBuffer, + hLowBuffer, + hCloseBuffer, + hColorBuffer, + mHSMLength, + showHind, + ratesTotal, + prevCalculated // + ); +} + +// +void CalculateCycle( + double &open[], + double &high[], + double &low[], + double &close[], + double &clr[], // Color Index Buffer + int length, // Calculation Length + bool show, // Show or not + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Open ... + int calculatedSMOpens = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + openBuffer, + open // + ); + + // + // Close ... + int calculatedSMCloses = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + closeBuffer, + close // + ); + + // + int calculatedSMLows = 0; + int calculatedSMHighs = 0; + if (!ignoreShadows) + { + // + // High ... + calculatedSMHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + highBuffer, + high // + ); + + // + // Low ... + calculatedSMLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + lowBuffer, + low // + ); + } + else + { + // + // High ... + calculatedSMHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + openBuffer, + high // + ); + + // + // Low ... + calculatedSMLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + closeBuffer, + low // + ); + } + + // + // Find Calculated Items for Colors Calculations ... + int mNumberOfItems = MathMin(calculatedSMOpens, calculatedSMHighs); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMLows); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMCloses); + + // + // Create a Loop for Color of Candles ... + for (int i = 0; i < mNumberOfItems; i++) + { + // + bool isBearish = + // + open[i] > close[i] + // + ; + + // + if (show) + { + // + clr[i] = isBearish + ? bearishColorIDX + : bullishColorIDX; + } + else + { + // + clr[i] = hideColorIDX; + } + } +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchich.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchich.ex5 new file mode 100644 index 0000000..ca1469a Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchich.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchich.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchich.mq5 new file mode 100644 index 0000000..f468e31 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchich.mq5 @@ -0,0 +1,1826 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHICH +// Description: Ichimoku Kinko Hyo on Cycles ... +// +// +// 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 XCHICH Indicator" +#property strict + +// +#define ShortName "XCHICH" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Ichimoku Lines Calculator Mode ... +enum ENUM_X_ICHIMOKU_CALCULATION_MODE +{ + // + X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low + X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close +}; + +// +// Inputs ... + +// +input group "Market"; + +// +// TENKANSEN ... +input group "Tenkan Sen"; +input int tenkanSenLength = 9; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// KIJUNSEN ... +input group "Kijun Sen"; +input int kijunSenLength = 26; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// SENKOUSPANB ... +input group "Senkou Span B"; +input int senkouSpanBLength = 52; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// CHIKOUSPAN ... +input group "Chikou Span"; +input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Presentation"; + +// +input bool showTenkanSen = true; // Show Tenkan Sen +input bool showKijunSen = true; // Show Kijun Sen +input bool showChikouSpan = true; // Show Chikou Span +input bool showSenkouSpanA = true; // Show Senkou Span A +input bool showSenkouSpanB = true; // Show Senkou Span B +input bool showKumo = true; // Show Kumo +input bool shiftKumo = true; // Shift Kumo to Future + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 40 +#property indicator_plots 30 + +// +// CURRENT ... + +// +#define cTenBufferIndex 0 +double cTenBuffer[]; + +// +#property indicator_label1 "XICH C TK" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrBrown +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +#define cKijBufferIndex 1 +double cKijBuffer[]; + +// +#property indicator_label2 "XICH C KJ" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrDodgerBlue +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +#define cChikBufferIndex 2 +double cChikBuffer[]; + +// +#property indicator_label3 "XICH C CS" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrDarkGreen +#property indicator_style3 STYLE_SOLID +#property indicator_width3 1 + +// +#define cSSABufferIndex 3 +double cSSABuffer[]; + +// +#property indicator_label4 "XICH C SSA" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrLightGray +#property indicator_style4 STYLE_DASHDOTDOT +#property indicator_width4 1 + +// +#define cSSBBufferIndex 4 +double cSSBBuffer[]; + +// +#property indicator_label5 "XICH C SSB" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLightGray +#property indicator_style5 STYLE_DASHDOTDOT +#property indicator_width5 1 + +// +// SHORT ... + +// +#define sTenBufferIndex 5 +double sTenBuffer[]; + +// +#property indicator_label6 "XICH S TK" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrBrown +#property indicator_style6 STYLE_SOLID +#property indicator_width6 1 + +// +#define sKijBufferIndex 6 +double sKijBuffer[]; + +// +#property indicator_label7 "XICH S KJ" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrDodgerBlue +#property indicator_style7 STYLE_SOLID +#property indicator_width7 1 + +// +#define sChikBufferIndex 7 +double sChikBuffer[]; + +// +#property indicator_label8 "XICH S CS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrDarkGreen +#property indicator_style8 STYLE_SOLID +#property indicator_width8 1 + +// +#define sSSABufferIndex 8 +double sSSABuffer[]; + +// +#property indicator_label9 "XICH S SSA" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLightGray +#property indicator_style9 STYLE_DASHDOTDOT +#property indicator_width9 1 + +// +#define sSSBBufferIndex 9 +double sSSBBuffer[]; + +// +#property indicator_label10 "XICH S SSB" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrLightGray +#property indicator_style10 STYLE_DASHDOTDOT +#property indicator_width10 1 + +// +// MEDIUM ... + +// +#define mTenBufferIndex 10 +double mTenBuffer[]; + +// +#property indicator_label11 "XICH M TK" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrBrown +#property indicator_style11 STYLE_SOLID +#property indicator_width11 1 + +// +#define mKijBufferIndex 11 +double mKijBuffer[]; + +// +#property indicator_label12 "XICH M KJ" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrDodgerBlue +#property indicator_style12 STYLE_SOLID +#property indicator_width12 1 + +// +#define mChikBufferIndex 12 +double mChikBuffer[]; + +// +#property indicator_label13 "XICH M CS" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkGreen +#property indicator_style13 STYLE_SOLID +#property indicator_width13 1 + +// +#define mSSABufferIndex 13 +double mSSABuffer[]; + +// +#property indicator_label14 "XICH M SSA" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrLightGray +#property indicator_style14 STYLE_DASHDOTDOT +#property indicator_width14 1 + +// +#define mSSBBufferIndex 14 +double mSSBBuffer[]; + +// +#property indicator_label15 "XICH M SSB" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrLightGray +#property indicator_style15 STYLE_DASHDOTDOT +#property indicator_width15 1 + +// +// LONG ... + +// +#define lTenBufferIndex 15 +double lTenBuffer[]; + +// +#property indicator_label16 "XICH L TK" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrBrown +#property indicator_style16 STYLE_SOLID +#property indicator_width16 1 + +// +#define lKijBufferIndex 16 +double lKijBuffer[]; + +// +#property indicator_label17 "XICH L KJ" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrDodgerBlue +#property indicator_style17 STYLE_SOLID +#property indicator_width17 1 + +// +#define lChikBufferIndex 17 +double lChikBuffer[]; + +// +#property indicator_label18 "XICH L CS" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrDarkGreen +#property indicator_style18 STYLE_SOLID +#property indicator_width18 1 + +// +#define lSSABufferIndex 18 +double lSSABuffer[]; + +// +#property indicator_label19 "XICH L SSA" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrLightGray +#property indicator_style19 STYLE_DASHDOTDOT +#property indicator_width19 1 + +// +#define lSSBBufferIndex 19 +double lSSBBuffer[]; + +// +#property indicator_label20 "XICH L SSB" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrLightGray +#property indicator_style20 STYLE_DASHDOTDOT +#property indicator_width20 1 + +// +// HIND ... + +// +#define hTenBufferIndex 20 +double hTenBuffer[]; + +// +#property indicator_label21 "XICH H TK" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrBrown +#property indicator_style21 STYLE_SOLID +#property indicator_width21 1 + +// +#define hKijBufferIndex 21 +double hKijBuffer[]; + +// +#property indicator_label22 "XICH H KJ" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDodgerBlue +#property indicator_style22 STYLE_SOLID +#property indicator_width22 1 + +// +#define hChikBufferIndex 22 +double hChikBuffer[]; + +// +#property indicator_label23 "XICH H CS" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrDarkGreen +#property indicator_style23 STYLE_SOLID +#property indicator_width23 1 + +// +#define hSSABufferIndex 23 +double hSSABuffer[]; + +// +#property indicator_label24 "XICH H SSA" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrLightGray +#property indicator_style24 STYLE_DASHDOTDOT +#property indicator_width24 1 + +// +#define hSSBBufferIndex 24 +double hSSBBuffer[]; + +// +#property indicator_label25 "XICH H SSB" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrLightGray +#property indicator_style25 STYLE_DASHDOTDOT +#property indicator_width25 1 + +// +// +// + +// +// CURRENT ... + +// +#define cSSAKCBufferIndex 25 +double cSSAKCBuffer[]; + +// +#define cSSBKCBufferIndex 26 +double cSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define cKCBufferIndex 25 + +// +#property indicator_label26 "XICH C Kumo" +#property indicator_type26 DRAW_FILLING +#property indicator_color26 clrAqua, clrMagenta +#property indicator_style26 STYLE_SOLID +#property indicator_width26 1 + +// +// SHORT ... + +// +#define sSSAKCBufferIndex 27 +double sSSAKCBuffer[]; + +// +#define sSSBKCBufferIndex 28 +double sSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define sKCBufferIndex 26 + +// +#property indicator_label27 "XICH S Kumo" +#property indicator_type27 DRAW_FILLING +#property indicator_color27 clrAqua, clrMagenta +#property indicator_style27 STYLE_SOLID +#property indicator_width27 1 + +// +// MEDIUM ... + +// +#define mSSAKCBufferIndex 29 +double mSSAKCBuffer[]; + +// +#define mSSBKCBufferIndex 30 +double mSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define mKCBufferIndex 27 + +// +#property indicator_label28 "XICH M Kumo" +#property indicator_type28 DRAW_FILLING +#property indicator_color28 clrAqua, clrMagenta +#property indicator_style28 STYLE_SOLID +#property indicator_width28 1 + +// +// LONG ... + +// +#define lSSAKCBufferIndex 31 +double lSSAKCBuffer[]; + +// +#define lSSBKCBufferIndex 32 +double lSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define lKCBufferIndex 28 + +// +#property indicator_label29 "XICH L Kumo" +#property indicator_type29 DRAW_FILLING +#property indicator_color29 clrAqua, clrMagenta +#property indicator_style29 STYLE_SOLID +#property indicator_width29 1 + +// +// HIND ... + +// +#define hSSAKCBufferIndex 33 +double hSSAKCBuffer[]; + +// +#define hSSBKCBufferIndex 34 +double hSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define hKCBufferIndex 29 + +// +#property indicator_label30 "XICH H Kumo" +#property indicator_type30 DRAW_FILLING +#property indicator_color30 clrAqua, clrMagenta +#property indicator_style30 STYLE_SOLID +#property indicator_width30 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCTenkanSenLength = tenkanSenLength; +int mCKijunSenLength = kijunSenLength; +int mCSenkouSpanBLength = senkouSpanBLength; + +// +// Short ... +int mSCycleLength = 0; +int mSTenkanSenLength = 0; +int mSKijunSenLength = 0; +int mSSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMTenkanSenLength = 0; +int mMKijunSenLength = 0; +int mMSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLTenkanSenLength = 0; +int mLKijunSenLength = 0; +int mLSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHTenkanSenLength = 0; +int mHKijunSenLength = 0; +int mHSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +ENUM_SERIESMODE mTenkanSenTopMode = NULL; +ENUM_SERIESMODE mTenkanSenBottomMode = NULL; + +// +ENUM_SERIESMODE mKijunSenTopMode = NULL; +ENUM_SERIESMODE mKijunSenBottomMode = NULL; + +// +ENUM_SERIESMODE mSenkouSpanBTopMode = NULL; +ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // 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); + + // + // this counts Available Bars ... + int limit; + + // + 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 ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + (tenkanSenLength > 2 && + kijunSenLength > tenkanSenLength && + senkouSpanBLength > kijunSenLength) + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSTenkanSenLength = mSCycleLength * mCTenkanSenLength; + mSKijunSenLength = mSCycleLength * mCKijunSenLength; + mSSenkouSpanBLength = mSCycleLength * mCSenkouSpanBLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMTenkanSenLength = mMCycleLength * mCTenkanSenLength; + mMKijunSenLength = mMCycleLength * mCKijunSenLength; + mMSenkouSpanBLength = mMCycleLength * mCSenkouSpanBLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLTenkanSenLength = mLCycleLength * mCTenkanSenLength; + mLKijunSenLength = mLCycleLength * mCKijunSenLength; + mLSenkouSpanBLength = mLCycleLength * mCSenkouSpanBLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHTenkanSenLength = mHCycleLength * mCTenkanSenLength; + mHKijunSenLength = mHCycleLength * mCKijunSenLength; + mHSenkouSpanBLength = mHCycleLength * mCSenkouSpanBLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(mCTenkanSenLength, mCKijunSenLength); + result = MathMax(result, mCSenkouSpanBLength); + + // + // Short ... + result = MathMax(mSTenkanSenLength, mSKijunSenLength); + result = MathMax(result, mSSenkouSpanBLength); + + // + // Medium ... + result = MathMax(mMTenkanSenLength, mMKijunSenLength); + result = MathMax(result, mMSenkouSpanBLength); + + // + // Long ... + result = MathMax(mLTenkanSenLength, mLKijunSenLength); + result = MathMax(result, mLSenkouSpanBLength); + + // + // Hind ... + result = MathMax(mHTenkanSenLength, mHKijunSenLength); + result = MathMax(result, mHSenkouSpanBLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // TENKANSEN ... + + // + bool canCShowTenkanSen = showTenkanSen && showCurrent; + ENUM_DRAW_TYPE cTenkanSenDrawType = canCShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cTenBuffer, true); + SetIndexBuffer(cTenBufferIndex, cTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cTenBufferIndex, PLOT_SHOW_DATA, canCShowTenkanSen); + PlotIndexSetInteger(cTenBufferIndex, PLOT_DRAW_TYPE, cTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canCShowKijunSen = showKijunSen && showCurrent; + ENUM_DRAW_TYPE cKijunSenDrawType = canCShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cKijBuffer, true); + SetIndexBuffer(cKijBufferIndex, cKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cKijBufferIndex, PLOT_SHOW_DATA, canCShowKijunSen); + PlotIndexSetInteger(cKijBufferIndex, PLOT_DRAW_TYPE, cKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canCShowChikouSpan = showChikouSpan && showCurrent; + ENUM_DRAW_TYPE cChikouSpanDrawType = canCShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cChikBuffer, true); + SetIndexBuffer(cChikBufferIndex, cChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cChikBufferIndex, PLOT_SHIFT, -mCKijunSenLength); + PlotIndexSetInteger(cChikBufferIndex, PLOT_SHOW_DATA, canCShowChikouSpan); + PlotIndexSetInteger(cChikBufferIndex, PLOT_DRAW_TYPE, cChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int cShiftSize = shiftKumo ? mCKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canCShowSenkouSpanA = showSenkouSpanA && showCurrent; + ENUM_DRAW_TYPE cSenkouSpanADrawType = canCShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cSSABuffer, true); + SetIndexBuffer(cSSABufferIndex, cSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSABufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cSSABufferIndex, PLOT_SHOW_DATA, canCShowSenkouSpanA); + PlotIndexSetInteger(cSSABufferIndex, PLOT_DRAW_TYPE, cSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canCShowSenkouSpanB = showSenkouSpanB && showCurrent; + ENUM_DRAW_TYPE cSenkouSpanBDrawType = canCShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cSSBBuffer, true); + SetIndexBuffer(cSSBBufferIndex, cSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_SHOW_DATA, canCShowSenkouSpanB); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_DRAW_TYPE, cSenkouSpanBDrawType); + + // + // Short ... + + // + // TENKANSEN ... + + // + bool canSShowTenkanSen = showTenkanSen && showShort; + ENUM_DRAW_TYPE sTenkanSenDrawType = canSShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sTenBuffer, true); + SetIndexBuffer(sTenBufferIndex, sTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sTenBufferIndex, PLOT_SHOW_DATA, canSShowTenkanSen); + PlotIndexSetInteger(sTenBufferIndex, PLOT_DRAW_TYPE, sTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canSShowKijunSen = showKijunSen && showShort; + ENUM_DRAW_TYPE sKijunSenDrawType = canSShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sKijBuffer, true); + SetIndexBuffer(sKijBufferIndex, sKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sKijBufferIndex, PLOT_SHOW_DATA, canSShowKijunSen); + PlotIndexSetInteger(sKijBufferIndex, PLOT_DRAW_TYPE, sKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canSShowChikouSpan = showChikouSpan && showShort; + ENUM_DRAW_TYPE sChikouSpanDrawType = canSShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sChikBuffer, true); + SetIndexBuffer(sChikBufferIndex, sChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sChikBufferIndex, PLOT_SHIFT, -mSKijunSenLength); + PlotIndexSetInteger(sChikBufferIndex, PLOT_SHOW_DATA, canSShowChikouSpan); + PlotIndexSetInteger(sChikBufferIndex, PLOT_DRAW_TYPE, sChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int sShiftSize = shiftKumo ? mSKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canSShowSenkouSpanA = showSenkouSpanA && showShort; + ENUM_DRAW_TYPE sSenkouSpanADrawType = canSShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sSSABuffer, true); + SetIndexBuffer(sSSABufferIndex, sSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSABufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sSSABufferIndex, PLOT_SHOW_DATA, canSShowSenkouSpanA); + PlotIndexSetInteger(sSSABufferIndex, PLOT_DRAW_TYPE, sSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canSShowSenkouSpanB = showSenkouSpanB && showShort; + ENUM_DRAW_TYPE sSenkouSpanBDrawType = canSShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sSSBBuffer, true); + SetIndexBuffer(sSSBBufferIndex, sSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_SHOW_DATA, canSShowSenkouSpanB); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_DRAW_TYPE, sSenkouSpanBDrawType); + + // + // Medium ... + + // + // TENKANSEN ... + + // + bool canMShowTenkanSen = showTenkanSen && showMedium; + ENUM_DRAW_TYPE mTenkanSenDrawType = canMShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mTenBuffer, true); + SetIndexBuffer(mTenBufferIndex, mTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mTenBufferIndex, PLOT_SHOW_DATA, canMShowTenkanSen); + PlotIndexSetInteger(mTenBufferIndex, PLOT_DRAW_TYPE, mTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canMShowKijunSen = showKijunSen && showMedium; + ENUM_DRAW_TYPE mKijunSenDrawType = canMShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mKijBuffer, true); + SetIndexBuffer(mKijBufferIndex, mKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mKijBufferIndex, PLOT_SHOW_DATA, canMShowKijunSen); + PlotIndexSetInteger(mKijBufferIndex, PLOT_DRAW_TYPE, mKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canMShowChikouSpan = showChikouSpan && showMedium; + ENUM_DRAW_TYPE mChikouSpanDrawType = canMShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mChikBuffer, true); + SetIndexBuffer(mChikBufferIndex, mChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mChikBufferIndex, PLOT_SHIFT, -mMKijunSenLength); + PlotIndexSetInteger(mChikBufferIndex, PLOT_SHOW_DATA, canMShowChikouSpan); + PlotIndexSetInteger(mChikBufferIndex, PLOT_DRAW_TYPE, mChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int mShiftSize = shiftKumo ? mMKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canMShowSenkouSpanA = showSenkouSpanA && showMedium; + ENUM_DRAW_TYPE mSenkouSpanADrawType = canMShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mSSABuffer, true); + SetIndexBuffer(mSSABufferIndex, mSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSABufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mSSABufferIndex, PLOT_SHOW_DATA, canMShowSenkouSpanA); + PlotIndexSetInteger(mSSABufferIndex, PLOT_DRAW_TYPE, mSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canMShowSenkouSpanB = showSenkouSpanB && showMedium; + ENUM_DRAW_TYPE mSenkouSpanBDrawType = canMShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mSSBBuffer, true); + SetIndexBuffer(mSSBBufferIndex, mSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_SHOW_DATA, canMShowSenkouSpanB); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_DRAW_TYPE, mSenkouSpanBDrawType); + + // + // Long ... + + // + // TENKANSEN ... + + // + bool canLShowTenkanSen = showTenkanSen && showLong; + ENUM_DRAW_TYPE lTenkanSenDrawType = canLShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lTenBuffer, true); + SetIndexBuffer(lTenBufferIndex, lTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lTenBufferIndex, PLOT_SHOW_DATA, canLShowTenkanSen); + PlotIndexSetInteger(lTenBufferIndex, PLOT_DRAW_TYPE, lTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canLShowKijunSen = showKijunSen && showLong; + ENUM_DRAW_TYPE lKijunSenDrawType = canLShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lKijBuffer, true); + SetIndexBuffer(lKijBufferIndex, lKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lKijBufferIndex, PLOT_SHOW_DATA, canLShowKijunSen); + PlotIndexSetInteger(lKijBufferIndex, PLOT_DRAW_TYPE, lKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canLShowChikouSpan = showChikouSpan && showLong; + ENUM_DRAW_TYPE lChikouSpanDrawType = canLShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lChikBuffer, true); + SetIndexBuffer(lChikBufferIndex, lChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lChikBufferIndex, PLOT_SHIFT, -mLKijunSenLength); + PlotIndexSetInteger(lChikBufferIndex, PLOT_SHOW_DATA, canLShowChikouSpan); + PlotIndexSetInteger(lChikBufferIndex, PLOT_DRAW_TYPE, lChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int lShiftSize = shiftKumo ? mLKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canLShowSenkouSpanA = showSenkouSpanA && showLong; + ENUM_DRAW_TYPE lSenkouSpanADrawType = canLShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lSSABuffer, true); + SetIndexBuffer(lSSABufferIndex, lSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSABufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lSSABufferIndex, PLOT_SHOW_DATA, canLShowSenkouSpanA); + PlotIndexSetInteger(lSSABufferIndex, PLOT_DRAW_TYPE, lSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canLShowSenkouSpanB = showSenkouSpanB && showLong; + ENUM_DRAW_TYPE lSenkouSpanBDrawType = canLShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lSSBBuffer, true); + SetIndexBuffer(lSSBBufferIndex, lSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_SHOW_DATA, canLShowSenkouSpanB); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_DRAW_TYPE, lSenkouSpanBDrawType); + + // + // Hind ... + + // + // TENKANSEN ... + + // + bool canHShowTenkanSen = showTenkanSen && showHind; + ENUM_DRAW_TYPE hTenkanSenDrawType = canHShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hTenBuffer, true); + SetIndexBuffer(hTenBufferIndex, hTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hTenBufferIndex, PLOT_SHOW_DATA, canHShowTenkanSen); + PlotIndexSetInteger(hTenBufferIndex, PLOT_DRAW_TYPE, hTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canHShowKijunSen = showKijunSen && showHind; + ENUM_DRAW_TYPE hKijunSenDrawType = canHShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hKijBuffer, true); + SetIndexBuffer(hKijBufferIndex, hKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hKijBufferIndex, PLOT_SHOW_DATA, canHShowKijunSen); + PlotIndexSetInteger(hKijBufferIndex, PLOT_DRAW_TYPE, hKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canHShowChikouSpan = showChikouSpan && showHind; + ENUM_DRAW_TYPE hChikouSpanDrawType = canHShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hChikBuffer, true); + SetIndexBuffer(hChikBufferIndex, hChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hChikBufferIndex, PLOT_SHIFT, -mHKijunSenLength); + PlotIndexSetInteger(hChikBufferIndex, PLOT_SHOW_DATA, canHShowChikouSpan); + PlotIndexSetInteger(hChikBufferIndex, PLOT_DRAW_TYPE, hChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int hShiftSize = shiftKumo ? mHKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canHShowSenkouSpanA = showSenkouSpanA && showHind; + ENUM_DRAW_TYPE hSenkouSpanADrawType = canHShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hSSABuffer, true); + SetIndexBuffer(hSSABufferIndex, hSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSABufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hSSABufferIndex, PLOT_SHOW_DATA, canHShowSenkouSpanA); + PlotIndexSetInteger(hSSABufferIndex, PLOT_DRAW_TYPE, hSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canHShowSenkouSpanB = showSenkouSpanB && showHind; + ENUM_DRAW_TYPE hSenkouSpanBDrawType = canHShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hSSBBuffer, true); + SetIndexBuffer(hSSBBufferIndex, hSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_SHOW_DATA, canHShowSenkouSpanB); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_DRAW_TYPE, hSenkouSpanBDrawType); + + // + // Here we Create KUMO CLOUD Buffers ... + + // + // int lastBufferIndex = hSSBBufferIndex; + + // + // Current ... + bool cCanShowKumo = showKumo && showCurrent; + ENUM_DRAW_TYPE cKumoDrawType = cCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(cSSAKCBuffer, true); + SetIndexBuffer(cSSAKCBufferIndex, cSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(cSSBKCBuffer, true); + SetIndexBuffer(cSSBKCBufferIndex, cSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(cKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(cKCBufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cKCBufferIndex, PLOT_DRAW_TYPE, cKumoDrawType); + + // + // Short ... + bool sCanShowKumo = showKumo && showShort; + ENUM_DRAW_TYPE sKumoDrawType = sCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(sSSAKCBuffer, true); + SetIndexBuffer(sSSAKCBufferIndex, sSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(sSSBKCBuffer, true); + SetIndexBuffer(sSSBKCBufferIndex, sSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(sKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(sKCBufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sKCBufferIndex, PLOT_DRAW_TYPE, sKumoDrawType); + + // + // Medium ... + bool mCanShowKumo = showKumo && showMedium; + ENUM_DRAW_TYPE mKumoDrawType = mCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(mSSAKCBuffer, true); + SetIndexBuffer(mSSAKCBufferIndex, mSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(mSSBKCBuffer, true); + SetIndexBuffer(mSSBKCBufferIndex, mSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(mKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(mKCBufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mKCBufferIndex, PLOT_DRAW_TYPE, mKumoDrawType); + + // + // Long ... + bool lCanShowKumo = showKumo && showLong; + ENUM_DRAW_TYPE lKumoDrawType = lCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(lSSAKCBuffer, true); + SetIndexBuffer(lSSAKCBufferIndex, lSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(lSSBKCBuffer, true); + SetIndexBuffer(lSSBKCBufferIndex, lSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(lKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(lKCBufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lKCBufferIndex, PLOT_DRAW_TYPE, lKumoDrawType); + + // + // Hind ... + bool hCanShowKumo = showKumo && showHind; + ENUM_DRAW_TYPE hKumoDrawType = hCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(hSSAKCBuffer, true); + SetIndexBuffer(hSSAKCBufferIndex, hSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(hSSBKCBuffer, true); + SetIndexBuffer(hSSBKCBufferIndex, hSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(hKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(hKCBufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hKCBufferIndex, PLOT_DRAW_TYPE, hKumoDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mCTenkanSenLength, + mCKijunSenLength, + mCSenkouSpanBLength, + // + cTenBuffer, + cKijBuffer, + cChikBuffer, + cSSABuffer, + cSSBBuffer, + cSSAKCBuffer, + cSSBKCBuffer + // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSTenkanSenLength, + mSKijunSenLength, + mSSenkouSpanBLength, + // + sTenBuffer, + sKijBuffer, + sChikBuffer, + sSSABuffer, + sSSBBuffer, + sSSAKCBuffer, + sSSBKCBuffer + // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMTenkanSenLength, + mMKijunSenLength, + mMSenkouSpanBLength, + // + mTenBuffer, + mKijBuffer, + mChikBuffer, + mSSABuffer, + mSSBBuffer, + mSSAKCBuffer, + mSSBKCBuffer + // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLTenkanSenLength, + mLKijunSenLength, + mLSenkouSpanBLength, + // + lTenBuffer, + lKijBuffer, + lChikBuffer, + lSSABuffer, + lSSBBuffer, + lSSAKCBuffer, + lSSBKCBuffer + // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHTenkanSenLength, + mHKijunSenLength, + mHSenkouSpanBLength, + // + hTenBuffer, + hKijBuffer, + hChikBuffer, + hSSABuffer, + hSSBBuffer, + hSSAKCBuffer, + hSSBKCBuffer + // + ); +} + +// +void CalculateCycle( + 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 _tenkanSenLength, + int _kijunSenLength, + int _senkouSpanBLength, + // + double &_tenkanSenBuffer[], + double &_kijunSenBuffer[], + double &_chikouSpanBuffer[], + double &_senkouABuffer[], + double &_senkouBBuffer[], + double &_cloudSenkouSpanABuffer[], + double &_cloudSenkouSpanBBuffer[] + // +) +{ + // + double topValue; + double bottomValue; + + // + // TENKANSEN ... + + // + // Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ... + if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL) + { + // + switch (tenkanSenMode) + { + // + case X_XICH_HH_LL_MODE: + // + mTenkanSenTopMode = MODE_HIGH; + mTenkanSenBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mTenkanSenTopMode = MODE_OPEN; + mTenkanSenBottomMode = MODE_CLOSE; + break; + } + } + + // + XOHCL bar; + bar.Init( + _Symbol, + _Period, + bar_index + // + ); + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _tenkanSenLength, + mTenkanSenTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _tenkanSenLength, + mTenkanSenBottomMode + // + ); + + // + double tenkanSenValue = (topValue + bottomValue) / 2; + _tenkanSenBuffer[bar_index] = tenkanSenValue; + + // + // KIJUNSEN ... + + // + // Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ... + if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL) + { + // + switch (kijunSenMode) + { + // + case X_XICH_HH_LL_MODE: + // + mKijunSenTopMode = MODE_HIGH; + mKijunSenBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mKijunSenTopMode = MODE_OPEN; + mKijunSenBottomMode = MODE_CLOSE; + break; + } + } + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _kijunSenLength, + mKijunSenTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _kijunSenLength, + mKijunSenBottomMode + // + ); + + // + double kijunSenValue = (topValue + bottomValue) / 2; + _kijunSenBuffer[bar_index] = kijunSenValue; + + // + // CHIKOUSPAN ... + double chikouSpanValue = bar + .GetPrice(chikuoSpanAppliedTo); + + // + _chikouSpanBuffer[bar_index] = chikouSpanValue; + + // + // KUMO ... + + // + // SENKOUSPANA ... + double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2; + _senkouABuffer[bar_index] = senkouSpanAValue; + _cloudSenkouSpanABuffer[bar_index] = senkouSpanAValue; + + // + // SENKOUSPANB ... + + // + // Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ... + if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL) + { + // + switch (senkouSpanBMode) + { + // + case X_XICH_HH_LL_MODE: + // + mSenkouSpanBTopMode = MODE_HIGH; + mSenkouSpanBBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mSenkouSpanBTopMode = MODE_OPEN; + mSenkouSpanBBottomMode = MODE_CLOSE; + break; + } + } + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _senkouSpanBLength, + mSenkouSpanBTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _senkouSpanBLength, + mSenkouSpanBBottomMode + // + ); + + // + double senkouSpanBValue = (topValue + bottomValue) / 2; + _senkouBBuffer[bar_index] = senkouSpanBValue; + _cloudSenkouSpanBBuffer[bar_index] = senkouSpanBValue; + + // +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchm.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchm.ex5 new file mode 100644 index 0000000..f028f43 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchm.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchm.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchm.mq5 new file mode 100644 index 0000000..5ca1078 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchm.mq5 @@ -0,0 +1,1086 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHM +// Description: XCHMrend Detector ... +// +// 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 XCHM Indicator" +#property strict + +// +#define ShortName "XCHM" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input int fastLength = 9; // Fast Length +input int slowLength = 18; // Slow Length +input ENUM_MA_METHOD method = MODE_SMA; // Mode +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// AVG ... +input bool showFast = true; // Show Fast +input bool showSlow = true; // Show Slow + +// +// Current ... +input bool showCCFast = true; // Show Current Cycle Fast +input bool showCCSlow = true; // Show Current Cycle Slow +// +// Short ... +input bool showSCFast = true; // Show Short Cycle Fast +input bool showSCSlow = true; // Show Short Cycle Slow +// +// Medium ... +input bool showMCFast = true; // Show Medium Cycle Fast +input bool showMCSlow = true; // Show Medium Cycle Slow +// +// Long ... +input bool showLCFast = true; // Show Long Cycle Fast +input bool showLCSlow = true; // Show Long Cycle Slow +// +// Hind ... +input bool showHCFast = true; // Show Hind Cycle Fast +input bool showHCSlow = true; // Show Hind Cycle Slow + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 12 +#property indicator_plots 12 + +// +// AVG ... + +// +// Fast ... +#define avgFastBufferIndex 0 +double avgFastBuffer[]; + +// +#property indicator_label1 "XCHM AF" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Slow ... +#define avgSlowBufferIndex 1 +double avgSlowBuffer[]; + +// +#property indicator_label2 "XCHM AS" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Current ... + +// +// Fast ... +#define cFastBufferIndex 2 +double cFastBuffer[]; + +// +#property indicator_label3 "XCHM CF" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Slow ... +#define cSlowBufferIndex 3 +double cSlowBuffer[]; + +// +#property indicator_label4 "XCHM CS" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Short ... + +// +// Fast ... +#define sFastBufferIndex 4 +double sFastBuffer[]; + +// +#property indicator_label5 "XCHM SF" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrAqua +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Slow ... +#define sSlowBufferIndex 5 +double sSlowBuffer[]; + +// +#property indicator_label6 "XCHM SS" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrMagenta +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Medium ... + +// +// Fast ... +#define mFastBufferIndex 6 +double mFastBuffer[]; + +// +#property indicator_label7 "XCHM MF" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrAqua +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +// Slow ... +#define mSlowBufferIndex 7 +double mSlowBuffer[]; + +// +#property indicator_label8 "XCHM MS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrMagenta +#property indicator_style8 STYLE_DOT +#property indicator_width8 1 + +// +// Long ... + +// +// Fast ... +#define lFastBufferIndex 8 +double lFastBuffer[]; + +// +#property indicator_label9 "XCHM LF" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrAqua +#property indicator_style9 STYLE_DOT +#property indicator_width9 1 + +// +// Slow ... +#define lSlowBufferIndex 9 +double lSlowBuffer[]; + +// +#property indicator_label10 "XCHM LS" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +// +// Hind ... + +// +// Fast ... +#define hFastBufferIndex 10 +double hFastBuffer[]; + +// +#property indicator_label11 "XCHM HF" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAqua +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +// Slow ... +#define hSlowBufferIndex 11 +double hSlowBuffer[]; + +// +#property indicator_label12 "XCHM HS" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +// Variables ... + +// +int maxLength; + +// +// Current ... +int cFastHandler = INVALID_HANDLE; +int cSlowHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSCFastLength = 0; +int mSCSlowLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +int sFastHandler = INVALID_HANDLE; +int sSlowHandler = INVALID_HANDLE; + +// +// Medium ... +int mMCLength = 0; +int mMCFastLength = 0; +int mMCSlowLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +int mFastHandler = INVALID_HANDLE; +int mSlowHandler = INVALID_HANDLE; + +// +// Long ... +int mLCLength = 0; +int mLCFastLength = 0; +int mLCSlowLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +int lFastHandler = INVALID_HANDLE; +int lSlowHandler = INVALID_HANDLE; + +// +// Hind ... +int mHCLength = 0; +int mHCFastLength = 0; +int mHCSlowLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +int hFastHandler = INVALID_HANDLE; +int hSlowHandler = INVALID_HANDLE; + +// +// EVENT Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 + + // + // Current ... + IndicatorRelease(cFastHandler); + IndicatorRelease(cSlowHandler); + + // + // Short ... + IndicatorRelease(sFastHandler); + IndicatorRelease(sSlowHandler); + + // + // Medium ... + IndicatorRelease(mFastHandler); + IndicatorRelease(mSlowHandler); + + // + // Long ... + IndicatorRelease(lFastHandler); + IndicatorRelease(lSlowHandler); + + // + // Hind ... + IndicatorRelease(hFastHandler); + IndicatorRelease(hSlowHandler); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(low, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(close, true); + + // + // this counts Available Bars ... + int limit; + + // + // Validate Calculated Bars ... + bool isPassedRequiredCalculatedBars = + // + // Current ... + BarsCalculated(cFastHandler) >= maxLength && + BarsCalculated(cSlowHandler) >= maxLength && + // + // Short ... + BarsCalculated(sFastHandler) >= maxLength && + BarsCalculated(sSlowHandler) >= maxLength && + // + // Medium ... + BarsCalculated(mFastHandler) >= maxLength && + BarsCalculated(mSlowHandler) >= maxLength && + // + // Long ... + BarsCalculated(lFastHandler) >= maxLength && + BarsCalculated(lSlowHandler) >= maxLength && + // + // Hind ... + BarsCalculated(hFastHandler) >= maxLength && + BarsCalculated(hSlowHandler) >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = + (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + // Current ... + int copiedCFasts = CopyBuffer(cFastHandler, 0, 0, limit, cFastBuffer); + int copiedCSlows = CopyBuffer(cSlowHandler, 0, 0, limit, cSlowBuffer); + + // + // Short ... + int copiedSFasts = CopyBuffer(sFastHandler, 0, 0, limit, sFastBuffer); + int copiedSSlows = CopyBuffer(sSlowHandler, 0, 0, limit, sSlowBuffer); + + // + // Medium ... + int copiedMFasts = CopyBuffer(mFastHandler, 0, 0, limit, mFastBuffer); + int copiedMSlows = CopyBuffer(mSlowHandler, 0, 0, limit, mSlowBuffer); + + // + // Long ... + int copiedLFasts = CopyBuffer(lFastHandler, 0, 0, limit, lFastBuffer); + int copiedLSlows = CopyBuffer(lSlowHandler, 0, 0, limit, lSlowBuffer); + + // + // Hind ... + int copiedHFasts = CopyBuffer(hFastHandler, 0, 0, limit, hFastBuffer); + int copiedHSlows = CopyBuffer(hSlowHandler, 0, 0, limit, hSlowBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // + // Current ... + copiedCFasts > 0 && + copiedCSlows > 0 && + // + // Short ... + copiedSFasts > 0 && + copiedSSlows > 0 && + // + // Medium ... + copiedMFasts > 0 && + copiedMSlows > 0 && + // + // Long ... + copiedLFasts > 0 && + copiedLSlows > 0 && + // + // Hind ... + copiedHFasts > 0 && + copiedHSlows > 0 + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// CUSTOM Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + fastLength > 2 && + slowLength > fastLength && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(fastLength, slowLength); + + // + // Short ... + result = MathMax(result, mSCFastLength); + result = MathMax(result, mSCSlowLength); + + // + // Medium ... + result = MathMax(result, mMCFastLength); + result = MathMax(result, mMCSlowLength); + + // + // Long ... + result = MathMax(result, mLCFastLength); + result = MathMax(result, mLCSlowLength); + + // + // Hind ... + result = MathMax(result, mHCFastLength); + result = MathMax(result, mHCSlowLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // AVG ... + + // + // Fast ... + ENUM_DRAW_TYPE avgFastDrawType = showFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgFastBuffer, true); + SetIndexBuffer(avgFastBufferIndex, avgFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_SHOW_DATA, showFast); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_TYPE, avgFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE avgSlowDrawType = showSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgSlowBuffer, true); + SetIndexBuffer(avgSlowBufferIndex, avgSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_SHOW_DATA, showSlow); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_TYPE, avgSlowDrawType); + + // + // Current ... + + // + // Fast ... + ENUM_DRAW_TYPE cFastDrawType = showCCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cFastBuffer, true); + SetIndexBuffer(cFastBufferIndex, cFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cFastBufferIndex, PLOT_SHOW_DATA, showCCFast); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_TYPE, cFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE cSlowDrawType = showCCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cSlowBuffer, true); + SetIndexBuffer(cSlowBufferIndex, cSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_SHOW_DATA, showCCSlow); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_TYPE, cSlowDrawType); + + // + // Short ... + + // + // Fast ... + ENUM_DRAW_TYPE sFastDrawType = showSCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sFastBuffer, true); + SetIndexBuffer(sFastBufferIndex, sFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sFastBufferIndex, PLOT_SHOW_DATA, showSCFast); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_TYPE, sFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE sSlowDrawType = showSCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sSlowBuffer, true); + SetIndexBuffer(sSlowBufferIndex, sSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_SHOW_DATA, showSCSlow); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_TYPE, sSlowDrawType); + + // + // Medium ... + + // + // Fast ... + ENUM_DRAW_TYPE mFastDrawType = showMCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mFastBuffer, true); + SetIndexBuffer(mFastBufferIndex, mFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mFastBufferIndex, PLOT_SHOW_DATA, showMCFast); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_TYPE, mFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE mSlowDrawType = showMCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mSlowBuffer, true); + SetIndexBuffer(mSlowBufferIndex, mSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_SHOW_DATA, showMCSlow); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_TYPE, mSlowDrawType); + + // + // Long ... + + // + // Fast ... + ENUM_DRAW_TYPE lFastDrawType = showLCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lFastBuffer, true); + SetIndexBuffer(lFastBufferIndex, lFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lFastBufferIndex, PLOT_SHOW_DATA, showLCFast); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_TYPE, lFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE lSlowDrawType = showLCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lSlowBuffer, true); + SetIndexBuffer(lSlowBufferIndex, lSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_SHOW_DATA, showLCSlow); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_TYPE, lSlowDrawType); + + // + // Hind ... + + // + // Fast ... + ENUM_DRAW_TYPE hFastDrawType = showHCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hFastBuffer, true); + SetIndexBuffer(hFastBufferIndex, hFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hFastBufferIndex, PLOT_SHOW_DATA, showHCFast); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_TYPE, hFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE hSlowDrawType = showHCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hSlowBuffer, true); + SetIndexBuffer(hSlowBufferIndex, hSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_SHOW_DATA, showHCSlow); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_TYPE, hSlowDrawType); +} + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Initialize Handlers ... + cFastHandler = iMA( + _Symbol, + _Period, + fastLength, + 0, + method, + appliedTo // + ); + cSlowHandler = iMA( + _Symbol, + _Period, + slowLength, + 0, + method, + appliedTo // + ); + result = + // + cFastHandler != INVALID_HANDLE && + cSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSCFastLength = fastLength * mSCLength; + mSCSlowLength = slowLength * mSCLength; + + // + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + sFastHandler = iMA( + _Symbol, + _Period, + mSCFastLength, + 0, + method, + appliedTo // + ); + sSlowHandler = iMA( + _Symbol, + _Period, + mSCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + sFastHandler != INVALID_HANDLE && + sSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMCFastLength = fastLength * mMCLength; + mMCSlowLength = slowLength * mMCLength; + + // + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + mFastHandler = iMA( + _Symbol, + _Period, + mMCFastLength, + 0, + method, + appliedTo // + ); + mSlowHandler = iMA( + _Symbol, + _Period, + mMCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + mFastHandler != INVALID_HANDLE && + mSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLCFastLength = fastLength * mLCLength; + mLCSlowLength = slowLength * mLCLength; + + // + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + lFastHandler = iMA( + _Symbol, + _Period, + mLCFastLength, + 0, + method, + appliedTo // + ); + lSlowHandler = iMA( + _Symbol, + _Period, + mLCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + lFastHandler != INVALID_HANDLE && + lSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHCFastLength = fastLength * mHCLength; + mHCSlowLength = slowLength * mHCLength; + + // + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + hFastHandler = iMA( + _Symbol, + _Period, + mHCFastLength, + 0, + method, + appliedTo // + ); + hSlowHandler = iMA( + _Symbol, + _Period, + mHCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + hFastHandler != INVALID_HANDLE && + hSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Do all Custom Calculations ... +void CalculateBuffers(int barIndex) +{ + // + double cFast = cFastBuffer[barIndex]; + double sFast = sFastBuffer[barIndex]; + double mFast = mFastBuffer[barIndex]; + double lFast = lFastBuffer[barIndex]; + double hFast = hFastBuffer[barIndex]; + + // + double fast = + cFast + + sFast + + mFast + + lFast + + hFast; + avgFastBuffer[barIndex] = fast / 5; + + // + double cSlow = cSlowBuffer[barIndex]; + double sSlow = sSlowBuffer[barIndex]; + double mSlow = mSlowBuffer[barIndex]; + double lSlow = lSlowBuffer[barIndex]; + double hSlow = hSlowBuffer[barIndex]; + + // + double slow = + cSlow + + sSlow + + mSlow + + lSlow + + hSlow; + avgSlowBuffer[barIndex] = slow / 5; +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchstr.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchstr.ex5 new file mode 100644 index 0000000..717b1a6 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchstr.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchstr.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchstr.mq5 new file mode 100644 index 0000000..b67b000 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchstr.mq5 @@ -0,0 +1,1246 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHSTR +// Description: Smoothed HikenAshi Cycles ... +// +// 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 XCHSTR Indicator" +#property strict + +// +#define ShortName "XCHSTR" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; + +// +input int atrLength = 14; // Length +input double atrMultiplier = 3.0; // Multiplier +input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 35 +#property indicator_plots 10 + +// +// Current ... + +// +#define cBufferIndex 0 +#define cPlotBufferIndex 0 +double cBuffer[]; + +// +#define cColorBufferIndex 1 +double cColorBuffer[]; + +// +#property indicator_label1 "C XSTR" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style1 STYLE_DOT + +// +// Short ... + +// +#define sBufferIndex 2 +#define sPlotBufferIndex 1 +double sBuffer[]; + +// +#define sColorBufferIndex 3 +double sColorBuffer[]; + +// +#property indicator_label2 "S XSTR" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style2 STYLE_DOT + +// +// Medium ... + +// +#define mBufferIndex 4 +#define mPlotBufferIndex 2 +double mBuffer[]; + +// +#define mColorBufferIndex 5 +double mColorBuffer[]; + +// +#property indicator_label3 "M XSTR" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style3 STYLE_DOT + +// +// Long ... + +// +#define lBufferIndex 6 +#define lPlotBufferIndex 3 +double lBuffer[]; + +// +#define lColorBufferIndex 7 +double lColorBuffer[]; + +// +#property indicator_label4 "L XSTR" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style4 STYLE_DOT + +// +// Hind ... + +// +#define hBufferIndex 8 +#define hPlotBufferIndex 4 +double hBuffer[]; + +// +#define hColorBufferIndex 9 +double hColorBuffer[]; + +// +#property indicator_label5 "H XSTR" +#property indicator_type5 DRAW_COLOR_LINE +#property indicator_color5 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style5 STYLE_DOT + +// +// Data Buffers ... + +// +// Current ... + +// +#define cAtrBufferIndex 10 +double cAtrBuffer[]; + +// +#define cTrendBufferIndex 11 +double cTrendBuffer[]; + +// +#define cUpBufferIndex 12 +double cUpBuffer[]; + +// +#define cDownBufferIndex 13 +double cDownBuffer[]; + +// +#define cPriceBufferIndex 14 +double cPriceBuffer[]; + +// +// Short ... + +// +#define sAtrBufferIndex 15 +double sAtrBuffer[]; + +// +#define sTrendBufferIndex 16 +double sTrendBuffer[]; + +// +#define sUpBufferIndex 17 +double sUpBuffer[]; + +// +#define sDownBufferIndex 18 +double sDownBuffer[]; + +// +#define sPriceBufferIndex 19 +double sPriceBuffer[]; + +// +// Medium ... + +// +#define mAtrBufferIndex 20 +double mAtrBuffer[]; + +// +#define mTrendBufferIndex 21 +double mTrendBuffer[]; + +// +#define mUpBufferIndex 22 +double mUpBuffer[]; + +// +#define mDownBufferIndex 23 +double mDownBuffer[]; + +// +#define mPriceBufferIndex 24 +double mPriceBuffer[]; + +// +// Long ... + +// +#define lAtrBufferIndex 25 +double lAtrBuffer[]; + +// +#define lTrendBufferIndex 26 +double lTrendBuffer[]; + +// +#define lUpBufferIndex 27 +double lUpBuffer[]; + +// +#define lDownBufferIndex 28 +double lDownBuffer[]; + +// +#define lPriceBufferIndex 29 +double lPriceBuffer[]; + +// +// Hind ... + +// +#define hAtrBufferIndex 30 +double hAtrBuffer[]; + +// +#define hTrendBufferIndex 31 +double hTrendBuffer[]; + +// +#define hUpBufferIndex 32 +double hUpBuffer[]; + +// +#define hDownBufferIndex 33 +double hDownBuffer[]; + +// +#define hPriceBufferIndex 34 +double hPriceBuffer[]; + +// +// Variables, Properties and etc ... + +// +int changeOfTrend; +int startBearishTrend; +int startBullishTrend; + +// +int maxLength; + +// +// Current ... +int mCSMLength = atrLength; +int mCAtrHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +int mSAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +int mMAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +int mLAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +int mHAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + int numOfRequiredAtrs; + if (prev_calculated > rates_total || prev_calculated < 0) + { + numOfRequiredAtrs = rates_total; + } + else + { + // + numOfRequiredAtrs = rates_total - prev_calculated; + if (prev_calculated > 0) + { + numOfRequiredAtrs++; + } + } + + // + // Checking for stop ... + if (IsStopped()) + { + return 0; + } + + // + // Check Number of items Copy or not ... + int copiedCATRs = CopyBuffer(mCAtrHandler, 0, 0, numOfRequiredAtrs, cAtrBuffer); + int copiedSATRs = CopyBuffer(mSAtrHandler, 0, 0, numOfRequiredAtrs, sAtrBuffer); + int copiedMATRs = CopyBuffer(mMAtrHandler, 0, 0, numOfRequiredAtrs, mAtrBuffer); + int copiedLATRs = CopyBuffer(mLAtrHandler, 0, 0, numOfRequiredAtrs, lAtrBuffer); + int copiedHATRs = CopyBuffer(mHAtrHandler, 0, 0, numOfRequiredAtrs, hAtrBuffer); + if (copiedCATRs <= 0 || + copiedSATRs <= 0 || + copiedMATRs <= 0 || + copiedLATRs <= 0 || + copiedHATRs <= 0) + { + return 0; + } + + // + int limit; + + // + // checking for the limit start of calculation of an indicator ... + if (prev_calculated > rates_total || prev_calculated <= 0) + { + // + // starting index for calculation of all bars ... + limit = maxLength; + } + else + { + // + // starting number for calculation of new bars + limit = prev_calculated - 1; + } + + // + // Main Loop ... + for (int i = limit; i < rates_total && !IsStopped(); i++) + { + // + CalculateBuffers( + open, + high, + low, + close, + i // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + atrLength >= 2 && + atrMultiplier > 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + mCAtrHandler = iATR( + _Symbol, + _Period, + mCSMLength // + ); + result = mCAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + mSAtrHandler = iATR( + _Symbol, + _Period, + mSSMLength // + ); + result = mSAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + mMAtrHandler = iATR( + _Symbol, + _Period, + mMSMLength // + ); + result = mMAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + mLAtrHandler = iATR( + _Symbol, + _Period, + mLSMLength // + ); + result = mLAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + mHAtrHandler = iATR( + _Symbol, + _Period, + mHSMLength // + ); + result = mHAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT Cycle ... + + // + // STR ... + SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(cPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(cAtrBufferIndex, cAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(cPriceBufferIndex, cPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(cTrendBufferIndex, cTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(cUpBufferIndex, cUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(cDownBufferIndex, cDownBuffer, INDICATOR_CALCULATIONS); + + // + // SHORT Cycle ... + + // + // STR ... + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(sPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(sAtrBufferIndex, sAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(sPriceBufferIndex, sPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(sTrendBufferIndex, sTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(sUpBufferIndex, sUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(sDownBufferIndex, sDownBuffer, INDICATOR_CALCULATIONS); + + // + // MEDIUM Cycle ... + + // + // STR ... + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(mPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(mAtrBufferIndex, mAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(mPriceBufferIndex, mPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(mTrendBufferIndex, mTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(mUpBufferIndex, mUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(mDownBufferIndex, mDownBuffer, INDICATOR_CALCULATIONS); + + // + // LONG Cycle ... + + // + // STR ... + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(lPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(lAtrBufferIndex, lAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(lPriceBufferIndex, lPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(lTrendBufferIndex, lTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(lUpBufferIndex, lUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(lDownBufferIndex, lDownBuffer, INDICATOR_CALCULATIONS); + + // + // HIND Cycle ... + + // + // STR ... + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(hPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(hAtrBufferIndex, hAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(hPriceBufferIndex, hPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(hTrendBufferIndex, hTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(hUpBufferIndex, hUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(hDownBufferIndex, hDownBuffer, INDICATOR_CALCULATIONS); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Hiken Ashi ... +void CalculateBuffers( + const double &open[], + const double &high[], + const double &low[], + const double &close[], + int barIndex // +) +{ + // + // Current ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + cAtrBuffer, + cPriceBuffer, + cUpBuffer, + cDownBuffer, + cTrendBuffer, + cBuffer, + cColorBuffer, + showCurrent // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + sAtrBuffer, + sPriceBuffer, + sUpBuffer, + sDownBuffer, + sTrendBuffer, + sBuffer, + sColorBuffer, + showShort // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + mAtrBuffer, + mPriceBuffer, + mUpBuffer, + mDownBuffer, + mTrendBuffer, + mBuffer, + mColorBuffer, + showMedium // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + lAtrBuffer, + lPriceBuffer, + lUpBuffer, + lDownBuffer, + lTrendBuffer, + lBuffer, + lColorBuffer, + showLong // + ); + + // + // Hind ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + hAtrBuffer, + hPriceBuffer, + hUpBuffer, + hDownBuffer, + hTrendBuffer, + hBuffer, + hColorBuffer, + showHind // + ); +} + +// +void CalculateCycle( + const double &open[], + const double &high[], + const double &low[], + const double &close[], + int barIndex, + double &atr[], + double &price[], + double &up[], + double &down[], + double &trend[], + double &main[], + double &clr[], // Color Index Buffer + bool show // +) +{ + // + // Calculated Price ... + double _price = getPrice( + atrAppliedTo, + open, + high, + low, + close, + barIndex // + ); + price[barIndex] = _price; + + // + double _atr = atr[barIndex]; + + // + // Up ... + up[barIndex] = _price + (atrMultiplier * _atr); + + // + // Down ... + down[barIndex] = _price - (atrMultiplier * _atr); + + // + if (close[barIndex] > up[barIndex - 1]) + { + // + trend[barIndex] = 1; + if (trend[barIndex - 1] == -1) + { + changeOfTrend = 1; + } + } + else if (close[barIndex] < down[barIndex - 1]) + { + // + trend[barIndex] = -1; + if (trend[barIndex - 1] == 1) + { + changeOfTrend = 1; + } + } + else if (trend[barIndex - 1] == 1) + { + // + trend[barIndex] = 1; + changeOfTrend = 0; + } + else if (trend[barIndex - 1] == -1) + { + // + trend[barIndex] = -1; + changeOfTrend = 0; + } + + // + // Down Trend Starting ... + if (trend[barIndex] < 0 && trend[barIndex - 1] > 0) + { + startBearishTrend = 1; + } + else + { + startBearishTrend = 0; + } + + // + // Up Trend Starting ... + if (trend[barIndex] > 0 && trend[barIndex - 1] < 0) + { + startBullishTrend = 1; + } + else + { + startBullishTrend = 0; + } + + // + if (trend[barIndex] > 0 && down[barIndex] < down[barIndex - 1]) + { + down[barIndex] = down[barIndex - 1]; + } + + // + if (trend[barIndex] < 0 && up[barIndex] > up[barIndex - 1]) + { + up[barIndex] = up[barIndex - 1]; + } + + // + if (startBearishTrend == 1) + { + up[barIndex] = price[barIndex] + (atrMultiplier * _atr); + } + + // + if (startBullishTrend == 1) + { + down[barIndex] = price[barIndex] - (atrMultiplier * _atr); + } + + // + double colorIDX = hideColorIDX; + clr[barIndex] = colorIDX; + + // + if (trend[barIndex] == 1) + { + // + main[barIndex] = down[barIndex]; + if (changeOfTrend == 1) + { + // + main[barIndex - 1] = main[barIndex - 2]; + changeOfTrend = 0; + } + + // + colorIDX = bullishColorIDX; + } + else if (trend[barIndex] == -1) + { + // + main[barIndex] = up[barIndex]; + if (changeOfTrend == 1) + { + // + main[barIndex - 1] = main[barIndex - 2]; + changeOfTrend = 0; + } + + // + colorIDX = bearishColorIDX; + } + + // + if (show) + { + clr[barIndex] = colorIDX; + } + + // +} + +// +// TEMPLATE Function ... + +template +double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i) +{ + switch (tprice) + { + case PRICE_CLOSE: + return (close[i]); + case PRICE_OPEN: + return (open[i]); + case PRICE_HIGH: + return (high[i]); + case PRICE_LOW: + return (low[i]); + case PRICE_MEDIAN: + return ((high[i] + low[i]) / 2.0); + case PRICE_TYPICAL: + return ((high[i] + low[i] + close[i]) / 3.0); + case PRICE_WEIGHTED: + return ((high[i] + low[i] + close[i] + close[i]) / 4.0); + } + return (0); +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchswings.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchswings.ex5 new file mode 100644 index 0000000..aa7b1a2 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchswings.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchswings.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchswings.mq5 new file mode 100644 index 0000000..15c5c4f --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchswings.mq5 @@ -0,0 +1,993 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHSwings +// Description: XCHSwings Detector ... +// +// 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 XCHVWAP Indicator" +#property strict + +// +#define ShortName "XCHVWAP" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input int length = 12; // Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; +// +input bool showSwingHighs = true; // Show Swing Highs +input bool showSwingLows = true; // Show Swing Lows +// +input bool showCurrent = true; // Show Cycle Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 10 + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +// Current ... + +// +#define cSHBufferIndex 0 +double cSHBuffer[]; + +// +#property indicator_label1 "XCHVSwings CH" +#property indicator_type1 DRAW_ARROW +#property indicator_color1 clrMagenta +#property indicator_style1 STYLE_SOLID +#property indicator_width1 2 + +// +#define cSLBufferIndex 1 +double cSLBuffer[]; + +// +#property indicator_label2 "XCHVSwings CL" +#property indicator_type2 DRAW_ARROW +#property indicator_color2 clrAqua +#property indicator_style2 STYLE_SOLID +#property indicator_width2 2 + +// +// Short ... + +// +#define sSHBufferIndex 2 +double sSHBuffer[]; + +// +#property indicator_label3 "XCHVSwings SH" +#property indicator_type3 DRAW_ARROW +#property indicator_color3 clrMagenta +#property indicator_style3 STYLE_SOLID +#property indicator_width3 2 + +// +#define sSLBufferIndex 3 +double sSLBuffer[]; + +// +#property indicator_label4 "XCHVSwings SL" +#property indicator_type4 DRAW_ARROW +#property indicator_color4 clrAqua +#property indicator_style4 STYLE_SOLID +#property indicator_width4 2 + +// +// Medium ... + +// +#define mSHBufferIndex 4 +double mSHBuffer[]; + +// +#property indicator_label5 "XCHVSwings MH" +#property indicator_type5 DRAW_ARROW +#property indicator_color5 clrMagenta +#property indicator_style5 STYLE_SOLID +#property indicator_width5 2 + +// +#define mSLBufferIndex 5 +double mSLBuffer[]; + +// +#property indicator_label6 "XCHVSwings ML" +#property indicator_type6 DRAW_ARROW +#property indicator_color6 clrAqua +#property indicator_style6 STYLE_SOLID +#property indicator_width6 2 + +// +// Long ... + +// +#define lSHBufferIndex 6 +double lSHBuffer[]; + +// +#property indicator_label7 "XCHVSwings LH" +#property indicator_type7 DRAW_ARROW +#property indicator_color7 clrMagenta +#property indicator_style7 STYLE_SOLID +#property indicator_width7 2 + +// +#define lSLBufferIndex 7 +double lSLBuffer[]; + +// +#property indicator_label8 "XCHVSwings LL" +#property indicator_type8 DRAW_ARROW +#property indicator_color8 clrAqua +#property indicator_style8 STYLE_SOLID +#property indicator_width8 2 + +// +// Hind ... + +// +#define hSHBufferIndex 8 +double hSHBuffer[]; + +// +#property indicator_label9 "XCHVSwings HH" +#property indicator_type9 DRAW_ARROW +#property indicator_color9 clrMagenta +#property indicator_style9 STYLE_SOLID +#property indicator_width9 2 + +// +#define hSLBufferIndex 9 +double hSLBuffer[]; + +// +#property indicator_label10 "XCHVSwings HL" +#property indicator_type10 DRAW_ARROW +#property indicator_color10 clrAqua +#property indicator_style10 STYLE_SOLID +#property indicator_width10 2 + +// +// Variables ... + +// +int maxLength; + +// +// Cuurent ... +int mCMarketLength = length; + +// +double cH1 = 0; +double cL1 = 0; +datetime cH1Time = 0; +datetime cL1Time = 0; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +double sH1 = 0; +double sL1 = 0; +datetime sH1Time = 0; +datetime sL1Time = 0; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +double mH1 = 0; +double mL1 = 0; +datetime mH1Time = 0; +datetime mL1Time = 0; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +double lH1 = 0; +double lL1 = 0; +datetime lH1Time = 0; +datetime lL1Time = 0; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +double hH1 = 0; +double hL1 = 0; +datetime hH1Time = 0; +datetime hL1Time = 0; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + int start; + + // + if (prev_calculated == 0) + { + start = maxLength; + } + else + { + start = prev_calculated - 1; + } + + // + for (int i = start; i < rates_total - maxLength && !IsStopped(); i++) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + time, + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + + // Setting Indicator Digits + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + ENUM_DRAW_TYPE cSHDrawType = + showCurrent && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(cSHBufferIndex, cSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(cSHBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingHighs); + PlotIndexSetInteger(cSHBufferIndex, PLOT_DRAW_TYPE, cSHDrawType); + + // + ENUM_DRAW_TYPE cSLDrawType = + showCurrent && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(cSLBufferIndex, cSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(cSLBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingLows); + PlotIndexSetInteger(cSLBufferIndex, PLOT_DRAW_TYPE, cSLDrawType); + + // + // Short ... + + // + ENUM_DRAW_TYPE sSHDrawType = + showShort && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(sSHBufferIndex, sSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(sSHBufferIndex, PLOT_SHOW_DATA, showShort && showSwingHighs); + PlotIndexSetInteger(sSHBufferIndex, PLOT_DRAW_TYPE, sSHDrawType); + + // + ENUM_DRAW_TYPE sSLDrawType = + showShort && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(sSLBufferIndex, sSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(sSLBufferIndex, PLOT_SHOW_DATA, showShort && showSwingLows); + PlotIndexSetInteger(sSLBufferIndex, PLOT_DRAW_TYPE, sSLDrawType); + + // + // Medium ... + + // + ENUM_DRAW_TYPE mSHDrawType = + showMedium && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(mSHBufferIndex, mSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(mSHBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingHighs); + PlotIndexSetInteger(mSHBufferIndex, PLOT_DRAW_TYPE, mSHDrawType); + + // + ENUM_DRAW_TYPE mSLDrawType = + showMedium && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(mSLBufferIndex, mSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(mSLBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingLows); + PlotIndexSetInteger(mSLBufferIndex, PLOT_DRAW_TYPE, mSLDrawType); + + // + // Long ... + + // + ENUM_DRAW_TYPE lSHDrawType = + showLong && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(lSHBufferIndex, lSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(lSHBufferIndex, PLOT_SHOW_DATA, showLong && showSwingHighs); + PlotIndexSetInteger(lSHBufferIndex, PLOT_DRAW_TYPE, lSHDrawType); + + // + ENUM_DRAW_TYPE lSLDrawType = + showLong && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(lSLBufferIndex, lSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(lSLBufferIndex, PLOT_SHOW_DATA, showLong && showSwingLows); + PlotIndexSetInteger(lSLBufferIndex, PLOT_DRAW_TYPE, lSLDrawType); + + // + // Hind ... + + // + ENUM_DRAW_TYPE hSHDrawType = + showHind && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(hSHBufferIndex, hSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(hSHBufferIndex, PLOT_SHOW_DATA, showHind && showSwingHighs); + PlotIndexSetInteger(hSHBufferIndex, PLOT_DRAW_TYPE, hSHDrawType); + + // + ENUM_DRAW_TYPE hSLDrawType = + showHind && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(hSLBufferIndex, hSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(hSLBufferIndex, PLOT_SHOW_DATA, showHind && showSwingLows); + PlotIndexSetInteger(hSLBufferIndex, PLOT_DRAW_TYPE, hSLDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const datetime &time[], + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateCycles( + // + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const datetime &time[], + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cSHBuffer, + cSLBuffer, + cH1, + cH1Time, + cL1, + cL1Time // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sSHBuffer, + sSLBuffer, + sH1, + sH1Time, + sL1, + sL1Time // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mSHBuffer, + mSLBuffer, + mH1, + mH1Time, + mL1, + mL1Time // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lSHBuffer, + lSLBuffer, + lH1, + lH1Time, + lL1, + lL1Time // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hSHBuffer, + hSLBuffer, + hH1, + hH1Time, + hL1, + hL1Time // + ); +} + +// +void CalculateCycle( + // + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const datetime &time[], + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, // Calculation Length + bool _show, + double &_hBuffer[], + double &_lBuffer[], + double &_h1, + datetime &_h1Time, + double &_l1, + datetime &_l1Time // +) +{ + // + bool isSwingHigh = true; + bool isSwingLow = true; + + // + _hBuffer[bar_index] = 0; + _lBuffer[bar_index] = 0; + + // + // Check for Swing High + for (int j = 1; j <= _length; j++) + { + // + if (high[bar_index] <= high[bar_index + j] || high[bar_index] <= high[bar_index - j]) + { + // + isSwingHigh = false; + break; + } + } + + // + // Check for Swing Low + for (int j = 1; j <= _length; j++) + { + // + if (low[bar_index] >= low[bar_index + j] || low[bar_index] >= low[bar_index - j]) + { + // + isSwingLow = false; + break; + } + } + + // + if (isSwingHigh) + { + // + _hBuffer[bar_index] = high[bar_index]; + if (high[bar_index] > _h1 || _h1 == 0) + { + // + _h1 = high[bar_index]; + _h1Time = time[bar_index]; + } + } + + // + if (isSwingLow) + { + // + _lBuffer[bar_index] = low[bar_index]; + if (low[bar_index] < _l1 || _l1 == 0) + { + // + _l1 = low[bar_index]; + _l1Time = time[bar_index]; + } + } +} \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchtd.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchtd.ex5 new file mode 100644 index 0000000..fdd3e05 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchtd.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchtd.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchtd.mq5 new file mode 100644 index 0000000..86ec2b5 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchtd.mq5 @@ -0,0 +1,900 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHTD +// Description: XCHTD Cycles ... +// +// 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 XCHTD Indicator" +#property strict + +// +#define ShortName "XCHTD" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +enum ENUM_XCHTD_MODE +{ + XCHTD_POWER_MODE = 0, // Using Power + XCHTD_PRESSURE_MODE = 1, // Using Pressure + XCHTD_TYPE_MODE = 2, // Using Type + XCHTD_STRONG_MODE = 3, // Using Power and Pressures +}; + +// +// Inputs ... + +// +input group "Market"; +input int length = 14; // Length +input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// Current ... +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 0 + +// +// Current ... + +// +#define cBullBufferIndex 0 +double cBullBuffer[]; + +// +#property indicator_label1 "XCHTD C Bull" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID + +// +#define cBearBufferIndex 1 +double cBearBuffer[]; + +// +#property indicator_label2 "XCHTD C Bear" +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_SOLID +#property indicator_color2 clrRed + +// +// Short ... + +// +#define sBullBufferIndex 2 +double sBullBuffer[]; + +// +#property indicator_label3 "XCHTD S Bull" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrLime +#property indicator_style3 STYLE_SOLID + +// +#define sBearBufferIndex 3 +double sBearBuffer[]; + +// +#property indicator_label4 "XCHTD S Bear" +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_SOLID +#property indicator_color4 clrRed + +// +// Medium ... + +// +#define mBullBufferIndex 4 +double mBullBuffer[]; + +// +#property indicator_label5 "XCHTD M Bull" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLime +#property indicator_style5 STYLE_SOLID + +// +#define mBearBufferIndex 5 +double mBearBuffer[]; + +// +#property indicator_label6 "XCHTD M Bear" +#property indicator_type6 DRAW_LINE +#property indicator_style6 STYLE_SOLID +#property indicator_color6 clrRed + +// +// Long ... + +// +#define lBullBufferIndex 6 +double lBullBuffer[]; + +// +#property indicator_label7 "XCHTD L Bull" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrLime +#property indicator_style7 STYLE_SOLID + +// +#define lBearBufferIndex 7 +double lBearBuffer[]; + +// +#property indicator_label8 "XCHTD L Bear" +#property indicator_type8 DRAW_LINE +#property indicator_style8 STYLE_SOLID +#property indicator_color8 clrRed + +// +// Hind ... + +// +#define hBullBufferIndex 8 +double hBullBuffer[]; + +// +#property indicator_label9 "XCHTD H Bull" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLime +#property indicator_style9 STYLE_SOLID + +// +#define hBearBufferIndex 9 +double hBearBuffer[]; + +// +#property indicator_label10 "XCHTD H Bear" +#property indicator_type10 DRAW_LINE +#property indicator_style10 STYLE_SOLID +#property indicator_color10 clrRed + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // 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); + + // + // this counts Available Bars ... + int limit; + + // + // 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 ... + + // + limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated; + + // + // Main Loop ... + for (int i = limit; 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 ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cBullBuffer, true); + SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType); + // PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + ArraySetAsSeries(cBearBuffer, true); + SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType); + // PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + // Short ... + + // + // ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sBullBuffer, true); + SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType); + // PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort); + + // + ArraySetAsSeries(sBearBuffer, true); + SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType); + // PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort); + + // + // Medium ... + + // + // ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mBullBuffer, true); + SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType); + // PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + ArraySetAsSeries(mBearBuffer, true); + SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType); + // PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + // Long ... + + // + // ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lBullBuffer, true); + SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType); + // PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong); + + // + ArraySetAsSeries(lBearBuffer, true); + SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType); + // PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong); + + // + // Hind ... + + // + // ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hBullBuffer, true); + SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType); + // PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind); + + // + ArraySetAsSeries(hBearBuffer, true); + SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType); + // PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cBullBuffer, + cBearBuffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sBullBuffer, + sBearBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mBullBuffer, + mBearBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lBullBuffer, + lBearBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hBullBuffer, + hBearBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, // Calculation Length + bool _show, + double &_bull[], + double &_bear[] // +) +{ + // + double bullPower = 0; + double bearPower = 0; + + // + double lowShadow = 0; + double highShadow = 0; + + // + double bullPressure = 0; + double bearPressure = 0; + + // + double bullRange = 0; + double bearRange = 0; + + // + for (int i = bar_index; i < bar_index + _length; i++) + { + // + bool isBullish = + // + close[i] > open[i] + // + ; + + // + bool isBearish = + // + close[i] < open[i] + // + ; + + // + double iUpper = MathMax(open[i], close[i]); + double iLower = MathMin(open[i], close[i]); + + // + double iBody = iUpper - iLower; + double iRange = high[i] - low[i]; + + // + double iHighShadow = high[i] - iUpper; + double iLowShadow = iLower - low[i]; + + // + if (isBullish) + { + // + bullPower += iBody; + bullRange += iRange; + bearPressure += iHighShadow; + } + else if (isBearish) + { + // + bearPower += iBody; + bearRange += iRange; + bullPressure += iLowShadow; + } + + // + lowShadow += iLowShadow; + highShadow += iHighShadow; + } + + // + if (mode == XCHTD_POWER_MODE) + { + // + _bull[bar_index] = bullPower; + _bear[bar_index] = bearPower; + } + else if (mode == XCHTD_PRESSURE_MODE) + { + // + _bull[bar_index] = bullPressure; + _bear[bar_index] = bearPressure; + } + else if (mode == XCHTD_TYPE_MODE) + { + // + _bull[bar_index] = bullRange; + _bear[bar_index] = bearRange; + } + else if (mode == XCHTD_STRONG_MODE) + { + // + _bull[bar_index] = bullPower + bullPressure; + _bear[bar_index] = bearPower + bearPressure; + } +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchtd.osc.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchtd.osc.ex5 new file mode 100644 index 0000000..37e86f6 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchtd.osc.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchtd.osc.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchtd.osc.mq5 new file mode 100644 index 0000000..8b30a6e --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchtd.osc.mq5 @@ -0,0 +1,898 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHTD +// Description: XCHTD Cycles ... +// +// 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 XCHTD Indicator" +#property strict + +// +#define ShortName "XCHTD" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +enum ENUM_XCHTD_MODE +{ + XCHTD_POWER_MODE = 0, // Using Power + XCHTD_PRESSURE_MODE = 1, // Using Pressure + XCHTD_TYPE_MODE = 2, // Using Type + XCHTD_STRONG_MODE = 3, // Using Power and Pressures +}; + +// +// Inputs ... + +// +input group "Market"; +input int length = 14; // Length +input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// Current ... +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_separate_window + +// +#property indicator_buffers 10 +#property indicator_plots 10 + +// +// Current ... + +// +#define cBullBufferIndex 0 +double cBullBuffer[]; + +// +#property indicator_label1 "XCHTD C Bull" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID + +// +#define cBearBufferIndex 1 +double cBearBuffer[]; + +// +#property indicator_label2 "XCHTD C Bear" +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_SOLID +#property indicator_color2 clrRed + +// +// Short ... + +// +#define sBullBufferIndex 2 +double sBullBuffer[]; + +// +#property indicator_label3 "XCHTD S Bull" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrLime +#property indicator_style3 STYLE_SOLID + +// +#define sBearBufferIndex 3 +double sBearBuffer[]; + +// +#property indicator_label4 "XCHTD S Bear" +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_SOLID +#property indicator_color4 clrRed + +// +// Medium ... + +// +#define mBullBufferIndex 4 +double mBullBuffer[]; + +// +#property indicator_label5 "XCHTD M Bull" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLime +#property indicator_style5 STYLE_SOLID + +// +#define mBearBufferIndex 5 +double mBearBuffer[]; + +// +#property indicator_label6 "XCHTD M Bear" +#property indicator_type6 DRAW_LINE +#property indicator_style6 STYLE_SOLID +#property indicator_color6 clrRed + +// +// Long ... + +// +#define lBullBufferIndex 6 +double lBullBuffer[]; + +// +#property indicator_label7 "XCHTD L Bull" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrLime +#property indicator_style7 STYLE_SOLID + +// +#define lBearBufferIndex 7 +double lBearBuffer[]; + +// +#property indicator_label8 "XCHTD L Bear" +#property indicator_type8 DRAW_LINE +#property indicator_style8 STYLE_SOLID +#property indicator_color8 clrRed + +// +// Hind ... + +// +#define hBullBufferIndex 8 +double hBullBuffer[]; + +// +#property indicator_label9 "XCHTD H Bull" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLime +#property indicator_style9 STYLE_SOLID + +// +#define hBearBufferIndex 9 +double hBearBuffer[]; + +// +#property indicator_label10 "XCHTD H Bear" +#property indicator_type10 DRAW_LINE +#property indicator_style10 STYLE_SOLID +#property indicator_color10 clrRed + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // 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); + + // + // this counts Available Bars ... + int limit; + + // + // 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 ... + + // + limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated; + + // + // Main Loop ... + for (int i = limit; 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 ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cBullBuffer, true); + SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType); + PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + ArraySetAsSeries(cBearBuffer, true); + SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType); + PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + // Short ... + + // + ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sBullBuffer, true); + SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType); + PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort); + + // + ArraySetAsSeries(sBearBuffer, true); + SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType); + PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort); + + // + // Medium ... + + // + ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mBullBuffer, true); + SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType); + PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + ArraySetAsSeries(mBearBuffer, true); + SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType); + PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + // Long ... + + // + ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lBullBuffer, true); + SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType); + PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong); + + // + ArraySetAsSeries(lBearBuffer, true); + SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType); + PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong); + + // + // Hind ... + + // + ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hBullBuffer, true); + SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType); + PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind); + + // + ArraySetAsSeries(hBearBuffer, true); + SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType); + PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cBullBuffer, + cBearBuffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sBullBuffer, + sBearBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mBullBuffer, + mBearBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lBullBuffer, + lBearBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hBullBuffer, + hBearBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, // Calculation Length + bool _show, + double &_bull[], + double &_bear[] // +) +{ + // + double bullPower = 0; + double bearPower = 0; + + // + double lowShadow = 0; + double highShadow = 0; + + // + double bullPressure = 0; + double bearPressure = 0; + + // + double bullRange = 0; + double bearRange = 0; + + // + for (int i = bar_index; i < bar_index + _length; i++) + { + // + bool isBullish = + // + close[i] > open[i] + // + ; + + // + bool isBearish = + // + close[i] < open[i] + // + ; + + // + double iUpper = MathMax(open[i], close[i]); + double iLower = MathMin(open[i], close[i]); + + // + double iBody = iUpper - iLower; + double iRange = high[i] - low[i]; + + // + double iHighShadow = high[i] - iUpper; + double iLowShadow = iLower - low[i]; + + // + if (isBullish) + { + // + bullPower += iBody; + bullRange += iRange; + bearPressure += iHighShadow; + } + else if (isBearish) + { + // + bearPower += iBody; + bearRange += iRange; + bullPressure += iLowShadow; + } + + // + lowShadow += iLowShadow; + highShadow += iHighShadow; + } + + // + if (mode == XCHTD_POWER_MODE) + { + // + _bull[bar_index] = bullPower; + _bear[bar_index] = bearPower; + } + else if (mode == XCHTD_PRESSURE_MODE) + { + // + _bull[bar_index] = bullPressure; + _bear[bar_index] = bearPressure; + } + else if (mode == XCHTD_TYPE_MODE) + { + // + _bull[bar_index] = bullRange; + _bear[bar_index] = bearRange; + } else if (mode == XCHTD_STRONG_MODE) { + // + _bull[bar_index] = bullPower + bullPressure; + _bear[bar_index] = bearPower + bearPressure; + } +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchvlm.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchvlm.ex5 new file mode 100644 index 0000000..a75e6ba Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchvlm.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchvlm.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchvlm.mq5 new file mode 100644 index 0000000..dd1105e --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchvlm.mq5 @@ -0,0 +1,814 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHVLM +// Description: XCHVLM Cycles ... +// +// 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 XCHVLM Indicator" +#property strict + +// +#define ShortName "XCHVLM" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 14; // Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 0 + +// +// Current ... + +// +#define cBufferIndex 0 +double cBuffer[]; + +// +#define cColorBufferIndex 1 +double cColorBuffer[]; + +// +#define cPlotBufferIndex 0 +#property indicator_label1 "XCHVLM C" +#property indicator_style1 STYLE_SOLID +#property indicator_type1 DRAW_COLOR_HISTOGRAM +#property indicator_color1 CLR_NONE, clrLime, clrRed + +// +// Short ... + +// +#define sBufferIndex 2 +double sBuffer[]; + +// +#define sColorBufferIndex 3 +double sColorBuffer[]; + +// +#define sPlotBufferIndex 1 +#property indicator_label2 "XCHVLM S" +#property indicator_style2 STYLE_SOLID +#property indicator_type2 DRAW_COLOR_HISTOGRAM +#property indicator_color2 CLR_NONE, clrLime, clrRed + +// +// Medium ... + +// +#define mBufferIndex 4 +double mBuffer[]; + +// +#define mColorBufferIndex 5 +double mColorBuffer[]; + +// +#define mPlotBufferIndex 2 +#property indicator_label3 "XCHVLM M" +#property indicator_style3 STYLE_SOLID +#property indicator_type3 DRAW_COLOR_HISTOGRAM +#property indicator_color3 CLR_NONE, clrLime, clrRed + +// +// Long ... + +// +#define lBufferIndex 6 +double lBuffer[]; + +// +#define lColorBufferIndex 7 +double lColorBuffer[]; + +// +#define lPlotBufferIndex 3 +#property indicator_label4 "XCHVLM L" +#property indicator_style4 STYLE_SOLID +#property indicator_type4 DRAW_COLOR_HISTOGRAM +#property indicator_color4 CLR_NONE, clrLime, clrRed + +// +// Hind ... + +// +#define hBufferIndex 8 +double hBuffer[]; + +// +#define hColorBufferIndex 9 +double hColorBuffer[]; + +// +#define hPlotBufferIndex 4 +#property indicator_label5 "XCHVLM H" +#property indicator_style5 STYLE_SOLID +#property indicator_type5 DRAW_COLOR_HISTOGRAM +#property indicator_color5 CLR_NONE, clrLime, clrRed + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; +double cVolumes[]; +double cDistances[]; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +double sVolumes[]; +double sDistances[]; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +double mVolumes[]; +double mDistances[]; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +double lVolumes[]; +double lDistances[]; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +double hVolumes[]; +double hDistances[]; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Current ... + ArrayResize(cVolumes, maxLength, 0); + ArrayResize(cDistances, maxLength, 0); + + // + // Short ... + ArrayResize(sVolumes, maxLength, 0); + ArrayResize(sDistances, maxLength, 0); + + // + // Medium ... + ArrayResize(mVolumes, maxLength, 0); + ArrayResize(mDistances, maxLength, 0); + + // + // Long ... + ArrayResize(lVolumes, maxLength, 0); + ArrayResize(lDistances, maxLength, 0); + + // + // Hind ... + ArrayResize(hVolumes, maxLength, 0); + ArrayResize(hDistances, maxLength, 0); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 + + // + Clean(cVolumes); + Clean(cDistances); + + // + Clean(sVolumes); + Clean(sDistances); + + // + Clean(mVolumes); + Clean(mDistances); + + // + Clean(lVolumes); + Clean(lDistances); + + // + Clean(hVolumes); + Clean(hDistances); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + static int i = maxLength * 2; + for (i; i < rates_total; i++) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + i = rates_total - 1; + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType); + // PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent); + // SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_CALCULATIONS); + + // + // Short ... + + // + // ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType); + // PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort); + // SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_CALCULATIONS); + + // + // Medium ... + + // + // ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType); + // PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium); + // SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_CALCULATIONS); + + // + // Long ... + + // + // ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType); + // PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong); + // SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_CALCULATIONS); + + // + // Hind ... + + // + // ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType); + // PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind); + // SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_CALCULATIONS); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cVolumes, + cDistances, + cBuffer, + cColorBuffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sVolumes, + sDistances, + sBuffer, + sColorBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mVolumes, + mDistances, + mBuffer, + mColorBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lVolumes, + lDistances, + lBuffer, + lColorBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hVolumes, + hDistances, + hBuffer, + hColorBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, // Calculation Length + bool _show, + double &_volumes[], + double &_distances[], + double &_buffer[], + double &_colorBuffer[] // +) +{ + // + for (int x = 0; x < _length; x++) + { + // + _volumes[x] = (double)tickVolume[bar_index - x]; + _distances[x] = + (close[bar_index - x] > open[bar_index - x]) + ? high[bar_index - x] - low[bar_index - x] + : low[bar_index - x] - high[bar_index - x]; + } + + // + double iValue = MathMean(_volumes) * MathMean(_distances); + + // + _buffer[bar_index] = iValue; + _colorBuffer[bar_index] = iValue > 0 + ? _show + ? bullishColorIDX + : hideColorIDX + : _show + ? bearishColorIDX + : hideColorIDX; +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchvlm.osc.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchvlm.osc.ex5 new file mode 100644 index 0000000..993b9e4 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchvlm.osc.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchvlm.osc.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchvlm.osc.mq5 new file mode 100644 index 0000000..f1f91b6 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchvlm.osc.mq5 @@ -0,0 +1,810 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHVLM +// Description: XCHVLM Cycles ... +// +// 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 XCHVLM Indicator" +#property strict + +// +#define ShortName "XCHVLM" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 14; // Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// Current ... +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_separate_window + +// +#property indicator_buffers 10 +#property indicator_plots 10 + +// +// Current ... + +// +#define cBufferIndex 0 +double cBuffer[]; + +// +#define cColorBufferIndex 1 +double cColorBuffer[]; + +// +#define cPlotBufferIndex 0 +#property indicator_label1 "XCHVLM C" +#property indicator_style1 STYLE_SOLID +#property indicator_type1 DRAW_COLOR_HISTOGRAM +#property indicator_color1 CLR_NONE, clrLime, clrRed + +// +// Short ... + +// +#define sBufferIndex 2 +double sBuffer[]; + +// +#define sColorBufferIndex 3 +double sColorBuffer[]; + +// +#define sPlotBufferIndex 1 +#property indicator_label2 "XCHVLM S" +#property indicator_style2 STYLE_SOLID +#property indicator_type2 DRAW_COLOR_HISTOGRAM +#property indicator_color2 CLR_NONE, clrLime, clrRed + +// +// Medium ... + +// +#define mBufferIndex 4 +double mBuffer[]; + +// +#define mColorBufferIndex 5 +double mColorBuffer[]; + +// +#define mPlotBufferIndex 2 +#property indicator_label3 "XCHVLM M" +#property indicator_style3 STYLE_SOLID +#property indicator_type3 DRAW_COLOR_HISTOGRAM +#property indicator_color3 CLR_NONE, clrLime, clrRed + +// +// Long ... + +// +#define lBufferIndex 6 +double lBuffer[]; + +// +#define lColorBufferIndex 7 +double lColorBuffer[]; + +// +#define lPlotBufferIndex 3 +#property indicator_label4 "XCHVLM L" +#property indicator_style4 STYLE_SOLID +#property indicator_type4 DRAW_COLOR_HISTOGRAM +#property indicator_color4 CLR_NONE, clrLime, clrRed + +// +// Hind ... + +// +#define hBufferIndex 8 +double hBuffer[]; + +// +#define hColorBufferIndex 9 +double hColorBuffer[]; + +// +#define hPlotBufferIndex 4 +#property indicator_label5 "XCHVLM H" +#property indicator_style5 STYLE_SOLID +#property indicator_type5 DRAW_COLOR_HISTOGRAM +#property indicator_color5 CLR_NONE, clrLime, clrRed + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; +double cVolumes[]; +double cDistances[]; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +double sVolumes[]; +double sDistances[]; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +double mVolumes[]; +double mDistances[]; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +double lVolumes[]; +double lDistances[]; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +double hVolumes[]; +double hDistances[]; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Current ... + ArrayResize(cVolumes, maxLength, 0); + ArrayResize(cDistances, maxLength, 0); + + // + // Short ... + ArrayResize(sVolumes, maxLength, 0); + ArrayResize(sDistances, maxLength, 0); + + // + // Medium ... + ArrayResize(mVolumes, maxLength, 0); + ArrayResize(mDistances, maxLength, 0); + + // + // Long ... + ArrayResize(lVolumes, maxLength, 0); + ArrayResize(lDistances, maxLength, 0); + + // + // Hind ... + ArrayResize(hVolumes, maxLength, 0); + ArrayResize(hDistances, maxLength, 0); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 + + // + Clean(cVolumes); + Clean(cDistances); + + // + Clean(sVolumes); + Clean(sDistances); + + // + Clean(mVolumes); + Clean(mDistances); + + // + Clean(lVolumes); + Clean(lDistances); + + // + Clean(hVolumes); + Clean(hDistances); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + static int i = maxLength * 2; + for (i; i < rates_total; i++) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + i = rates_total - 1; + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType); + SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent); + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Short ... + + // + // ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Medium ... + + // + // ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType); + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Long ... + + // + // ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType); + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Hind ... + + // + // ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType); + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cVolumes, + cDistances, + cBuffer, + cColorBuffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sVolumes, + sDistances, + sBuffer, + sColorBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mVolumes, + mDistances, + mBuffer, + mColorBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lVolumes, + lDistances, + lBuffer, + lColorBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hVolumes, + hDistances, + hBuffer, + hColorBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, // Calculation Length + bool _show, + double &_volumes[], + double &_distances[], + double &_buffer[], + double &_colorBuffer[] // +) +{ + // + for (int x = 0; x < _length; x++) + { + // + _volumes[x] = (double)tickVolume[bar_index - x]; + _distances[x] = + (close[bar_index - x] > open[bar_index - x]) + ? high[bar_index - x] - low[bar_index - x] + : low[bar_index - x] - high[bar_index - x]; + } + + // + double iValue = MathMean(_volumes) * MathMean(_distances); + + // + _buffer[bar_index] = iValue; + _colorBuffer[bar_index] = iValue > 0 + ? _show + ? bullishColorIDX + : hideColorIDX + : _show + ? bearishColorIDX + : hideColorIDX; +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xchvwap.ex5 b/BKPS/Indicators 14030517/x-saherelm.xchvwap.ex5 new file mode 100644 index 0000000..ea77844 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xchvwap.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xchvwap.mq5 b/BKPS/Indicators 14030517/x-saherelm.xchvwap.mq5 new file mode 100644 index 0000000..b98fafc --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xchvwap.mq5 @@ -0,0 +1,830 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHVWAP +// Description: XCHVWAP Trend Detector ... +// +// 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 XCHVWAP Indicator" +#property strict + +// +#define ShortName "XCHVWAP" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 14 +#property indicator_plots 8 + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 +#define neuturalColorIDX 3 + +// +// Short ... + +// +#define sBufferIndex 0 +double sBuffer[]; + +// +#define sColorBufferIndex 1 +double sColorBuffer[]; + +// +#define sPlotBufferIndex 0 +#property indicator_label1 "XCHVWAP S" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Medium ... + +// +#define mBufferIndex 2 +double mBuffer[]; + +// +#define mColorBufferIndex 3 +double mColorBuffer[]; + +// +#define mPlotBufferIndex 1 +#property indicator_label2 "XCHVWAP M" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Long ... + +// +#define lBufferIndex 4 +double lBuffer[]; + +// +#define lColorBufferIndex 5 +double lColorBuffer[]; + +// +#define lPlotBufferIndex 2 +#property indicator_label3 "XCHVWAP L" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Hind ... + +// +#define hBufferIndex 6 +double hBuffer[]; + +// +#define hColorBufferIndex 7 +double hColorBuffer[]; + +// +#define hPlotBufferIndex 3 +#property indicator_label4 "XCHVWAP H" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Data Buffers ... + +// +// Volumes ... +#define volumeBufferIndex 8 +double volumeBuffer[]; + +// +// Price ... +#define priceBufferIndex 9 +double priceBuffer[]; + +// +// SHORT ... +#define sStateBufferIndex 10 +double sStateBuffer[]; + +// +// MEDIUM ... +#define mStateBufferIndex 11 +double mStateBuffer[]; + +// +// LONG ... +#define lStateBufferIndex 12 +double lStateBuffer[]; + +// +// HIND ... +#define hStateBufferIndex 13 +double hStateBuffer[]; + +// +// Variables ... + +// +int maxLength; + +// +// Short ... +int mSCycleLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// EVENT Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(low, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + + // + // this counts Available Bars ... + int limit; + + // + 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; +} + +// +// CUSTOM Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Short ... + + // + ArraySetAsSeries(sBuffer, true); + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Medium ... + + // + ArraySetAsSeries(mBuffer, true); + ArraySetAsSeries(mColorBuffer, true); + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Long ... + + // + ArraySetAsSeries(lBuffer, true); + ArraySetAsSeries(lColorBuffer, true); + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Hind ... + + // + ArraySetAsSeries(hBuffer, true); + ArraySetAsSeries(hColorBuffer, true); + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Data Buffers ... + + // + // Volumes ... + ArraySetAsSeries(volumeBuffer, true); + SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + ArraySetAsSeries(priceBuffer, true); + SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS); + + // + // Short State ... + ArraySetAsSeries(sStateBuffer, true); + SetIndexBuffer(sStateBufferIndex, sStateBuffer, INDICATOR_CALCULATIONS); + + // + // Medium State ... + ArraySetAsSeries(mStateBuffer, true); + SetIndexBuffer(mStateBufferIndex, mStateBuffer, INDICATOR_CALCULATIONS); + + // + // Long State ... + ArraySetAsSeries(lStateBuffer, true); + SetIndexBuffer(lStateBufferIndex, lStateBuffer, INDICATOR_CALCULATIONS); + + // + // Hind State ... + ArraySetAsSeries(hStateBuffer, true); + SetIndexBuffer(hStateBufferIndex, hStateBuffer, INDICATOR_CALCULATIONS); +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCycleLength, mMCycleLength); + result = MathMax(result, mLCycleLength); + result = MathMax(result, mHCycleLength); + + // + return result; +} + +// +// Calculate Buffers ... +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[] // +) +{ + // + // Calculate Volumes and Price ... + + // + if (ratesTotal - bar_index <= maxLength) + { + // + CalculateDataBuffers( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + return; + } + + // + CalculateDataBuffers( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateDataBuffers( + 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[] // +) +{ + // + double price = GetAppliedPrice( + appliedTo, + open, + high, + low, + close, + bar_index // + ); + priceBuffer[bar_index] = price; + volumeBuffer[bar_index] = (double)tickVolume[bar_index]; +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSCycleLength, + showShort, + sBuffer, + sColorBuffer, + sStateBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMCycleLength, + showMedium, + mBuffer, + mColorBuffer, + mStateBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLCycleLength, + showLong, + lBuffer, + lColorBuffer, + lStateBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHCycleLength, + showHind, + hBuffer, + hColorBuffer, + hStateBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, // Calculation Length + bool _show, + double &_buffer[], + double &_colorBuffer[], + double &_stateBuffer[] // +) +{ + // + double vSum = 0; + double pSum = 0; + double mSum = 0; + for (int x = 0; x < _length; x++) + { + // + pSum += priceBuffer[x + bar_index]; + vSum += volumeBuffer[x + bar_index]; + mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index]; + } + + // + double iValue = mSum / vSum; + iValue = NormalizeDouble(iValue, _Digits); + + // + _buffer[bar_index] = iValue; + + // + bool isBullish = low[bar_index] > iValue; + bool isBearish = high[bar_index] < iValue; + + // + double iColor = + isBullish + ? bullishColorIDX + : isBearish + ? bearishColorIDX + : neuturalColorIDX; + + // + _colorBuffer[bar_index] = hideColorIDX; + _stateBuffer[bar_index] = iColor; + if (_show) + { + _colorBuffer[bar_index] = iColor; + } +} + +// \ No newline at end of file diff --git a/BKPS/Indicators 14030517/x-saherelm.xct.ex5 b/BKPS/Indicators 14030517/x-saherelm.xct.ex5 new file mode 100644 index 0000000..1d69ddd Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xct.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xct.mq5 b/BKPS/Indicators 14030517/x-saherelm.xct.mq5 new file mode 100644 index 0000000..25b3b07 --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xct.mq5 @@ -0,0 +1,261 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// --------------------------------------------- +// Name: XCT +// Description: Trend Magic Indicator ... +// +// +// 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 XCT Indicator" +#property strict + +// +// START Constants ... +// + +// +#define ShortName "XCT" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input color clr = clrYellow; // Text Color +input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position + +// +input group "Presentation"; +input bool showCandleTime = true; // Show Candle Time + +// +// END Inputs ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (showCandleTime) + { + CreateIndicatorObject(); + } + else + { + ObjectDelete(0, ShortName); + } + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + // + // Delete Object ... + ObjectDelete(chID, ShortName); + + // + Comment(""); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(time, true); + + // + if (!showCandleTime) + { + return rates_total; + } + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + // + XBarRemainsTime barRemains; + barRemains.Init( + _Symbol, + _Period + // + ); + + // + string msg = barRemains + .ToString( + "", + "", + "", + "", + "", + ":", + true + // + ); + + // + long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD); + + // + string _sp = ""; + if (mSpread < 10) + _sp = ".."; + else if (mSpread < 100) + _sp = "."; + + // + string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in: " + msg; + + // + ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr); + ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText); + ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10); + ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier"); + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +void CreateIndicatorObject() +{ + // + if (!showCandleTime) + { + return; + } + + // + ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0); + ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner); + ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10); + ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); + + // + ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER; + switch (corner) + { + case CORNER_LEFT_UPPER: + Anchor = ANCHOR_LEFT_UPPER; + break; + case CORNER_RIGHT_UPPER: + Anchor = ANCHOR_RIGHT_UPPER; + break; + case CORNER_LEFT_LOWER: + Anchor = ANCHOR_LEFT_LOWER; + break; + case CORNER_RIGHT_LOWER: + Anchor = ANCHOR_RIGHT_LOWER; + break; + } + + // + ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor); +} + +// +// END Functions ... +// diff --git a/BKPS/Indicators 14030517/x-saherelm.xpv.ex5 b/BKPS/Indicators 14030517/x-saherelm.xpv.ex5 new file mode 100644 index 0000000..f29ab60 Binary files /dev/null and b/BKPS/Indicators 14030517/x-saherelm.xpv.ex5 differ diff --git a/BKPS/Indicators 14030517/x-saherelm.xpv.mq5 b/BKPS/Indicators 14030517/x-saherelm.xpv.mq5 new file mode 100644 index 0000000..e15924d --- /dev/null +++ b/BKPS/Indicators 14030517/x-saherelm.xpv.mq5 @@ -0,0 +1,1289 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XPV +// Description: Peaks and Vales ... +// +// +// 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 XPV Indicator" +#property strict + +// +// Definitions ... + +// +#define ShortName "XPV" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Makret Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Fibonacci"; +input double fiboLevel1 = 0.236; // Fibio 1st Level +input double fiboLevel2 = 0.382; // Fibio 2st Level +input double fiboLevel3 = 0.5; // Fibio 3rd Level +input double fiboLevel4 = 0.618; // Fibio 4th Level +input double fiboLevel5 = 0.764; // Fibio 5th Level + +// +input group "Boundary Detection Modes"; +input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method +input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method + +// +input group "Presentation"; +input bool showPeaksAndVales = true; // Show Peaks and Vales +input bool showLevels = false; // Show Levels +input bool showConsolidations = false; // Show Consolidations +input bool showFibo1Levels = false; // Show Fibo 1st Level +input bool showFibo2Levels = false; // Show Fibo 2nd Level +input bool showFibo3Levels = false; // Show Fibo 3rd Level +input bool showFibo4Levels = false; // Show Fibo 4th Level +input bool showFibo5Levels = false; // Show Fibo 5th Level + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 32 +#property indicator_plots 32 + +// +// PEAKS ... + +// +#define peaksBufferIndex 0 +double peaksBuffer[]; + +// +#property indicator_label1 "XPV PEAKS" +#property indicator_type1 DRAW_ARROW +#property indicator_color1 clrAqua +#property indicator_width1 1 + +// +// VALES ... + +// +#define valesBufferIndex 1 +double valesBuffer[]; + +// +#property indicator_label2 "XPV VALES" +#property indicator_type2 DRAW_ARROW +#property indicator_color2 clrMagenta +#property indicator_width2 1 + +// +#define rBufferIndex 2 +double rBuffer[]; + +// +#define rColorBufferIndex 3 +double rColorBuffer[]; + +// +#property indicator_label3 "XPV R" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +#define sBufferIndex 4 +#define sBufferPlotIndex 3 +double sBuffer[]; + +// +#define sColorBufferIndex 5 +double sColorBuffer[]; + +// +#property indicator_label4 "XPV S" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// FIBBO Level 1 ... + +// +#define fl1BufferIndex 6 +#define fl1BufferPlotIndex 4 +double fl1Buffer[]; + +// +#define fl1ColorBufferIndex 7 +double fl1ColorBuffer[]; + +// +#property indicator_label5 "XPV FL1" +#property indicator_type5 DRAW_COLOR_LINE +#property indicator_color5 CLR_NONE, clrGold +#property indicator_style5 STYLE_DASHDOTDOT +#property indicator_width5 1 + +// +// FIBBO Level 2 ... + +// +#define fl2BufferIndex 8 +#define fl2BufferPlotIndex 5 +double fl2Buffer[]; + +// +#define fl2ColorBufferIndex 9 +double fl2ColorBuffer[]; + +// +#property indicator_label6 "XPV FL2" +#property indicator_type6 DRAW_COLOR_LINE +#property indicator_color6 CLR_NONE, clrGold +#property indicator_style6 STYLE_DASHDOTDOT +#property indicator_width6 1 + +// +// FIBBO Level 3 ... + +// +#define fl3BufferIndex 10 +#define fl3BufferPlotIndex 6 +double fl3Buffer[]; + +// +#define fl3ColorBufferIndex 11 +double fl3ColorBuffer[]; + +// +#property indicator_label7 "XPV FL3" +#property indicator_type7 DRAW_COLOR_LINE +#property indicator_color7 CLR_NONE, clrGold +#property indicator_style7 STYLE_DASHDOTDOT +#property indicator_width7 1 + +// +// FIBBO Level 4 ... + +// +#define fl4BufferIndex 12 +#define fl4BufferPlotIndex 7 +double fl4Buffer[]; + +// +#define fl4ColorBufferIndex 13 +double fl4ColorBuffer[]; + +// +#property indicator_label8 "XPV FL4" +#property indicator_type8 DRAW_COLOR_LINE +#property indicator_color8 CLR_NONE, clrGold +#property indicator_style8 STYLE_DASHDOTDOT +#property indicator_width8 1 + +// +// FIBBO Level 5 ... + +// +#define fl5BufferIndex 14 +#define fl5BufferPlotIndex 8 +double fl5Buffer[]; + +// +#define fl5ColorBufferIndex 15 +double fl5ColorBuffer[]; + +// +#property indicator_label9 "XPV FL5" +#property indicator_type9 DRAW_COLOR_LINE +#property indicator_color9 CLR_NONE, clrGold +#property indicator_style9 STYLE_DASHDOTDOT +#property indicator_width9 1 + +// +// LEVELS ... + +// +#define scHHBufferIndex 16 +#define scHHBufferPlotIndex 9 +double scHHBuffer[]; + +// +#define scHHColorBufferIndex 17 +double scHHColorBuffer[]; + +// +#property indicator_label10 "XPV SHH" +#property indicator_type10 DRAW_COLOR_LINE +#property indicator_color10 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +#define scLLBufferIndex 18 +#define scLLBufferPlotIndex 10 +double scLLBuffer[]; + +// +#define scLLColorBufferIndex 19 +double scLLColorBuffer[]; + +// +#property indicator_label11 "XPV SLL" +#property indicator_type11 DRAW_COLOR_LINE +#property indicator_color11 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +#define mcHHBufferIndex 20 +#define mcHHBufferPlotIndex 11 +double mcHHBuffer[]; + +// +#define mcHHColorBufferIndex 21 +double mcHHColorBuffer[]; + +// +#property indicator_label12 "XPV MHH" +#property indicator_type12 DRAW_COLOR_LINE +#property indicator_color12 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +#define mcLLBufferIndex 22 +#define mcLLBufferPlotIndex 12 +double mcLLBuffer[]; + +// +#define mcLLColorBufferIndex 23 +double mcLLColorBuffer[]; + +// +#property indicator_label13 "XPV MLL" +#property indicator_type13 DRAW_COLOR_LINE +#property indicator_color13 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style13 STYLE_DOT +#property indicator_width13 1 + +// +#define lcHHBufferIndex 24 +#define lcHHBufferPlotIndex 13 +double lcHHBuffer[]; + +// +#define lcHHColorBufferIndex 25 +double lcHHColorBuffer[]; + +// +#property indicator_label14 "XPV LHH" +#property indicator_type14 DRAW_COLOR_LINE +#property indicator_color14 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style14 STYLE_DOT +#property indicator_width14 1 + +// +#define lcLLBufferIndex 26 +#define lcLLBufferPlotIndex 14 +double lcLLBuffer[]; + +// +#define lcLLColorBufferIndex 27 +double lcLLColorBuffer[]; + +// +#property indicator_label15 "XPV LLL" +#property indicator_type15 DRAW_COLOR_LINE +#property indicator_color15 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style15 STYLE_DOT +#property indicator_width15 1 + +// +#define hcHHBufferIndex 28 +#define hcHHBufferPlotIndex 15 +double hcHHBuffer[]; + +// +#define hcHHColorBufferIndex 29 +double hcHHColorBuffer[]; + +// +#property indicator_label16 "XPV HHH" +#property indicator_type16 DRAW_COLOR_LINE +#property indicator_color16 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style16 STYLE_DOT +#property indicator_width16 1 + +// +#define hcLLBufferIndex 30 +#define hcLLBufferPlotIndex 16 +double hcLLBuffer[]; + +// +#define hcLLColorBufferIndex 31 +double hcLLColorBuffer[]; + +// +#property indicator_label17 "XPV HLL" +#property indicator_type17 DRAW_COLOR_LINE +#property indicator_color17 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style17 STYLE_DOT +#property indicator_width17 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +double mHideColorIDX = 0; + +// +// XMarketCycle sc; +int mSCLength = 0; +double mLastSCHH = 0; +double mLastSCLL = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// XMarketCycle mc; +int mMCLength = 0; +double mLastMCHH = 0; +double mLastMCLL = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// XMarketCycle lc; +int mLCLength = 0; +double mLastLCHH = 0; +double mLastLCLL = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// XMarketCycle hc; +int mHCLength = 0; +double mLastHCHH = 0; +double mLastHCLL = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +double lastPeak = 0; +double lastVale = 0; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... + // +) +{ + // + // 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); + + // + // this counts Available Bars ... + int limit; + + // + 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); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCLength, mMCLength); + result = MathMax(result, mLCLength); + result = MathMax(result, mHCLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // PEAKS and VALES ... + ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; + + // + // PEAKS ... + ArraySetAsSeries(peaksBuffer, true); + SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); + PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225); + PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); + PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + // VALES ... + ArraySetAsSeries(valesBuffer, true); + SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); + PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225); + PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); + PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + // SUPPORT and RESISTANCE ... + // + + // + // RESISTANCE ... + ArraySetAsSeries(rBuffer, true); + SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA); + PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // RESISTANCE Color ... + ArraySetAsSeries(rColorBuffer, true); + SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX); + + // + // SUPPORT ... + ArraySetAsSeries(sBuffer, true); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false); + + // + // SUPPORT Color ... + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // FIBBO Levels ... + + // + // LEVEL 1 ... + + // + // Buffer ... + ArraySetAsSeries(fl1Buffer, true); + SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_SHOW_DATA, showFibo1Levels); + + // + // Color ... + ArraySetAsSeries(fl1ColorBuffer, true); + SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 2 ... + + // + // Buffer ... + ArraySetAsSeries(fl2Buffer, true); + SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_SHOW_DATA, showFibo2Levels); + + // + // Color ... + ArraySetAsSeries(fl2ColorBuffer, true); + SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 3 ... + + // + // Buffer ... + ArraySetAsSeries(fl3Buffer, true); + SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_SHOW_DATA, showFibo3Levels); + + // + // Color ... + ArraySetAsSeries(fl3ColorBuffer, true); + SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 4 ... + + // + // Buffer ... + ArraySetAsSeries(fl4Buffer, true); + SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_SHOW_DATA, showFibo4Levels); + + // + // Color ... + ArraySetAsSeries(fl4ColorBuffer, true); + SetIndexBuffer(fl4ColorBufferIndex, fl4ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 5 ... + + // + // Buffer ... + ArraySetAsSeries(fl5Buffer, true); + SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_SHOW_DATA, showFibo5Levels); + + // + // Color ... + ArraySetAsSeries(fl5ColorBuffer, true); + SetIndexBuffer(fl5ColorBufferIndex, fl5ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // SHORT Buffers ... + + // + // HIGH ... + ArraySetAsSeries(scHHBuffer, true); + SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(scHHColorBuffer, true); + SetIndexBuffer(scHHColorBufferIndex, scHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(scLLBuffer, true); + SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(scLLColorBuffer, true); + SetIndexBuffer(scLLColorBufferIndex, scLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // MEDIUM Buffer ... + + // + // HIGH ... + ArraySetAsSeries(mcHHBuffer, true); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(mcHHColorBuffer, true); + SetIndexBuffer(mcHHColorBufferIndex, mcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(mcLLBuffer, true); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(mcLLColorBuffer, true); + SetIndexBuffer(mcLLColorBufferIndex, mcLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LONG Buffer ... + + // + // HIGH ... + ArraySetAsSeries(lcHHBuffer, true); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(lcHHColorBuffer, true); + SetIndexBuffer(lcHHColorBufferIndex, lcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(lcLLBuffer, true); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(lcLLColorBuffer, true); + SetIndexBuffer(lcLLColorBufferIndex, lcLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // HIND Buffer ... + + // + // HIGH ... + ArraySetAsSeries(hcHHBuffer, true); + SetIndexBuffer(hcHHBufferIndex, hcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(hcHHColorBuffer, true); + SetIndexBuffer(hcHHColorBufferIndex, hcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(hcLLBuffer, true); + SetIndexBuffer(hcLLBufferIndex, hcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(hcLLColorBuffer, true); + SetIndexBuffer(hcLLColorBufferIndex, hcLLColorBuffer, INDICATOR_COLOR_INDEX); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index // Selected Bar Index +) +{ + // + // Calculate Cycles ... + CalculateCycles(bar_index); + + // + // Calculate Peaks and Vales ... + CalculatePeaksAndVales(bar_index); + + // + // Calculate Fibonnaci ... + CalculateFibonacci(bar_index); +} + +// +// Custom ... + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + if (IsValid(mSCPeriod)) + { + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + if (IsValid(mMCPeriod)) + { + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + if (IsValid(mLCPeriod)) + { + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + if (IsValid(mHCPeriod)) + { + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + } + + // + result = mSCLength > 0 && + mMCLength > mSCLength && + mLCLength > mMCLength && + mHCLength > mLCLength; + + // + return result; +} + +// +// Calculate Specified Cycles HH and LL ... +void CalculateCycle( + int barIndex, + ENUM_X_MARKET_CYCLES cycle, + double &lastHH, + double &hhBuffer[], + double &hhColorBuffer[], + double &lastLL, + double &llBuffer[], + double &llColorBuffer[] // +) +{ + // + XOHCL bar; + bar.Init( + _Symbol, + _Period, + barIndex + // + ); + + // + int mLength = 0; + switch (cycle) + { + // + case X_MARKET_CYCLE_SHORT: + mLength = mSCLength; + break; + + // + case X_MARKET_CYCLE_MEDIUM: + mLength = mMCLength; + break; + + // + case X_MARKET_CYCLE_LONG: + mLength = mLCLength; + break; + + // + case X_MARKET_CYCLE_HIND: + mLength = mHCLength; + break; + } + + // + if (mLength <= 0) + { + return; + } + + // + double hhValue = bar.FindHighest( + mLength, + hhMode + // + ); + hhBuffer[barIndex] = hhValue; + + // + double hhColorIDX = + !showLevels + ? mHideColorIDX + : (hhValue == lastHH) + ? !showConsolidations + ? mHideColorIDX + : 1 + : hhValue > lastHH + ? 2 + : hhValue < lastHH + ? 3 + : mHideColorIDX; + hhColorBuffer[barIndex] = hhColorIDX; + + // + lastHH = hhValue; + + // + double llValue = bar.FindLowest( + mLength, + llMode + // + ); + llBuffer[barIndex] = llValue; + + // + double llColorIDX = + !showLevels + ? mHideColorIDX + : (llValue == lastLL) + ? !showConsolidations + ? mHideColorIDX + : 1 + : llValue > lastLL + ? 2 + : llValue < lastLL + ? 3 + : mHideColorIDX; + llColorBuffer[barIndex] = llColorIDX; + + // + lastLL = llValue; +} + +// +// Calculate Cycles Up and Down Boundaries ... +void CalculateCycles( + int barIndex // Bar Index +) +{ + // + // Short ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_SHORT, + // + mLastSCHH, + scHHBuffer, + scHHColorBuffer, + // + mLastSCLL, + scLLBuffer, + scLLColorBuffer + // + ); + + // + // Medium ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_MEDIUM, + // + mLastMCHH, + mcHHBuffer, + mcHHColorBuffer, + // + mLastMCLL, + mcLLBuffer, + mcLLColorBuffer + // + ); + + // + // Long ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_LONG, + // + mLastLCHH, + lcHHBuffer, + lcHHColorBuffer, + // + mLastLCLL, + lcLLBuffer, + lcLLColorBuffer + // + ); + + // + // Hind ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_HIND, + // + mLastHCHH, + hcHHBuffer, + hcHHColorBuffer, + // + mLastHCLL, + hcLLBuffer, + hcLLColorBuffer + // + ); +} + +// +// Calculate Peaks and Values ... +void CalculatePeaksAndVales( + int barIndex // Bar Index +) +{ + // + // Retrieve Requirements ... + + // + // Short ... + double scHHValue = scHHBuffer[barIndex]; + double scLLValue = scLLBuffer[barIndex]; + + // + // Medium ... + double mcHHValue = mcHHBuffer[barIndex]; + double mcLLValue = mcLLBuffer[barIndex]; + + // + // Long ... + double lcHHValue = lcHHBuffer[barIndex]; + double lcLLValue = lcLLBuffer[barIndex]; + + // + // Hind ... + double hcHHValue = hcHHBuffer[barIndex]; + double hcLLValue = hcLLBuffer[barIndex]; + + // + double rColorIDX = mHideColorIDX; + double sColorIDX = mHideColorIDX; + + // + // RESISTANCE ... + double rValue = (scHHValue + mcHHValue + lcHHValue + hcHHValue) / 4; + + // + // PEAKS ... + bool isPeak = rValue == hcHHValue && + hcHHValue == lcHHValue && + lcHHValue == mcHHValue && + mcHHValue == scHHValue; + + // + if (isPeak && lastPeak != rValue) + { + // + rColorIDX = 1; + lastPeak = rValue; + } + + // + // SUPPORT ... + double sValue = (scLLValue + mcLLValue + lcLLValue + hcLLValue) / 4; + + // + // VALES ... + bool isVale = sValue == hcLLValue && + hcLLValue == lcLLValue && + lcLLValue == mcLLValue && + mcLLValue == scLLValue; + + // + if (isVale && lastVale != sValue) + { + // + sColorIDX = 1; + + // + lastVale = sValue; + } + + // + rBuffer[barIndex] = rValue; + sBuffer[barIndex] = sValue; + peaksBuffer[barIndex] = lastPeak; + valesBuffer[barIndex] = lastVale; + + // + if (showPeaksAndVales) + { + // + rColorBuffer[barIndex] = rColorIDX; + sColorBuffer[barIndex] = sColorIDX; + } + else + { + // + rColorBuffer[barIndex] = mHideColorIDX; + sColorBuffer[barIndex] = mHideColorIDX; + } +} + +// +// Calculate Fibonacci Level 1 ... +void CalculateFibonacci( + int barIndex // Bar Index +) +{ + // + // Select Requirements ... + double upPrice = peaksBuffer[barIndex]; + double downPrice = valesBuffer[barIndex]; + + // + // Level 1 ... + double fibLevel1Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel1, + 1); + // + // Level 2 ... + double fibLevel2Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel2, + 1); + + // + // Level 3 ... + double fibLevel3Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel3, + 1); + + // + // Level 4 ... + double fibLevel4Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel4, + 1); + + // + // Level 5 ... + double fibLevel5Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel5, + 1); + + // + fl1Buffer[barIndex] = fibLevel1Value; + fl2Buffer[barIndex] = fibLevel2Value; + fl3Buffer[barIndex] = fibLevel3Value; + fl4Buffer[barIndex] = fibLevel4Value; + fl5Buffer[barIndex] = fibLevel5Value; + + // + double fl1ColorIdx = showFibo1Levels ? 1 : mHideColorIDX; + double fl2ColorIdx = showFibo2Levels ? 1 : mHideColorIDX; + double fl3ColorIdx = showFibo3Levels ? 1 : mHideColorIDX; + double fl4ColorIdx = showFibo4Levels ? 1 : mHideColorIDX; + double fl5ColorIdx = showFibo5Levels ? 1 : mHideColorIDX; + + // + fl1ColorBuffer[barIndex] = fl1ColorIdx; + fl2ColorBuffer[barIndex] = fl2ColorIdx; + fl3ColorBuffer[barIndex] = fl3ColorIdx; + fl4ColorBuffer[barIndex] = fl4ColorIdx; + fl5ColorBuffer[barIndex] = fl5ColorIdx; +} + +// \ No newline at end of file