diff --git a/Classes/x-saherelm.x-md5.class.mq5 b/Classes/x-saherelm.x-md5.class.mq5 index e5cc2016..6bd1c4ef 100644 --- a/Classes/x-saherelm.x-md5.class.mq5 +++ b/Classes/x-saherelm.x-md5.class.mq5 @@ -228,7 +228,7 @@ class XCMD5 // // Convert DWord to Byte ... - void DWordToByte(uchar &out[], int &in[], uint len) + void DWordToByte(uchar &out[], uint &in[], uint len) { // uint i = 0; diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 5e0a8c71..20604fa9 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -899,6 +899,26 @@ class XCPOIDrawer : public XCBase object.BoxStyle(style.style); } + /** + * Apply Specified Style to Object ... + */ + void ApplyStyle( + XCBarArrowObject *&object, + XPOIStyle &style // + ) + { + // + bool has = object != NULL; + if (!has) + { + return; + } + + // + object.ArrowColor(style.clr); + object.ArrowWidth(style.width); + } + // protected: // diff --git a/Indicators/x-saherelm.x121.xma.mq5 b/Indicators/x-saherelm.x121.xma.mq5 new file mode 100644 index 00000000..5a5d8620 --- /dev/null +++ b/Indicators/x-saherelm.x121.xma.mq5 @@ -0,0 +1,2231 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: X121 XMA +// Description: Integrates All Requirements inside +// this indicator for analyse Markets ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm X121 XMA Indicator" +#property strict + +// +// Definitions ... + +// +#define ShortName "X121 XMA" + +// +// Imports ... +#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Cycles"; + +// +// Short ... +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Short Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Short Period + +// +// Medium ... +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Medium Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Medium Period + +// +// Long ... +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Long Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Long Period + +// +// Hind ... +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Hind Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Hind Period + +// +input group "Calculation"; +input ENUM_SERIESMODE upperMode = MODE_HIGH; // Cycles Rnage Upper Method +input ENUM_SERIESMODE lowerMode = MODE_LOW; // Cycles Rnage Lower Method +input ENUM_MA_METHOD maMethod = MODE_SMA; // Cycles MA Method +input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Cycles MA Applied To +input int maLength = 20; // Cycles MA Length + +// +// Presentation ... +input group "Presentation"; +input bool showBars = true; // Show Bars +input bool showShortCycle = false; // Show Short Cycle Range +input bool showMediumCycle = false; // Show Medium Cycle Range +input bool showLongCycle = false; // Show Long Cycle Range +input bool showHindCycle = false; // Show Hind Cycle Range +input bool showShortCycleMa = false; // Show Short Cycle Ma +input bool showMediumCycleMa = false; // Show Medium Cycle Ma +input bool showLongCycleMa = false; // Show Long Cycle Ma +input bool showHindCycleMa = false; // Show Hind Cycle Ma + +// +input int startCalculationForLastBars = 1500; // Calculate Last n Bars + +// +// Non Inputs ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 +#define neuturalColorIDX 3 + +// +#define bullishState 1 +#define neuturalState 0 +#define bearishState -1 + +// +#define emptyValue 0.0 + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 20 +#property indicator_plots 12 + +// +// Plot Buffers ... + +// +// SC ... + +// +#define scMaBufferIndex 0 +#define scMaBufferPlotIndex 0 +double scMaBuffer[]; + +// +#define scMaColorBufferIndex 1 +double scMaColorBuffer[]; + +// +#property indicator_label1 "SCMA" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style1 STYLE_DASHDOTDOT +#property indicator_width1 2 + +// +// MC ... + +// +#define mcMaBufferIndex 2 +#define mcMaBufferPlotIndex 1 +double mcMaBuffer[]; + +// +#define mcMaColorBufferIndex 3 +double mcMaColorBuffer[]; + +// +#property indicator_label2 "MCMA" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style2 STYLE_DASHDOTDOT +#property indicator_width2 2 + +// +// LC ... + +// +#define lcMaBufferIndex 4 +#define lcMaBufferPlotIndex 2 +double lcMaBuffer[]; + +// +#define lcMaColorBufferIndex 5 +double lcMaColorBuffer[]; + +// +#property indicator_label3 "LCMA" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style3 STYLE_DASHDOTDOT +#property indicator_width3 2 + +// +// HC ... + +// +#define hcMaBufferIndex 6 +#define hcMaBufferPlotIndex 3 +double hcMaBuffer[]; + +// +#define hcMaColorBufferIndex 7 +double hcMaColorBuffer[]; + +// +#property indicator_label4 "HCMA" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style4 STYLE_DASHDOTDOT +#property indicator_width4 2 + +// +// CYCLES Range ... + +// +// SHORT ... + +// +#define sHHBufferIndex 8 +#define sHHBufferPlotIndex 4 +double sHHBuffer[]; + +// +#property indicator_label5 "SH" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrGray +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +#define sLLBufferIndex 9 +#define sLLBufferPlotIndex 5 +double sLLBuffer[]; + +// +#property indicator_label6 "SL" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrGray +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// MEDIUM ... + +// +#define mHHBufferIndex 10 +#define mHHBufferPlotIndex 6 +double mHHBuffer[]; + +// +#property indicator_label7 "MH" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrIndigo +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +#define mLLBufferIndex 11 +#define mLLBufferPlotIndex 7 +double mLLBuffer[]; + +// +#property indicator_label8 "ML" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrIndigo +#property indicator_style8 STYLE_DOT +#property indicator_width8 1 + +// +// LONG ... + +// +#define lHHBufferIndex 12 +#define lHHBufferPlotIndex 8 +double lHHBuffer[]; + +// +#property indicator_label9 "LH" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrGoldenrod +#property indicator_style9 STYLE_DOT +#property indicator_width9 1 + +// +#define lLLBufferIndex 13 +#define lLLBufferPlotIndex 9 +double lLLBuffer[]; + +// +#property indicator_label10 "LL" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrGoldenrod +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +// +// HIND ... + +// +#define hHHBufferIndex 14 +#define hHHBufferPlotIndex 10 +double hHHBuffer[]; + +// +#property indicator_label11 "HH" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrBrown +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +#define hLLBufferIndex 15 +#define hLLBufferPlotIndex 11 +double hLLBuffer[]; + +// +#property indicator_label12 "HL" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrBrown +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +// Data Buffers ... + +// +#define mLastBufferIndex 15 + +// +#define scMaStateBufferIndex mLastBufferIndex + 1 +double scMaStateBuffer[]; + +// +#define mcMaStateBufferIndex mLastBufferIndex + 2 +double mcMaStateBuffer[]; + +// +#define lcMaStateBufferIndex mLastBufferIndex + 3 +double lcMaStateBuffer[]; + +// +#define hcMaStateBufferIndex mLastBufferIndex + 4 +double hcMaStateBuffer[]; + +// +// Variables, Properties and etc ... + +// +// Bars Color Variables ... +color _upColor = clrLime; +color _downColor = clrRed; +color _lineColor = clrLime; +color _bullishColor = clrLime; +color _bearishColor = clrRed; + +// +int limit; + +// +int maxLength; + +// +int firstBarIndex; + +// +// XMarketCycle sc; +int mSCLength = 0; +int mSCMALength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// XMarketCycle mc; +int mMCLength = 0; +int mMCMALength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// XMarketCycle lc; +int mLCLength = 0; +int mLCMALength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// XMarketCycle hc; +int mHCLength = 0; +int mHCMALength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Handlers ... +int scMaHandler = INVALID_HANDLE; +int mcMaHandler = INVALID_HANDLE; +int lcMaHandler = INVALID_HANDLE; +int hcMaHandler = INVALID_HANDLE; + +// +// Requirements ... +CArrayObj mObjects; +XCPOIDrawer *mDrawer; + +// +// Event Handlers ... + +/** + * Initialize Indicator ... + * + * @return ( int ) + */ +int OnInit() +{ + // + bool has = false; + + // + ReadBarStyle(); + + // + // Validate Inputs ... + has = ValidateInputs(); + if (!has) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + has = InitCycles(); + if (!has) + { + return INIT_FAILED; + } + + // + // 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(); + + // + // Initial Requirements ... + has = InitRequirements(); + if (!has) + { + return INIT_FAILED; + } + + // + if (showBars) + { + ShowBars(); + } + else + { + HideBars(); + } + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; + + // +} + +/** + * De Initialize Indicator ... + * + * @param reason: Integer, De Initialization Reason ... + */ +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + ShowBars(); + + // + delete mDrawer; + ZeroMemory(mDrawer); + + // + mObjects.Clear(); + + // + // De Initialize all Handlers and etc ... + IndicatorRelease(scMaHandler); + IndicatorRelease(mcMaHandler); + IndicatorRelease(lcMaHandler); + IndicatorRelease(hcMaHandler); +} + +/** + * Calculate Bars ... + * + * @param rates_total: Integer, Total Bars on Chart ... + * @param prev_calculated: Integer, Total Calculated Bars on Charts ... + * @param time: DateTime Array, History of Open Time ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param low: Double Array, History of Low Prices ... + * @param close: Double Array, History of Close Prices ... + * @param tick_volume: Long, History of Tick Volumes on Bar ... + * @param volume: Long, History of Trade Volumes ... + * @param spread: Double, History of Spread Price ... + * + * @return ( int ) + */ +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] // +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // Validate Calculated Bars ... + + // + int scCalculatedBars = BarsCalculated(scMaHandler); + int mcCalculatedBars = BarsCalculated(mcMaHandler); + int lcCalculatedBars = BarsCalculated(lcMaHandler); + int hcCalculatedBars = BarsCalculated(hcMaHandler); + + // + bool isPassedRequiredCalculatedBars = + // + // SC ... + scCalculatedBars >= maxLength && + // + // MC ... + mcCalculatedBars >= maxLength && + // + // LC ... + lcCalculatedBars >= maxLength && + // + // HC ... + hcCalculatedBars >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + int copiedSCs = CopyBuffer(scMaHandler, MAIN_LINE, 0, limit, scMaBuffer); + int copiedMCs = CopyBuffer(mcMaHandler, MAIN_LINE, 0, limit, mcMaBuffer); + int copiedLCs = CopyBuffer(lcMaHandler, MAIN_LINE, 0, limit, lcMaBuffer); + int copiedHCs = CopyBuffer(hcMaHandler, MAIN_LINE, 0, limit, hcMaBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // SC ... + copiedSCs >= limit && + // + // MC ... + copiedMCs >= limit && + // + // LC ... + copiedLCs >= limit && + // + // HC ... + copiedHCs >= limit + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // 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 ... + +/** + * Set Indicator Short Name and also we can define Buffers Labels ... + */ +void SetIndicatorName() +{ + // + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +/** + * Validate Input Args for Initialization ... + * + * @return ( bool ) + */ +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + // CYCLES ... + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +/** + * Extract Max Length of Inputs ... + * + * @return ( int ) + */ +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCLength, mMCLength); + result = MathMax(result, mLCLength); + result = MathMax(result, mHCLength); + result = MathMax(result, mSCMALength); + result = MathMax(result, mMCMALength); + result = MathMax(result, mLCMALength); + result = MathMax(result, mHCMALength); + + // + return result; +} + +/** + * Define Required Buffers ... + */ +void DefineBuffers() +{ + // + // Plot Buffers ... + + // + // SC ... + + // + ArraySetAsSeries(scMaBuffer, true); + SetIndexBuffer(scMaBufferIndex, scMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scMaBufferPlotIndex, PLOT_SHOW_DATA, showShortCycleMa); + PlotIndexSetDouble(scMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(scMaColorBuffer, true); + SetIndexBuffer(scMaColorBufferIndex, scMaColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(scMaStateBuffer, true); + SetIndexBuffer(scMaStateBufferIndex, scMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // SC ... + + // + ArraySetAsSeries(mcMaBuffer, true); + SetIndexBuffer(mcMaBufferIndex, mcMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcMaBufferPlotIndex, PLOT_SHOW_DATA, showMediumCycleMa); + PlotIndexSetDouble(mcMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(mcMaColorBuffer, true); + SetIndexBuffer(mcMaColorBufferIndex, mcMaColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(scMaStateBuffer, true); + SetIndexBuffer(mcMaStateBufferIndex, mcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // LC ... + + // + ArraySetAsSeries(lcMaBuffer, true); + SetIndexBuffer(lcMaBufferIndex, lcMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcMaBufferPlotIndex, PLOT_SHOW_DATA, showLongCycleMa); + PlotIndexSetDouble(lcMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(lcMaColorBuffer, true); + SetIndexBuffer(lcMaColorBufferIndex, lcMaColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(lcMaStateBuffer, true); + SetIndexBuffer(lcMaStateBufferIndex, lcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // HC ... + + // + ArraySetAsSeries(hcMaBuffer, true); + SetIndexBuffer(hcMaBufferIndex, hcMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcMaBufferPlotIndex, PLOT_SHOW_DATA, showHindCycleMa); + PlotIndexSetDouble(hcMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(hcMaColorBuffer, true); + SetIndexBuffer(hcMaColorBufferIndex, hcMaColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(hcMaStateBuffer, true); + SetIndexBuffer(hcMaStateBufferIndex, hcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // CYCLES ... + + // + // SHORT ... + + // + ENUM_DRAW_TYPE sDrawType = showShortCycle ? DRAW_LINE : DRAW_NONE; + + // + // HH ... + + // + ArraySetAsSeries(sHHBuffer, true); + SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showShortCycle); + PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_TYPE, sDrawType); + PlotIndexSetDouble(sHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // LL ... + + // + ArraySetAsSeries(sLLBuffer, true); + SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showShortCycle); + PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_TYPE, sDrawType); + PlotIndexSetDouble(sLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // MEDIUM ... + + // + ENUM_DRAW_TYPE mDrawType = showMediumCycle ? DRAW_LINE : DRAW_NONE; + + // + // HH ... + + // + ArraySetAsSeries(mHHBuffer, true); + SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showMediumCycle); + PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_TYPE, mDrawType); + PlotIndexSetDouble(mHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // LL ... + + // + ArraySetAsSeries(mLLBuffer, true); + SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showMediumCycle); + PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_TYPE, mDrawType); + PlotIndexSetDouble(mLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // LONG ... + + // + ENUM_DRAW_TYPE lDrawType = showLongCycle ? DRAW_LINE : DRAW_NONE; + + // + // HH ... + + // + ArraySetAsSeries(lHHBuffer, true); + SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLongCycle); + PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_TYPE, lDrawType); + PlotIndexSetDouble(lHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // LL ... + + // + ArraySetAsSeries(lLLBuffer, true); + SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLongCycle); + PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_TYPE, lDrawType); + PlotIndexSetDouble(lLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // HIND ... + + // + ENUM_DRAW_TYPE hDrawType = showHindCycle ? DRAW_LINE : DRAW_NONE; + + // + // HH ... + + // + ArraySetAsSeries(hHHBuffer, true); + SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showHindCycle); + PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_TYPE, hDrawType); + PlotIndexSetDouble(hHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // LL ... + + // + ArraySetAsSeries(hLLBuffer, true); + SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showHindCycle); + PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_TYPE, hDrawType); + PlotIndexSetDouble(hLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // Data Buffers ... + + // + // SC ... + ArraySetAsSeries(scMaStateBuffer, true); + SetIndexBuffer(scMaStateBufferIndex, scMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // MC ... + ArraySetAsSeries(mcMaStateBuffer, true); + SetIndexBuffer(mcMaStateBufferIndex, mcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // LC ... + ArraySetAsSeries(lcMaStateBuffer, true); + SetIndexBuffer(lcMaStateBufferIndex, lcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // HC ... + ArraySetAsSeries(hcMaStateBuffer, true); + SetIndexBuffer(hcMaStateBufferIndex, hcMaStateBuffer, INDICATOR_CALCULATIONS); + + // +} + +/** + * Initial Market Cycles ... + * + * @return ( bool ) + */ +bool InitCycles() +{ + // + 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; + + // + // Selecte Applied Cycle ... + if (result) + { + // + int normalizedMALength = maLength > 0 + ? maLength + : 1; + + // + mSCMALength = + mSCLength * normalizedMALength; + mMCMALength = + mMCLength * normalizedMALength; + mLCMALength = + mLCLength * normalizedMALength; + mHCMALength = + mHCLength * normalizedMALength; + } + + // + return result; +} + +/** + * Initial all Indicator Requirements ... + * + * @return ( false ) + * + */ +bool InitRequirements() +{ + // + bool result = false; + + // + // Handlers ... + + // + // SC ... + scMaHandler = iMA( + _Symbol, + _Period, + mSCMALength, + 0, + maMethod, + maAppliedTo // + ); + result = scMaHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // MC ... + mcMaHandler = iMA( + _Symbol, + _Period, + mMCMALength, + 0, + maMethod, + maAppliedTo // + ); + result = mcMaHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // LC ... + lcMaHandler = iMA( + _Symbol, + _Period, + mLCMALength, + 0, + maMethod, + maAppliedTo // + ); + result = lcMaHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // HC ... + hcMaHandler = iMA( + _Symbol, + _Period, + mHCMALength, + 0, + maMethod, + maAppliedTo // + ); + result = hcMaHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + mDrawer = new XCPOIDrawer(); + + // + return result; +} + +/** + * Calculate Custom Buffers ... + * + * @param barIndex: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateBuffers( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int barsLimit = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : 0; + if (barsLimit == 0) + { + // + barsLimit = ratesTotal; + firstBarIndex = barsLimit - 1; + } + else + { + firstBarIndex = startCalculationForLastBars; + } + + // + // bool canCalculate = true; + bool canCalculate = + barIndex <= barsLimit; + if (canCalculate) + { + // + // Calculate Values ... + CalculateValues( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + } + else + { + FillBuffersZero(barIndex); + } +} + +/** + * Fill All Bufers to Zero Vlue for Specified Bar Index ... + * + * @param barIndex: Integer ... + */ +void FillBuffersZero(int barIndex) +{ + // + scMaColorBuffer[barIndex] = hideColorIDX; + mcMaColorBuffer[barIndex] = hideColorIDX; + lcMaColorBuffer[barIndex] = hideColorIDX; + hcMaColorBuffer[barIndex] = hideColorIDX; +} + +/** + * Calculate Values ... + * + * @param barIndex: int, Specified Bar Index ... + * @param prevCalculated: int, Provides Previous Calculated Bars ... + * @param ratesTotal: int, Provides All Availabled Bars ... + * @param open: double Collection, Provides Open Prices Time Series ... + * @param high: double Collection, Provides High Prices Time Series ... + * @param close: double Collection, Provides Close Prices Time Series ... + * @param low: double Collection, Provides Low Prices Time Series ... + * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... + */ +void CalculateValues( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int lastBarIndex = barIndex + 1; + int maxBarIndex = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : ratesTotal; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + // Cycle Ranges ... + CalculateCycleRanges( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // Cycle MAs ... + CalculateCycleMAs( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // Do Process if Required ... + DoProcess( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycleRanges( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // SHORT ... + CalculateCycleRange( + barIndex, + X_MARKET_CYCLE_SHORT, + sHHBuffer, + sLLBuffer // + ); + + // + // MEDIUM ... + CalculateCycleRange( + barIndex, + X_MARKET_CYCLE_MEDIUM, + mHHBuffer, + mLLBuffer // + ); + + // + // LONG ... + CalculateCycleRange( + barIndex, + X_MARKET_CYCLE_LONG, + lHHBuffer, + lLLBuffer // + ); + + // + // HIND ... + CalculateCycleRange( + barIndex, + X_MARKET_CYCLE_HIND, + hHHBuffer, + hLLBuffer // + ); +} + +// +void CalculateCycleMAs( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // SHORT ... + CalculateCycleMA( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + showShortCycleMa, + scMaBuffer, + scMaColorBuffer, + scMaStateBuffer // + ); + + // + // MEDIUM ... + CalculateCycleMA( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + showMediumCycleMa, + mcMaBuffer, + mcMaColorBuffer, + mcMaStateBuffer // + ); + + // + // LONG ... + CalculateCycleMA( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + showLongCycleMa, + lcMaBuffer, + lcMaColorBuffer, + lcMaStateBuffer // + ); + + // + // HIND ... + CalculateCycleMA( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + showHindCycleMa, + hcMaBuffer, + hcMaColorBuffer, + hcMaStateBuffer // + ); +} + +/** + * Calculate Specified Market Cycle Range ... + * + * @param barIndex: Integer, Bar Index ... + * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... + * @param hhBuffer: Highest High Buffer Reference ... + * @param llBuffer: Lowest Low Buffer Reference ... + */ +void CalculateCycleRange( + int barIndex, + ENUM_X_MARKET_CYCLES cycle, + double &hhBuffer[], + double &llBuffer[] // +) +{ + // + XOHCL bar; + bool isBarInited = bar.Init( + _Symbol, + _Period, + barIndex + // + ); + if (!isBarInited) + { + return; + } + + // + 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; + } + + // + // Find Highest High ... + double hhValue = bar.FindHighest( + mLength, + upperMode // + ); + hhBuffer[barIndex] = hhValue; + + // + // Find Lowest Low ... + double llValue = bar.FindLowest( + mLength, + lowerMode // + ); + llBuffer[barIndex] = llValue; + + // + bar.Clean(); +} + +/** + * Calculate Specified Market Cycle MA ... + * + * @param barIndex: Integer, Bar Index ... + * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... + * @param hhBuffer: Highest High Buffer Reference ... + * @param llBuffer: Lowest Low Buffer Reference ... + */ +void CalculateCycleMA( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + bool show, + double &maBuffer[], + double &colorBuffer[], + double &stateBuffer[] // +) +{ + // + double iLow = low[barIndex]; + double iHigh = high[barIndex]; + double iOpen = open[barIndex]; + double iClose = close[barIndex]; + double iValue = maBuffer[barIndex]; + + // + bool basedOnClose = false; + + // + double iState = neuturalState; + double iColor = neuturalColorIDX; + if (basedOnClose) + { + // + iColor = + iClose > iValue + ? bullishColorIDX + : iClose < iValue + ? bearishColorIDX + : neuturalColorIDX; + + // + iState = + iClose > iValue + ? bullishState + : iClose < iValue + ? bearishState + : neuturalState; + } + else + { + // + iColor = + iLow > iValue + ? bullishColorIDX + : iHigh < iValue + ? bearishColorIDX + : neuturalColorIDX; + + // + iState = + iLow > iValue + ? bullishState + : iHigh < iValue + ? bearishState + : neuturalState; + } + stateBuffer[barIndex] = iState; + colorBuffer[barIndex] = show + ? iColor + : hideColorIDX; +} + +// +// Process Bars ... +void DoProcess( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int lastBarIndex = barIndex + 1; + int maxBarIndex = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : ratesTotal; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + if (isFirstBar) + { + return; + } + + // + int minRequiredRange = 20; + if (barIndex > maxBarIndex + minRequiredRange + 4) + { + return; + } + + // + XOHCL iBar; + bool has = iBar.Init( + _Symbol, + _Period, + barIndex // + ); + if (!has) + { + // + iBar.Clean(); + + // + return; + } + + // + // Reading Values ... + + // + double iLow = low[barIndex]; + double iHigh = high[barIndex]; + double iOpen = open[barIndex]; + double iClose = close[barIndex]; + + // + double iPLow = low[barIndex + 1]; + double iPHigh = high[barIndex + 1]; + double iPOpen = open[barIndex + 1]; + double iPClose = close[barIndex + 1]; + + // + double iSCMa = scMaBuffer[barIndex]; + double iMCMa = mcMaBuffer[barIndex]; + double iLCMa = lcMaBuffer[barIndex]; + double iHCMa = hcMaBuffer[barIndex]; + + // + double iPSCMa = scMaBuffer[barIndex + 1]; + double iPMCMa = mcMaBuffer[barIndex + 1]; + double iPLCMa = lcMaBuffer[barIndex + 1]; + double iPHCMa = hcMaBuffer[barIndex + 1]; + + // + // SC Range ... + + // + double iSCLL = sLLBuffer[barIndex]; + double iSCHH = sHHBuffer[barIndex]; + + // + double iPSCLL = sLLBuffer[barIndex + 1]; + double iPSCHH = sHHBuffer[barIndex + 1]; + + // + double iP2SCLL = sLLBuffer[barIndex + 2]; + double iP2SCHH = sHHBuffer[barIndex + 2]; + + // + double iP3SCLL = sLLBuffer[barIndex + 3]; + double iP3SCHH = sHHBuffer[barIndex + 3]; + + // + double iP4SCLL = sLLBuffer[barIndex + 4]; + double iP4SCHH = sHHBuffer[barIndex + 4]; + + // + // MC Range ... + + // + double iMCLL = mLLBuffer[barIndex]; + double iMCHH = mHHBuffer[barIndex]; + + // + double iPMCLL = mLLBuffer[barIndex + 1]; + double iPMCHH = mHHBuffer[barIndex + 1]; + + // + double iP2MCLL = mLLBuffer[barIndex + 2]; + double iP2MCHH = mHHBuffer[barIndex + 2]; + + // + double iP3MCLL = mLLBuffer[barIndex + 3]; + double iP3MCHH = mHHBuffer[barIndex + 3]; + + // + double iP4MCLL = mLLBuffer[barIndex + 4]; + double iP4MCHH = mHHBuffer[barIndex + 4]; + + // + // LC Range ... + + // + double iLCLL = lLLBuffer[barIndex]; + double iLCHH = lHHBuffer[barIndex]; + + // + double iPLCLL = lLLBuffer[barIndex + 1]; + double iPLCHH = lHHBuffer[barIndex + 1]; + + // + double iP2LCLL = lLLBuffer[barIndex + 2]; + double iP2LCHH = lHHBuffer[barIndex + 2]; + + // + double iP3LCLL = lLLBuffer[barIndex + 3]; + double iP3LCHH = lHHBuffer[barIndex + 3]; + + // + double iP4LCLL = lLLBuffer[barIndex + 4]; + double iP4LCHH = lHHBuffer[barIndex + 4]; + + // + // HC Range ... + + // + double iHCLL = hLLBuffer[barIndex]; + double iHCHH = hHHBuffer[barIndex]; + + // + double iPHCLL = hLLBuffer[barIndex + 1]; + double iPHCHH = hHHBuffer[barIndex + 1]; + + // + double iP2HCLL = hLLBuffer[barIndex + 2]; + double iP2HCHH = hHHBuffer[barIndex + 2]; + + // + double iP3HCLL = hLLBuffer[barIndex + 3]; + double iP3HCHH = hHHBuffer[barIndex + 3]; + + // + double iP4HCLL = hLLBuffer[barIndex + 4]; + double iP4HCHH = hHHBuffer[barIndex + 4]; + + // + // Cycle States ... + + // + double iSCMaState = scMaStateBuffer[barIndex]; + double iMCMaState = mcMaStateBuffer[barIndex]; + double iLCMaState = lcMaStateBuffer[barIndex]; + double iHCMaState = hcMaStateBuffer[barIndex]; + + // + double iPSCMaState = scMaStateBuffer[barIndex + 1]; + double iPMCMaState = mcMaStateBuffer[barIndex + 1]; + double iPLCMaState = lcMaStateBuffer[barIndex + 1]; + double iPHCMaState = hcMaStateBuffer[barIndex + 1]; + + // + // Create Conditions ... + + // + bool isLCMaOverHCMa = iMCMa > iHCMa; + bool isPLCMaOverHCMa = iPMCMa > iPHCMa; + + // + bool isLCMaUnderHCMa = iMCMa < iHCMa; + bool isPLCMaUnderHCMa = iPMCMa < iPHCMa; + + // + bool isLCMaCrossedOverHCMa = + isLCMaOverHCMa && + !isPLCMaOverHCMa; + + // + bool isLCMaCrossedUnderHCMa = + isLCMaUnderHCMa && + !isPLCMaUnderHCMa; + + // + // SC State ... + + // + bool isSCMaBullish = + iSCMaState == bullishState; + bool isPSCMaBullish = + iPSCMaState == bullishState; + + // + bool isSCMaBearish = + iSCMaState == bearishState; + bool isPSCMaBearish = + iPSCMaState == bearishState; + + // + bool isSCMaSwitchedToBullish = + isSCMaBullish && + !isPSCMaBullish; + + // + bool isSCMaSwitchedToBearish = + isSCMaBearish && + !isPSCMaBearish; + + // + bool isSCLLOverMCLL = + iSCLL > iMCLL; + bool isPSCLLOverMCLL = + iPSCLL > iPMCLL; + bool isP2SCLLOverMCLL = + iP2SCLL > iP2MCLL; + bool isP3SCLLOverMCLL = + iP3SCLL > iP3MCLL; + bool isP4SCLLOverMCLL = + iP4SCLL > iP4MCLL; + + // + bool isSCHHUnderMCHH = + iSCHH < iMCHH; + bool isPSCHHUnderMCHH = + iPSCHH < iPMCHH; + bool isP2SCHHUnderMCHH = + iP2SCHH < iP2MCHH; + bool isP3SCHHUnderMCHH = + iP3SCHH < iP3MCHH; + bool isP4SCHHUnderMCHH = + iP4SCHH < iP4MCHH; + + // + bool isSCLLCrossedOverMCLL = + isSCLLOverMCLL && + !isPSCLLOverMCLL; + bool isPSCLLCrossedOverMCLL = + isPSCLLOverMCLL && + !isP2SCLLOverMCLL; + bool isP2SCLLCrossedOverMCLL = + isP2SCLLOverMCLL && + !isP3SCLLOverMCLL; + bool isP3SCLLCrossedOverMCLL = + isP3SCLLOverMCLL && + !isP4SCLLOverMCLL; + + // + bool isSCHHCrossedUnderMCHH = + isSCHHUnderMCHH && + !isPSCHHUnderMCHH; + bool isPSCHHCrossedUnderMCHH = + isPSCHHUnderMCHH && + !isP2SCHHUnderMCHH; + bool isP2SCHHCrossedUnderMCHH = + isP2SCHHUnderMCHH && + !isP3SCHHUnderMCHH; + bool isP3SCHHCrossedUnderMCHH = + isP3SCHHUnderMCHH && + !isP4SCHHUnderMCHH; + + // + // MC State ... + + // + bool isMCMaBullish = + iMCMaState == bullishState; + bool isPMCMaBullish = + iPMCMaState == bullishState; + + // + bool isMCMaBearish = + iMCMaState == bearishState; + bool isPMCMaBearish = + iPMCMaState == bearishState; + + // + bool isMCMaSwitchedToBullish = + isMCMaBullish && + !isPMCMaBullish; + + // + bool isMCMaSwitchedToBearish = + isMCMaBearish && + !isPMCMaBearish; + + // + bool isMCLLOverLCLL = + iMCLL > iLCLL; + bool isPMCLLOverLCLL = + iPMCLL > iPLCLL; + bool isP2MCLLOverLCLL = + iP2MCLL > iP2LCLL; + bool isP3MCLLOverLCLL = + iP3MCLL > iP3LCLL; + bool isP4MCLLOverLCLL = + iP4MCLL > iP4LCLL; + + // + bool isMCHHUnderLCHH = + iMCHH < iLCHH; + bool isPMCHHUnderLCHH = + iPMCHH < iPLCHH; + bool isP2MCHHUnderLCHH = + iP2MCHH < iP2LCHH; + bool isP3MCHHUnderLCHH = + iP3MCHH < iP3LCHH; + bool isP4MCHHUnderLCHH = + iP4MCHH < iP4LCHH; + + // + bool isMCLLCrossedOverLCLL = + isMCLLOverLCLL && + !isPMCLLOverLCLL; + bool isPMCLLCrossedOverLCLL = + isPMCLLOverLCLL && + !isP2MCLLOverLCLL; + bool isP2MCLLCrossedOverLCLL = + isP2MCLLOverLCLL && + !isP3MCLLOverLCLL; + bool isP3MCLLCrossedOverLCLL = + isP3MCLLOverLCLL && + !isP4MCLLOverLCLL; + + // + bool isMCHHCrossedUnderLCHH = + isMCHHUnderLCHH && + !isPMCHHUnderLCHH; + bool isPMCHHCrossedUnderLCHH = + isPMCHHUnderLCHH && + !isP2MCHHUnderLCHH; + bool isP2MCHHCrossedUnderLCHH = + isP2MCHHUnderLCHH && + !isP3MCHHUnderLCHH; + bool isP3MCHHCrossedUnderLCHH = + isP3MCHHUnderLCHH && + !isP4MCHHUnderLCHH; + + // + // LC State ... + + // + bool isLCMaBullish = + iLCMaState == bullishState; + bool isPLCMaBullish = + iPLCMaState == bullishState; + + // + bool isLCMaBearish = + iLCMaState == bearishState; + bool isPLCMaBearish = + iPLCMaState == bearishState; + + // + bool isLCMaSwitchedToBullish = + isLCMaBullish && + !isPLCMaBullish; + + // + bool isLCMaSwitchedToBearish = + isLCMaBearish && + !isPLCMaBearish; + + // + bool isLCLLOverHCLL = + iLCLL > iHCLL; + bool isPLCLLOverHCLL = + iPLCLL > iPHCLL; + bool isP2LCLLOverHCLL = + iP2LCLL > iP2HCLL; + bool isP3LCLLOverHCLL = + iP3LCLL > iP3HCLL; + bool isP4LCLLOverHCLL = + iP4LCLL > iP4HCLL; + + // + bool isLCHHUnderHCHH = + iLCHH < iHCHH; + bool isPLCHHUnderHCHH = + iPLCHH < iPHCHH; + bool isP2LCHHUnderHCHH = + iP2LCHH < iP2HCHH; + bool isP3LCHHUnderHCHH = + iP3LCHH < iP3HCHH; + bool isP4LCHHUnderHCHH = + iP4LCHH < iP4HCHH; + + // + bool isLCLLCrossedOverHCLL = + isLCLLOverHCLL && + !isPLCLLOverHCLL; + bool isPLCLLCrossedOverHCLL = + isPLCLLOverHCLL && + !isP2LCLLOverHCLL; + bool isP2LCLLCrossedOverHCLL = + isP2LCLLOverHCLL && + !isP3LCLLOverHCLL; + bool isP3LCLLCrossedOverHCLL = + isP3LCLLOverHCLL && + !isP4LCLLOverHCLL; + + // + bool isLCHHCrossedUnderHCHH = + isLCHHUnderHCHH && + !isPLCHHUnderHCHH; + bool isPLCHHCrossedUnderHCHH = + isPLCHHUnderHCHH && + !isP2LCHHUnderHCHH; + bool isP2LCHHCrossedUnderHCHH = + isP2LCHHUnderHCHH && + !isP3LCHHUnderHCHH; + bool isP3LCHHCrossedUnderHCHH = + isP3LCHHUnderHCHH && + !isP4LCHHUnderHCHH; + + // + // HC State ... + + // + bool isHCMaBullish = + iHCMaState == bullishState; + bool isPHCMaBullish = + iPHCMaState == bullishState; + + // + bool isHCMaBearish = + iHCMaState == bearishState; + bool isPHCMaBearish = + iPHCMaState == bearishState; + + // + bool isHCMaSwitchedToBullish = + isHCMaBullish && + !isPHCMaBullish; + + // + bool isHCMaSwitchedToBearish = + isHCMaBearish && + !isPHCMaBearish; + + // + // Check Price Inside Cloud Zone ... + + // + double iCloudZoneUpper = MathMax(iLCMa, iHCMa); + double iCloudZoneLower = MathMin(iLCMa, iHCMa); + + // + double iPCloudZoneUpper = MathMax(iPLCMa, iPHCMa); + double iPCloudZoneLower = MathMin(iPLCMa, iPHCMa); + + // + bool isBullishPriceInsideCloudZone = + iLow < iCloudZoneUpper && + iLow > iCloudZoneLower; + + // + bool isPBullishPriceInsideCloudZone = + iPLow < iPCloudZoneUpper && + iPLow > iPCloudZoneLower; + + // + bool isBearishPriceInsideCloudZone = + iHigh > iCloudZoneLower && + iHigh < iCloudZoneUpper; + + // + bool isPBearishPriceInsideCloudZone = + iPHigh > iPCloudZoneLower && + iPHigh < iPCloudZoneUpper; + + // + bool isPriceBullishCrossedInsideCloudZone = + isBullishPriceInsideCloudZone && + !isPBullishPriceInsideCloudZone; + + // + bool isPriceBearishCrossedInsideCloudZone = + isBearishPriceInsideCloudZone && + !isPBearishPriceInsideCloudZone; + + // + // Detect Cloud Direction ... + + // + bool isLLBullish = + // + isSCLLCrossedOverMCLL && + isLCLLCrossedOverHCLL && + iHCLL < iCloudZoneUpper && + iHCLL < iCloudZoneLower + // + ; + + // + bool isHHBearish = + // + isSCHHCrossedUnderMCHH && + isLCHHCrossedUnderHCHH && + iHCHH > iCloudZoneUpper && + iHCHH > iCloudZoneLower + // + ; + + // + bool isBullish = + isLLBullish; + + // + bool isBearish = + isHHBearish; + + // + // false; + // (isLCMaUnderHCMa + // ? isLCMaBullish + // : isLCMaOverHCMa + // ? isHCMaBullish + // : false) && + // iHCLL < iCloudZoneLower; + + // + // false; + // (isLCMaOverHCMa + // ? isLCMaBearish + // : isLCMaUnderHCMa + // ? isHCMaBearish + // : false) && + // iHCHH > iCloudZoneUpper; + + // + // Filter Bullish / Berish Directons ... + + // // + // isBullish = + // false + // // isBullish && + // // isBullishPriceInsideCloudZone + // // isSCMaBullish && + // // isMCMaBullish && + // // (isLCMaBullish || + // // isHCMaBullish) + // ; + + // // + // isBearish = + // false + // // isBearish && + // // isBearishPriceInsideCloudZone + // // isSCMaBearish && + // // isMCMaBearish && + // // (isLCMaBearish || + // // isHCMaBearish) + // ; + + // + has = isBullish || + isBearish; + + // + // Draw Inside Zone Arrow ... + if (has) + { + // + int arrowWidth = 3; + int arrowCode = 159; + ENUM_ARROW_ANCHOR arrowAnchor = + isBullish + ? ANCHOR_BOTTOM + : ANCHOR_TOP; + color arrowColor = + isBullish + ? mDrawer.defaultBullishStyle.clr + : mDrawer.defaultBearishStyle.clr; + ENUM_X_PRICE arrowPriceType = + isBullish + ? X_PRICE_LOW + : X_PRICE_HIGH; + + // + XCBarArrowObject *iObj; + has = mDrawer.CreateBarArrow( + iBar, + iObj, + arrowPriceType, + arrowCode, + arrowColor, + arrowWidth, + arrowAnchor // + ); + if (has) + { + mObjects.Add(iObj); + } + } + + // + // Cleanup Resources ... + + // + iBar.Clean(); +} + +// +void ReadBarStyle() +{ + // + long chartId = ChartID(); + + // + _upColor = GetChartUpColor(chartId); + _downColor = GetChartDownColor(chartId); + _lineColor = GetChartLineColor(chartId); + _bullishColor = GetChartBullishColor(chartId); + _bearishColor = GetChartBearishColor(chartId); +} + +// +void ShowBars() +{ + // + long chartId = ChartID(); + + // + SetChartUpColor(_upColor, chartId); + SetChartDownColor(_downColor, chartId); + SetChartLineColor(_lineColor, chartId); + SetChartBullishColor(_bullishColor, chartId); + SetChartBearishColor(_bearishColor, chartId); +} + +// +void HideBars() +{ + // + long chartId = ChartID(); + + // + SetChartUpColor(CLR_NONE, chartId); + SetChartDownColor(CLR_NONE, chartId); + SetChartLineColor(CLR_NONE, chartId); + SetChartBullishColor(CLR_NONE, chartId); + SetChartBearishColor(CLR_NONE, chartId); +} + +// \ No newline at end of file diff --git a/Libraries/x-saherelm.common.extensions.lib.mq5 b/Libraries/x-saherelm.common.extensions.lib.mq5 index 50719e6e..b473547c 100644 --- a/Libraries/x-saherelm.common.extensions.lib.mq5 +++ b/Libraries/x-saherelm.common.extensions.lib.mq5 @@ -1056,7 +1056,7 @@ bool IsRunningOnTestMode() // // check programm mode ... - result = MQL5InfoInteger(MQL5_TESTING); + result = MQLInfoInteger(MQL_TESTER); // return result; diff --git a/XCATBEA/Classes/xcatbea.expert.class.mq5 b/XCATBEA/Classes/xcatbea.expert.class.mq5 index ac4e0f7c..1c2c5529 100644 --- a/XCATBEA/Classes/xcatbea.expert.class.mq5 +++ b/XCATBEA/Classes/xcatbea.expert.class.mq5 @@ -1972,12 +1972,12 @@ class XCXCATBEAExpert : public XCBase // // Make Available all Requirement Buffers of XCATB indicator ... - iSignallerInputs.catbInputs.showPV = false; - iSignallerInputs.catbInputs.showKI = false; - iSignallerInputs.catbInputs.showSar = false; - iSignallerInputs.catbInputs.showTrend = false; - iSignallerInputs.catbInputs.showATRBand = false; - iSignallerInputs.catbInputs.showPVGolden = false; + iSignallerInputs.catbInputs.showPV = true; + iSignallerInputs.catbInputs.showKI = true; + iSignallerInputs.catbInputs.showSar = true; + iSignallerInputs.catbInputs.showTrend = true; + iSignallerInputs.catbInputs.showATRBand = true; + iSignallerInputs.catbInputs.showPVGolden = true; // // Signalling Configurations ... diff --git a/XCATBEA/Classes/xcatbea.signaller.class.mq5 b/XCATBEA/Classes/xcatbea.signaller.class.mq5 index 2a9138a0..5da4003a 100644 --- a/XCATBEA/Classes/xcatbea.signaller.class.mq5 +++ b/XCATBEA/Classes/xcatbea.signaller.class.mq5 @@ -199,10 +199,10 @@ class XCXCATBEASignaller : XCBase double slATRMultiplier; // SL ATR Multiplier ... // - XBarTracker barTraker; // Bar Tracker ... XCX121XCatbHelper *helper; // XCATB Helper Class instance ... XCBarAnalyser *barAnalyser; // Bar Analyser ... XCXCATBEAPOIDrawer *drawer; // POI Drawer ... + XBarTracker ticksBarTracker; // Bar Tracker ... XTriggerBlockFilters filters; // Trigger Block Filters ... XCXCATBEAPOIDetector *detector; // POI Detector ... XTriggerBlockValidationRules validations; // Trigger Block Validations ... @@ -295,6 +295,13 @@ class XCXCATBEASignaller : XCBase barIndex // ); + // + // Check Bar Processing ... + if (!ticksBarTracker.CanProcessBar()) + { + return; + } + // // Check Triggered Conditions ... has = HasChild(mConditionsCollection); @@ -378,13 +385,6 @@ class XCXCATBEASignaller : XCBase } } - // - // Check Bar Processing ... - if (!barTraker.CanProcessBar()) - { - return; - } - // // Initialize Bar ... bar.Init( @@ -518,7 +518,7 @@ class XCXCATBEASignaller : XCBase if (has) { // - barTraker.Waits(); + ticksBarTracker.Waits(); // AddConditionsIfNotExists(); @@ -1514,12 +1514,12 @@ class XCXCATBEASignaller : XCBase .IsValidForTrigger( cConditions.bars[0], triggerDir, - false, // Allow Cond 1 ... - false, // Allow Cond 2 ... - false, // Allow Cond 3 ... - false, // Allow Cond 4 ... - false, // Allow Cond 5 ... - false, // Allow Cond 6 ... + true, // Allow Cond 1 ... + true, // Allow Cond 2 ... + true, // Allow Cond 3 ... + true, // Allow Cond 4 ... + true, // Allow Cond 5 ... + true, // Allow Cond 6 ... true // Allow Cond 7 ... // ); @@ -1571,79 +1571,111 @@ class XCXCATBEASignaller : XCBase DrawPivotZone(conditions.pivotZone); // - // Check atleast 3 Bars Close Outside of applied Edge ... - // Check Current Bar is a Trigger Bar ... - // TODO: Complete this ... - - // - // Checking Score ... - double bullishScore = 0; - double bearishScore = 0; - cConditions - .GenerateScore( - bullishScore, - bearishScore // - ); - bool isScorePassed = - true; - // isBullish - // ? bullishScore > bearishScore - // : bearishScore > bullishScore; - - // - // Check Bar is Inside Zone ... - bool isBarInside = - (isBullish - ? (cConditions.bars[1].low < conditions.pivotZone.upper && - cConditions.bars[1].low > conditions.pivotZone.lower) - : (cConditions.bars[1].high > conditions.pivotZone.lower && - cConditions.bars[1].high < conditions.pivotZone.upper)); - - // - isBullish = - isBullish && - isBarInside && - isScorePassed && - isBullishTriggerBar; - - // - isBearish = - isBearish && - isBarInside && - isScorePassed && - isBearishTriggerBar; - - // - result = isBullish || - isBearish; - if (result) + // Trigger on Detection Time ... + bool triggerPivotZonesOnSetupTime = true; + if (triggerPivotZonesOnSetupTime) { + // + conditions.triggerTime = TimeCurrent(); + } + else + { + // + // Check atleast 3 Bars Close Outside of applied Edge ... + // Check Current Bar is a Trigger Bar ... + // TODO: Complete this ... // - // Check Bar is Touched Zone Middle or not ... - double mid = conditions.pivotZone.GetMid(); - bool isMiddlePassed = + // Checking Score ... + double bullishScore = 0; + double bearishScore = 0; + cConditions + .GenerateScore( + bullishScore, + bearishScore // + ); + bool isScorePassed = isBullish - ? (cConditions.bars[1].low < mid && - cConditions.bars[1].GetDown() > mid) - : (cConditions.bars[1].high > mid && - cConditions.bars[1].GetUp() < mid); + ? bullishScore > bearishScore + : bearishScore > bullishScore; + // true; // - result = - result && - isMiddlePassed; + // Check Bar is Inside Zone ... + bool isBarInside = + (isBullish + ? (cConditions.bars[1].low < conditions.pivotZone.upper && + cConditions.bars[1].low > conditions.pivotZone.lower) + : (cConditions.bars[1].high > conditions.pivotZone.lower && + cConditions.bars[1].high < conditions.pivotZone.upper)); // + // Checking Conditions Requirements ... + + // + bool isConditionsBullishPowered = + // + // Trend ... + (cConditions.isTrendBullish || + (!cConditions.isTrendBullish && + !cConditions.isTrendBearish)); + + // + bool isConditionsBearishPowered = + // + // Trend ... + (cConditions.isTrendBearish || + (!cConditions.isTrendBullish && + !cConditions.isTrendBearish)); + + // + isBullish = + isBullish && + isBarInside && + isScorePassed && + isBullishTriggerBar && + isConditionsBullishPowered; + + // + isBearish = + isBearish && + isBarInside && + isScorePassed && + isBearishTriggerBar && + isConditionsBearishPowered; + + // + result = isBullish || + isBearish; + result = false; if (result) { + // - Print("Trigger Bar Detected ..."); - conditions.triggerTime = TimeCurrent(); + // Check Bar is Touched Zone Middle or not ... + double mid = conditions.pivotZone.GetMid(); + bool isMiddlePassed = + isBullish + ? (cConditions.bars[1].low < mid && + cConditions.bars[1].GetDown() > mid) + : (cConditions.bars[1].high > mid && + cConditions.bars[1].GetUp() < mid); + + // + // Ignore Box Middle Pass ... + // result = + // result && + // isMiddlePassed; + + // + if (result) + { + // + // Print("Trigger Bar Detected ..."); + conditions.triggerTime = TimeCurrent(); + } } } - - // } // @@ -1800,7 +1832,7 @@ class XCXCATBEASignaller : XCBase // // Initialize Bar Tracker ... - has = barTraker.Init( + has = ticksBarTracker.Init( symbol, period // ); @@ -1809,6 +1841,8 @@ class XCXCATBEASignaller : XCBase return; } + // + // // Initialize Bar Analyser ... barAnalyser = new XCBarAnalyser(); @@ -1863,7 +1897,7 @@ class XCXCATBEASignaller : XCBase ZeroMemory(barAnalyser); // - barTraker.Clean(); + ticksBarTracker.Clean(); } /** diff --git a/XCATBEA/Libraries/xcatbea.signaller.lib.mq5 b/XCATBEA/Libraries/xcatbea.signaller.lib.mq5 index 3ed761cc..c8b2b543 100644 --- a/XCATBEA/Libraries/xcatbea.signaller.lib.mq5 +++ b/XCATBEA/Libraries/xcatbea.signaller.lib.mq5 @@ -860,17 +860,40 @@ bool DetectSignalZone( isMomentum && IsBearish(iBDir); + // + bool isTriggerBar = barAnalyser + .IsValidForTrigger( + conditions.bars[0], + iBDir, + true, // Allow Cond 1 ... + true, // Allow Cond 2 ... + true, // Allow Cond 3 ... + true, // Allow Cond 4 ... + true, // Allow Cond 5 ... + true, // Allow Cond 6 ... + true // Allow Cond 7 ... + // + ); + bool isBullishTriggerBar = + isTriggerBar && + IsBullish(iBDir); + bool isBearishTriggerBar = + isTriggerBar && + IsBearish(iBDir); + // bool isBarBullishPressured = isBullishRejected || isBullishEngulfed || - isBullishMomentum; + isBullishMomentum || + isBullishTriggerBar; // bool isBarBearishPressured = isBearishRejected || isBearishEngulfed || - isBearishMomentum; + isBearishMomentum || + isBearishTriggerBar; // // Implement Signalling Conditions ... @@ -881,9 +904,12 @@ bool DetectSignalZone( // -------------- // Descriptions: // - [] Detect Parabolic Sar Direction Change ... - // - [] Check Some others Conditions based on Changed Direction ... - // - [] Generate Direction Change Zone ... - // - [] Use it to Fill Signal Zone ... + // - [] KI is Directional ... + // - [] Bar Has Pressured ... + // - [] ATR is Directional Up/Down ... + // - [] TREND is Directional ... + // - [] TREND is Directional Change ... + // - [] TREND is Directional Up/Down ... // ------------------------------------ // @@ -912,8 +938,9 @@ bool DetectSignalZone( conditions.isATRUp && // // TREND ... - conditions.isTrendUp // && - // conditions.isTrendBullish + isTrendBullishStart && + conditions.isTrendUp && + conditions.isTrendBullish // ; @@ -938,8 +965,9 @@ bool DetectSignalZone( conditions.isATRDown && // // TREND ... - conditions.isTrendDown // && - // conditions.isTrendBearish + isTrendBearishStart && + conditions.isTrendDown && + conditions.isTrendBearish // ; } @@ -990,29 +1018,59 @@ bool DetectSignalZone( // - [] Generate Direction Change Zone ... // - [] Use it to Fill Signal Zone ... // ------------------------------------ + // Descriptions: + // - [] + // ------------------------------------ // bool isCond2Bullish = false; bool isCond2Bearish = false; if (allowSignallingConditions2) { - // - isCond2Bullish = - // - // Start ... - (isTrendBullishStart && - !isTrendBearishStart) - // - ; + // // + // isCond2Bullish = + // // + // // Start ... + // (isTrendBullishStart && + // !isTrendBearishStart) + // // + // ; + + // // + // isCond2Bearish = + // // + // // Start ... + // (isTrendBearishStart && + // !isTrendBullishStart) + // // + // ; // + // Temp Cndition 2 ... + + // + // Bullish ... + isCond2Bullish = + isScoreBullish && + isBullishTriggerBar && + conditions.isKIBullish && + conditions.isSarSwitchedToBullish; + // isScoreBullish && + // isBarBullishPressured && + // conditions.isKISwitchedToBullish && + // conditions.isSarSwitchedToBullish; + + // + // Bearish ... isCond2Bearish = - // - // Start ... - (isTrendBearishStart && - !isTrendBullishStart) - // - ; + isScoreBearish && + isBearishTriggerBar && + conditions.isKIBearish && + conditions.isSarSwitchedToBearish; + // isScoreBearish && + // isBarBearishPressured && + // conditions.isKISwitchedToBearish && + // conditions.isSarSwitchedToBearish; } // @@ -1021,6 +1079,10 @@ bool DetectSignalZone( isCond2Bearish; if (isCond2) { + // + // Retireve Conditions 2 ... + Print("Condition 2 Happens ..."); + // // Generate Direction Shift Zone ... has = GenerateTrendDirectionShiftBox( @@ -1443,8 +1505,6 @@ bool DetectSignalZone( } // - Print("Conditions ..."); - // signalZone.Clean(); } //