diff --git a/Helpers/x-saherelm.xfima.helper.mq5 b/Helpers/x-saherelm.xfima.helper.mq5 index c940415c..2e2b9a95 100644 --- a/Helpers/x-saherelm.xfima.helper.mq5 +++ b/Helpers/x-saherelm.xfima.helper.mq5 @@ -61,32 +61,40 @@ enum ENUM_XFIMA_BUFFERS XFIMA_PB_BAND_LOWER_LINE = 22, XFIMA_ATR_BAND_UPPER_LINE = 23, XFIMA_ATR_BAND_LOWER_LINE = 24, + XFIMA_SC_MA_LINE = 25, + XFIMA_MC_MA_LINE = 26, + XFIMA_LC_MA_LINE = 27, + XFIMA_HC_MA_LINE = 28, // // Data Buffers ... - XFIMA_MA_FAST_STATE_LINE = 25, - XFIMA_MA_SLOW_STATE_LINE = 26, - XFIMA_SAR_STATE_LINE = 27, - XFIMA_SC_HH_LINE = 28, - XFIMA_SC_LL_LINE = 29, - XFIMA_MC_HH_LINE = 30, - XFIMA_MC_LL_LINE = 31, - XFIMA_LC_HH_LINE = 32, - XFIMA_LC_LL_LINE = 33, - XFIMA_HC_HH_LINE = 34, - XFIMA_HC_LL_LINE = 35, - XFIMA_ZIGZAG_HIGHS_LINE = 36, - XFIMA_ZIGZAG_HIGHS_TIME_LINE = 37, - XFIMA_ZIGZAG_LOWS_LINE = 38, - XFIMA_ZIGZAG_LOWS_TIME_LINE = 39, - XFIMA_HK_RAW_OPEN_LINE = 40, - XFIMA_HK_RAW_HIGH_LINE = 41, - XFIMA_HK_RAW_LOW_LINE = 42, - XFIMA_HK_RAW_CLOSE_LINE = 43, - XFIMA_PB_BAND_RAW_UPPER_LINE = 44, - XFIMA_PB_BAND_RAW_LOWER_LINE = 45, - XFIMA_ATR_LINE = 46, - XFIMA_ATR_BAND_RAW_UPPER_LINE = 47, - XFIMA_ATR_BAND_RAW_LOWER_LINE = 48, + XFIMA_MA_FAST_STATE_LINE = 29, + XFIMA_MA_SLOW_STATE_LINE = 30, + XFIMA_SAR_STATE_LINE = 31, + XFIMA_SC_HH_LINE = 32, + XFIMA_SC_LL_LINE = 33, + XFIMA_MC_HH_LINE = 34, + XFIMA_MC_LL_LINE = 35, + XFIMA_LC_HH_LINE = 36, + XFIMA_LC_LL_LINE = 37, + XFIMA_HC_HH_LINE = 38, + XFIMA_HC_LL_LINE = 39, + XFIMA_ZIGZAG_HIGHS_LINE = 40, + XFIMA_ZIGZAG_HIGHS_TIME_LINE = 41, + XFIMA_ZIGZAG_LOWS_LINE = 42, + XFIMA_ZIGZAG_LOWS_TIME_LINE = 43, + XFIMA_HK_RAW_OPEN_LINE = 44, + XFIMA_HK_RAW_HIGH_LINE = 45, + XFIMA_HK_RAW_LOW_LINE = 46, + XFIMA_HK_RAW_CLOSE_LINE = 47, + XFIMA_PB_BAND_RAW_UPPER_LINE = 48, + XFIMA_PB_BAND_RAW_LOWER_LINE = 49, + XFIMA_ATR_LINE = 50, + XFIMA_ATR_BAND_RAW_UPPER_LINE = 51, + XFIMA_ATR_BAND_RAW_LOWER_LINE = 52, + XFIMA_SC_MA_STATE_LINE = 53, + XFIMA_MC_MA_STATE_LINE = 54, + XFIMA_LC_MA_STATE_LINE = 55, + XFIMA_HC_MA_STATE_LINE = 56, }; // @@ -144,6 +152,7 @@ struct XFIMAInputs bool showHKBand; // Show HK Band bool showATRBand; // Show ATR Band bool showZigZag; // Show ZigZag + bool showCyclesMa; // Show Cycles MA bool showFiboZone; // Show Fibo Zone int startCalculationForLastBars; // Calculate Last n Bars int sarArrowCode; // Parabolic SAR Arrow Code @@ -219,6 +228,7 @@ struct XFIMAInputs showHKBand = true; // Show HK Band showATRBand = true; // Show ATR Band showZigZag = true; // Show ZigZag + showCyclesMa = true; // Show Cycles MA showFiboZone = true; // Show Fibo Zone startCalculationForLastBars = 1500; // Calculate Last n Bars sarArrowCode = 159; // Parabolic SAR Arrow Code @@ -240,6 +250,7 @@ struct XFIMAInputs showHKBand = false; showATRBand = false; showZigZag = false; + showCyclesMa = true; showFiboZone = false; } @@ -312,22 +323,34 @@ struct XFIMAConditions // // Buffers ... double maFastBuffer[]; - double maFastColorBuffer[]; - double maFastStateBuffer[]; double maSlowBuffer[]; - double maSlowColorBuffer[]; - double maSlowStateBuffer[]; - double maBandUpperBuffer[]; - double maBandLowerBuffer[]; double sarBuffer[]; - double sarColorBuffer[]; - double sarStateBuffer[]; double peakBuffer[]; double valeBuffer[]; double fiboUpperBuffer[]; double fiboMiddleBuffer[]; double fiboLowerBuffer[]; double zigzagBuffer[]; + double maBandUpperBuffer[]; + double maBandLowerBuffer[]; + double hkOpenBuffer[]; + double hkHighBuffer[]; + double hkLowBuffer[]; + double hkCloseBuffer[]; + double hkColorBuffer[]; + double hkBandUpperBuffer[]; + double hkBandLowerBuffer[]; + double pbBandUpperBuffer[]; + double pbBandLowerBuffer[]; + double atrBandUpperBuffer[]; + double atrBandLowerBuffer[]; + double scMaBuffer[]; + double mcMaBuffer[]; + double lcMaBuffer[]; + double hcMaBuffer[]; + double maFastStateBuffer[]; + double maSlowStateBuffer[]; + double sarStateBuffer[]; double sHHBuffer[]; double sLLBuffer[]; double mHHBuffer[]; @@ -336,15 +359,19 @@ struct XFIMAConditions double lLLBuffer[]; double hHHBuffer[]; double hLLBuffer[]; - double highsBuffer[]; - double highsTimeBuffer[]; - double lowsBuffer[]; - double lowsTimeBuffer[]; - double hkOpenBuffer[]; - double hkHighBuffer[]; - double hkLowBuffer[]; - double hkCloseBuffer[]; - double hkColorBuffer[]; + double hkRawHighBuffer[]; + double hkRawOpenBuffer[]; + double hkRawLowBuffer[]; + double hkRawCloseBuffer[]; + double pbBandRawUpperBuffer[]; + double pbBandRawLowerBuffer[]; + double atrBuffer[]; + double atrBandRawUpperBuffer[]; + double atrBandRawLowerBuffer[]; + double scMaStateBuffer[]; + double mcMaStateBuffer[]; + double lcMaStateBuffer[]; + double hcMaStateBuffer[]; // // Conditions ... @@ -376,43 +403,59 @@ struct XFIMAConditions // Buffers ... // - SpecifiedClean(bars); + XClean(bars); // - SpecifiedClean(maFastBuffer); - SpecifiedClean(maFastColorBuffer); - SpecifiedClean(maFastStateBuffer); - SpecifiedClean(maSlowBuffer); - SpecifiedClean(maSlowColorBuffer); - SpecifiedClean(maSlowStateBuffer); - SpecifiedClean(maBandUpperBuffer); - SpecifiedClean(maBandLowerBuffer); - SpecifiedClean(sarBuffer); - SpecifiedClean(sarColorBuffer); - SpecifiedClean(sarStateBuffer); - SpecifiedClean(peakBuffer); - SpecifiedClean(valeBuffer); - SpecifiedClean(fiboUpperBuffer); - SpecifiedClean(fiboMiddleBuffer); - SpecifiedClean(fiboLowerBuffer); - SpecifiedClean(zigzagBuffer); - SpecifiedClean(sHHBuffer); - SpecifiedClean(sLLBuffer); - SpecifiedClean(mHHBuffer); - SpecifiedClean(mLLBuffer); - SpecifiedClean(lHHBuffer); - SpecifiedClean(lLLBuffer); - SpecifiedClean(hHHBuffer); - SpecifiedClean(hLLBuffer); - SpecifiedClean(highsBuffer); - SpecifiedClean(highsTimeBuffer); - SpecifiedClean(lowsBuffer); - SpecifiedClean(lowsTimeBuffer); - SpecifiedClean(hkOpenBuffer); - SpecifiedClean(hkHighBuffer); - SpecifiedClean(hkLowBuffer); - SpecifiedClean(hkCloseBuffer); - SpecifiedClean(hkColorBuffer); + XClean(maFastBuffer); + XClean(maSlowBuffer); + XClean(sarBuffer); + XClean(peakBuffer); + XClean(valeBuffer); + XClean(fiboUpperBuffer); + XClean(fiboMiddleBuffer); + XClean(fiboLowerBuffer); + XClean(zigzagBuffer); + XClean(maBandUpperBuffer); + XClean(maBandLowerBuffer); + XClean(hkOpenBuffer); + XClean(hkHighBuffer); + XClean(hkLowBuffer); + XClean(hkCloseBuffer); + XClean(hkColorBuffer); + XClean(hkBandUpperBuffer); + XClean(hkBandLowerBuffer); + XClean(pbBandUpperBuffer); + XClean(pbBandLowerBuffer); + XClean(atrBandUpperBuffer); + XClean(atrBandLowerBuffer); + XClean(scMaBuffer); + XClean(mcMaBuffer); + XClean(lcMaBuffer); + XClean(hcMaBuffer); + XClean(maFastStateBuffer); + XClean(maSlowStateBuffer); + XClean(sarStateBuffer); + XClean(sHHBuffer); + XClean(sLLBuffer); + XClean(mHHBuffer); + XClean(mLLBuffer); + XClean(lHHBuffer); + XClean(lLLBuffer); + XClean(hHHBuffer); + XClean(hLLBuffer); + XClean(hkRawHighBuffer); + XClean(hkRawOpenBuffer); + XClean(hkRawLowBuffer); + XClean(hkRawCloseBuffer); + XClean(pbBandRawUpperBuffer); + XClean(pbBandRawLowerBuffer); + XClean(atrBuffer); + XClean(atrBandRawUpperBuffer); + XClean(atrBandRawLowerBuffer); + XClean(scMaStateBuffer); + XClean(mcMaStateBuffer); + XClean(lcMaStateBuffer); + XClean(hcMaStateBuffer); // // Conditions ... @@ -422,22 +465,34 @@ struct XFIMAConditions // ArraySetAsSeries(maFastBuffer, true); - ArraySetAsSeries(maFastColorBuffer, true); - ArraySetAsSeries(maFastStateBuffer, true); ArraySetAsSeries(maSlowBuffer, true); - ArraySetAsSeries(maSlowColorBuffer, true); - ArraySetAsSeries(maSlowStateBuffer, true); - ArraySetAsSeries(maBandUpperBuffer, true); - ArraySetAsSeries(maBandLowerBuffer, true); ArraySetAsSeries(sarBuffer, true); - ArraySetAsSeries(sarColorBuffer, true); - ArraySetAsSeries(sarStateBuffer, true); ArraySetAsSeries(peakBuffer, true); ArraySetAsSeries(valeBuffer, true); ArraySetAsSeries(fiboUpperBuffer, true); ArraySetAsSeries(fiboMiddleBuffer, true); ArraySetAsSeries(fiboLowerBuffer, true); - ArraySetAsSeries(zigzagBuffer, false); // Fix this ... + ArraySetAsSeries(zigzagBuffer, true); + ArraySetAsSeries(maBandUpperBuffer, true); + ArraySetAsSeries(maBandLowerBuffer, true); + ArraySetAsSeries(hkOpenBuffer, true); + ArraySetAsSeries(hkHighBuffer, true); + ArraySetAsSeries(hkLowBuffer, true); + ArraySetAsSeries(hkCloseBuffer, true); + ArraySetAsSeries(hkColorBuffer, true); + ArraySetAsSeries(hkBandUpperBuffer, true); + ArraySetAsSeries(hkBandLowerBuffer, true); + ArraySetAsSeries(pbBandUpperBuffer, true); + ArraySetAsSeries(pbBandLowerBuffer, true); + ArraySetAsSeries(atrBandUpperBuffer, true); + ArraySetAsSeries(atrBandLowerBuffer, true); + ArraySetAsSeries(scMaBuffer, true); + ArraySetAsSeries(mcMaBuffer, true); + ArraySetAsSeries(lcMaBuffer, true); + ArraySetAsSeries(hcMaBuffer, true); + ArraySetAsSeries(maFastStateBuffer, true); + ArraySetAsSeries(maSlowStateBuffer, true); + ArraySetAsSeries(sarStateBuffer, true); ArraySetAsSeries(sHHBuffer, true); ArraySetAsSeries(sLLBuffer, true); ArraySetAsSeries(mHHBuffer, true); @@ -446,15 +501,19 @@ struct XFIMAConditions ArraySetAsSeries(lLLBuffer, true); ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hLLBuffer, true); - ArraySetAsSeries(highsBuffer, true); - ArraySetAsSeries(highsTimeBuffer, true); - ArraySetAsSeries(lowsBuffer, true); - ArraySetAsSeries(lowsTimeBuffer, true); - ArraySetAsSeries(hkOpenBuffer, true); - ArraySetAsSeries(hkHighBuffer, true); - ArraySetAsSeries(hkLowBuffer, true); - ArraySetAsSeries(hkCloseBuffer, true); - ArraySetAsSeries(hkColorBuffer, true); + ArraySetAsSeries(hkRawHighBuffer, true); + ArraySetAsSeries(hkRawOpenBuffer, true); + ArraySetAsSeries(hkRawLowBuffer, true); + ArraySetAsSeries(hkRawCloseBuffer, true); + ArraySetAsSeries(pbBandRawUpperBuffer, true); + ArraySetAsSeries(pbBandRawLowerBuffer, true); + ArraySetAsSeries(atrBuffer, true); + ArraySetAsSeries(atrBandRawUpperBuffer, true); + ArraySetAsSeries(atrBandRawLowerBuffer, true); + ArraySetAsSeries(scMaStateBuffer, true); + ArraySetAsSeries(mcMaStateBuffer, true); + ArraySetAsSeries(lcMaStateBuffer, true); + ArraySetAsSeries(hcMaStateBuffer, true); // ZeroMemory(this); @@ -743,6 +802,62 @@ class XCXFIMAHelper : public XCBaseHelper conditions.maSlowStateBuffer // ); + // + CopySCMA( + zIndex, + loopback, + conditions.scMaBuffer // + ); + + // + CopySCMAState( + zIndex, + loopback, + conditions.scMaStateBuffer // + ); + + // + CopyMCMA( + zIndex, + loopback, + conditions.mcMaBuffer // + ); + + // + CopyMCMAState( + zIndex, + loopback, + conditions.mcMaStateBuffer // + ); + + // + CopyLCMA( + zIndex, + loopback, + conditions.lcMaBuffer // + ); + + // + CopyLCMAState( + zIndex, + loopback, + conditions.lcMaStateBuffer // + ); + + // + CopyHCMA( + zIndex, + loopback, + conditions.hcMaBuffer // + ); + + // + CopyHCMAState( + zIndex, + loopback, + conditions.hcMaStateBuffer // + ); + // CopyMABandUpper( zIndex, @@ -897,6 +1012,34 @@ class XCXFIMAHelper : public XCBaseHelper conditions.hkCloseBuffer // ); + // + CopyHKRawOpen( + zIndex, + loopback, + conditions.hkRawOpenBuffer // + ); + + // + CopyHKRawHigh( + zIndex, + loopback, + conditions.hkRawHighBuffer // + ); + + // + CopyHKRawLow( + zIndex, + loopback, + conditions.hkRawLowBuffer // + ); + + // + CopyHKRawClose( + zIndex, + loopback, + conditions.hkRawCloseBuffer // + ); + // CopyHKColor( zIndex, @@ -904,6 +1047,86 @@ class XCXFIMAHelper : public XCBaseHelper conditions.hkColorBuffer // ); + // + CopyHKBandUpper( + zIndex, + loopback, + conditions.hkBandUpperBuffer // + ); + + // + CopyHKBandLower( + zIndex, + loopback, + conditions.hkBandLowerBuffer // + ); + + // + CopyPBBandUpper( + zIndex, + loopback, + conditions.pbBandUpperBuffer // + ); + + // + CopyPBBandLower( + zIndex, + loopback, + conditions.pbBandLowerBuffer // + ); + + // + CopyPBRawBandUpper( + zIndex, + loopback, + conditions.pbBandRawUpperBuffer // + ); + + // + CopyPBRawBandLower( + zIndex, + loopback, + conditions.pbBandRawLowerBuffer // + ); + + // + CopyATRBandUpper( + zIndex, + loopback, + conditions.atrBandUpperBuffer // + ); + + // + CopyATRBandLower( + zIndex, + loopback, + conditions.atrBandLowerBuffer // + ); + + // + CopyATR( + zIndex, + loopback, + conditions.atrBuffer // + ); + + // + CopyATRRawBandUpper( + zIndex, + loopback, + conditions.atrBandRawUpperBuffer // + ); + + // + CopyATRRawBandLower( + zIndex, + loopback, + conditions.atrBandRawLowerBuffer // + ); + + // + + // // Conditions ... @@ -1682,6 +1905,273 @@ class XCXFIMAHelper : public XCBaseHelper // // CYCLES Range ... + // + // MAs ... + + // + // SC MA ... + + // + double GetSCMA( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_SC_MA_LINE, + barIndex // + ); + } + + // + int CopySCMA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_SC_MA_LINE, + start, + count, + asSeries // + ); + } + + // + // SC MA State ... + + // + double GetSCMAState( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_SC_MA_STATE_LINE, + barIndex // + ); + } + + // + int CopySCMAState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_SC_MA_STATE_LINE, + start, + count, + asSeries // + ); + } + + // + // MC MA ... + + // + double GetMCMA( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_MC_MA_LINE, + barIndex // + ); + } + + // + int CopyMCMA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_MC_MA_LINE, + start, + count, + asSeries // + ); + } + + // + // MC MA State ... + + // + double GetMCMAState( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_MC_MA_STATE_LINE, + barIndex // + ); + } + + // + int CopyMCMAState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_MC_MA_STATE_LINE, + start, + count, + asSeries // + ); + } + + // + // LC MA ... + + // + double GetLCMA( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_LC_MA_LINE, + barIndex // + ); + } + + // + int CopyLCMA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_LC_MA_LINE, + start, + count, + asSeries // + ); + } + + // + // LC MA State ... + + // + double GetLCMAState( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_LC_MA_STATE_LINE, + barIndex // + ); + } + + // + int CopyLCMAState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_LC_MA_STATE_LINE, + start, + count, + asSeries // + ); + } + + // + // HC MA ... + + // + double GetHCMA( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HC_MA_LINE, + barIndex // + ); + } + + // + int CopyHCMA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HC_MA_LINE, + start, + count, + asSeries // + ); + } + + // + // HC MA State ... + + // + double GetHCMAState( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HC_MA_STATE_LINE, + barIndex // + ); + } + + // + int CopyHCMAState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HC_MA_STATE_LINE, + start, + count, + asSeries // + ); + } + // // SHORT ... diff --git a/Indicators/x-saherelm.xfima.mq5 b/Indicators/x-saherelm.xfima.mq5 index 5889549d..24bd6c83 100644 --- a/Indicators/x-saherelm.xfima.mq5 +++ b/Indicators/x-saherelm.xfima.mq5 @@ -111,6 +111,7 @@ input bool showMABand = true; // Show MA Band input bool showHKBand = true; // Show HK Band input bool showATRBand = true; // Show ATR Band input bool showZigZag = true; // Show ZigZag +input bool showCyclesMa = true; // Show Cycles MA input bool showFiboZone = true; // Show Fibo Zone // @@ -424,7 +425,6 @@ double atrBandLowerBuffer[]; #property indicator_color18 clrOrange #property indicator_width18 2 - // #define scMaBufferIndex 25 double scMaBuffer[]; @@ -434,7 +434,7 @@ double scMaBuffer[]; #property indicator_label19 "SCMA" #property indicator_type19 DRAW_LINE #property indicator_color19 clrChocolate -#property indicator_style19 STYLE_DASHDOT +#property indicator_style19 STYLE_DASHDOTDOT #property indicator_width19 2 // @@ -446,7 +446,7 @@ double mcMaBuffer[]; #property indicator_label20 "MCMA" #property indicator_type20 DRAW_LINE #property indicator_color20 clrChocolate -#property indicator_style20 STYLE_DASHDOT +#property indicator_style20 STYLE_DASHDOTDOT #property indicator_width20 2 // @@ -458,7 +458,7 @@ double lcMaBuffer[]; #property indicator_label21 "LCMA" #property indicator_type21 DRAW_LINE #property indicator_color21 clrChocolate -#property indicator_style21 STYLE_DASHDOT +#property indicator_style21 STYLE_DASHDOTDOT #property indicator_width21 2 // @@ -470,7 +470,7 @@ double hcMaBuffer[]; #property indicator_label22 "HCMA" #property indicator_type22 DRAW_LINE #property indicator_color22 clrChocolate -#property indicator_style22 STYLE_DASHDOT +#property indicator_style22 STYLE_DASHDOTDOT #property indicator_width22 2 // @@ -1461,6 +1461,69 @@ void DefineBuffers() ArraySetAsSeries(atrBandRawLowerBuffer, true); SetIndexBuffer(atrBandRawLowerBufferIndex, atrBandRawLowerBuffer, INDICATOR_CALCULATIONS); + // + // MA State ... + + // + // SC ... + + // + ArraySetAsSeries(scMaBuffer, true); + SetIndexBuffer(scMaBufferIndex, scMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scMaBufferPlotIndex, PLOT_SHOW_DATA, showCyclesMa); + PlotIndexSetDouble(scMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(scMaStateBuffer, true); + SetIndexBuffer(scMaStateBufferIndex, scMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // SC ... + + // + ArraySetAsSeries(mcMaBuffer, true); + SetIndexBuffer(mcMaBufferIndex, mcMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcMaBufferPlotIndex, PLOT_SHOW_DATA, showCyclesMa); + PlotIndexSetDouble(mcMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(scMaStateBuffer, true); + SetIndexBuffer(mcMaStateBufferIndex, mcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // LC ... + + // + ArraySetAsSeries(lcMaBuffer, true); + SetIndexBuffer(lcMaBufferIndex, lcMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcMaBufferPlotIndex, PLOT_SHOW_DATA, showCyclesMa); + PlotIndexSetDouble(lcMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(lcMaStateBuffer, true); + SetIndexBuffer(lcMaStateBufferIndex, lcMaStateBuffer, INDICATOR_CALCULATIONS); + + // + // HC ... + + // + ArraySetAsSeries(hcMaBuffer, true); + SetIndexBuffer(hcMaBufferIndex, hcMaBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcMaBufferPlotIndex, PLOT_SHOW_DATA, showCyclesMa); + PlotIndexSetDouble(hcMaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(hcMaStateBuffer, true); + SetIndexBuffer(hcMaStateBufferIndex, hcMaStateBuffer, INDICATOR_CALCULATIONS); + // } @@ -1929,6 +1992,19 @@ void CalculateValues( tickVolume // ); + // + // Cycles MA Calculation ... + CalculateCyclesMA( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + // // Fast MA ... double iFastMa = maFastBuffer[barIndex]; @@ -2765,6 +2841,78 @@ void CalculateCyclesMA( startCalculationForLastBars > 0 ? barIndex == startCalculationForLastBars : barIndex == firstBarIndex; + + // + // Retrieve Indexed Bar Price for MA States Checking ... + ENUM_X_PRICE iPriceType = X_PRICE_CLOSE; + double iPrice = GetAppliedPrice( + iPriceType, + open, + high, + low, + close, + barIndex // + ); + + // + // SC ... + double iSCMa = scMaBuffer[barIndex]; + double iSCMaColor = iPrice > iSCMa + ? bullishColorIDX + : iPrice < iSCMa + ? bearishColorIDX + : neuturalColorIDX; + double iSCMaState = iPrice > iSCMa + ? bullishState + : iPrice < iSCMa + ? bearishState + : neuturalState; + scMaStateBuffer[barIndex] = iSCMaState; + + // + // MC ... + double iMCMa = mcMaBuffer[barIndex]; + double iMCMaColor = iPrice > iMCMa + ? bullishColorIDX + : iPrice < iMCMa + ? bearishColorIDX + : neuturalColorIDX; + double iMCMaState = iPrice > iMCMa + ? bullishState + : iPrice < iMCMa + ? bearishState + : neuturalState; + mcMaStateBuffer[barIndex] = iMCMaState; + + // + // LC ... + double iLCMa = lcMaBuffer[barIndex]; + double iLCMaColor = iPrice > iLCMa + ? bullishColorIDX + : iPrice < iLCMa + ? bearishColorIDX + : neuturalColorIDX; + double iLCMaState = iPrice > iLCMa + ? bullishState + : iPrice < iLCMa + ? bearishState + : neuturalState; + lcMaStateBuffer[barIndex] = iLCMaState; + + // + // HC ... + double iHCMa = hcMaBuffer[barIndex]; + double iHCMaColor = iPrice > iHCMa + ? bullishColorIDX + : iPrice < iHCMa + ? bearishColorIDX + : neuturalColorIDX; + double iHCMaState = iPrice > iHCMa + ? bullishState + : iPrice < iHCMa + ? bearishState + : neuturalState; + hcMaStateBuffer[barIndex] = iHCMaState; } // diff --git a/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 index 274b42ca..15dbc2a4 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 @@ -341,6 +341,282 @@ class XCXFIMAHelperParser : XCBase // // XMA ... + /** + * Check Fast Ma is Bullish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMAFastBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetMAFastState(barIndex); + + // + result = state >= 1; + + // + return result; + } + + /** + * Check Slow Ma is Bullish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMASlowBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetMASlowState(barIndex); + + // + result = state >= 1; + + // + return result; + } + + /** + * Check Fast Ma is Bearish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMAFastBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetMAFastState(barIndex); + + // + result = state <= -1; + + // + return result; + } + + /** + * Check Slow Ma is Bearish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMASlowBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetMASlowState(barIndex); + + // + result = state <= -1; + + // + return result; + } + + /** + * Check Fast Ma is Switched to Bullish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMAFastSwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsMAFastBullish(barIndex); + bool isP = IsMAFastBullish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Slow Ma is Switched to Bullish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMASlowSwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsMASlowBullish(barIndex); + bool isP = IsMASlowBullish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Fast Ma is Switched to Bearish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMAFastSwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsMAFastBearish(barIndex); + bool isP = IsMAFastBearish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Slow Ma is Switched to Bearish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMASlowSwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsMASlowBearish(barIndex); + bool isP = IsMASlowBearish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + /** * Check Fast Ma Over Slow or not ... * @@ -2712,6 +2988,4485 @@ class XCXFIMAHelperParser : XCBase return result; } + // + // Cycles Tools ... + + // + // SC ... + + /** + * Check Short Cycle is Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCMABullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetSCMAState(barIndex); + + // + result = state >= 1; + + // + return result; + } + + /** + * Check Short Cycle is Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCMABearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetSCMAState(barIndex); + + // + result = state <= -1; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCMASwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsSCMABullish(barIndex); + bool isP = IsSCMABullish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCMASwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsSCMABearish(barIndex); + bool isP = IsSCMABearish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Count Bullish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBullishSCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsSCMABullish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Bearish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBearishSCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsSCMABearish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last MA Bullish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastSCMASwitchedToBullish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsSCMASwitchedToBullish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last MA Bearish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastSCMASwitchedToBearish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsSCMASwitchedToBearish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Lows is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCLLSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetSLL(barIndex); + double pValue = helper.GetSLL(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Lower Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCLowerLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetSLL(barIndex); + double pValue = helper.GetSLL(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Higher Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCHigherLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetSLL(barIndex); + double pValue = helper.GetSLL(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCHHSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetSHH(barIndex); + double pValue = helper.GetSHH(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Lower High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCLowerHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetSHH(barIndex); + double pValue = helper.GetSHH(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Higher High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsSCHigherHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetSHH(barIndex); + double pValue = helper.GetSHH(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Count Cycle Same LL(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountSCSameLLs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsSCLLSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Cycle Same HH(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountSCSameHHs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsSCHHSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last Cycle Lower Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastSCLowerLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsSCLowerLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastSCHigherLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsSCHigherLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Lower High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastSCLowerHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsSCLowerHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastSCHigherHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsSCHigherHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Has Trend or not ... + * + * @param trend: XTrend, reference to holds Detected Trend ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool HasSCTrend( + XTrend &trend, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + trend.Clean(); + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Detecte Lower Lows ... + int cLowerLowIDX = -1; + int pLowerLowIDX = -1; + bool hasCLowerLow = FindLastSCLowerLow(cLowerLowIDX, barIndex, loopback); + bool hasPLowerLow = + hasCLowerLow && + FindLastSCLowerLow(pLowerLowIDX, cLowerLowIDX, loopback); + + // + // Detect Lower Highs ... + int cLowerHighIDX = -1; + int pLowerHighIDX = -1; + bool hasCLowerHigh = FindLastSCLowerHigh(cLowerHighIDX, barIndex, loopback); + bool hasPLowerHigh = + hasCLowerHigh && + FindLastSCLowerHigh(pLowerHighIDX, cLowerHighIDX, loopback); + + // + // Detect Higher Lows ... + int cHigherLowIDX = -1; + int pHigherLowIDX = -1; + bool hasCHigherLow = FindLastSCHigherLow(cHigherLowIDX, barIndex, loopback); + bool hasPHigherLow = + hasCHigherLow && + FindLastSCHigherLow(pHigherLowIDX, cHigherLowIDX, loopback); + + // + // Detect Higher Highs ... + int cHigherHighIDX = -1; + int pHigherHighIDX = -1; + bool hasCHigherHigh = FindLastSCHigherHigh(cHigherHighIDX, barIndex, loopback); + bool hasPHigherHigh = + hasCHigherHigh && + FindLastSCHigherHigh(pHigherHighIDX, cHigherHighIDX, loopback); + + // + // Detect Direction ... + + // + // Bullish ... + bool isBullish = + hasCHigherLow && + hasPHigherLow && + hasCHigherHigh && + hasPHigherHigh; + + // + // Bearish ... + bool isBearish = + hasCLowerLow && + hasPLowerLow && + hasCLowerHigh && + hasPLowerHigh; + + // + // Summarize Result ... + result = isBullish || isBearish; + + // + // Preparing XTrend ... + if (result) + { + // + // Define Requirements ... + + // + datetime toTime = NULL; + datetime fromTime = NULL; + + // + double toValue = EMPTY_VALUE; + double fromValue = EMPTY_VALUE; + + // + // Validating Directions ... + + // + // Bullish Validation ... + if (isBullish) + { + // + datetime cHL = GetBarTime(symbol, period, cHigherLowIDX); + datetime pHL = GetBarTime(symbol, period, pHigherLowIDX); + + // + toTime = cHL; + fromTime = pHL; + + // + toValue = helper.GetSLL(cHigherLowIDX); + fromValue = helper.GetSLL(pHigherLowIDX); + + // + // Validate Conditions ... + isBullish = + isBullish && + fromValue < toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Bearish Validation ... + if (isBearish) + { + // + datetime cLH = GetBarTime(symbol, period, cLowerHighIDX); + datetime pLH = GetBarTime(symbol, period, pLowerHighIDX); + + // + toTime = cLH; + fromTime = pLH; + + // + toValue = helper.GetSHH(cLowerHighIDX); + fromValue = helper.GetSHH(pLowerHighIDX); + + // + // Validate Conditions ... + isBearish = + isBearish && + fromValue > toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Validate Values ... + result = + IsXValid(toTime) && + IsXValid(fromTime) && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + + // + // Try to Initialized Trend ... + if (result) + { + // + // Initialize Trend ... + result = trend.Init( + symbol, + period, + TimeCurrent(), + fromValue, + fromTime, + toValue, + toTime // + ); + } + + // + // Validate Trend ... + result = trend.IsValid(); + } + + // + // Validate Result ... + result = trend.IsValid() && + trend.HasTrend(); + + // + // Cleanup ... + if (!result) + { + trend.Clean(); + } + + // + return result; + } + + // + // MC ... + + /** + * Check Short Cycle is Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCMABullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetMCMAState(barIndex); + + // + result = state >= 1; + + // + return result; + } + + /** + * Check Short Cycle is Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCMABearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetMCMAState(barIndex); + + // + result = state <= -1; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCMASwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsMCMABullish(barIndex); + bool isP = IsMCMABullish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCMASwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsMCMABearish(barIndex); + bool isP = IsMCMABearish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Count Bullish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBullishMCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsMCMABullish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Bearish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBearishMCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsMCMABearish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last MA Bullish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastMCMASwitchedToBullish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsMCMASwitchedToBullish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last MA Bearish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastMCMASwitchedToBearish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsMCMASwitchedToBearish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Lows is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCLLSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetMLL(barIndex); + double pValue = helper.GetMLL(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Lower Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCLowerLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetMLL(barIndex); + double pValue = helper.GetMLL(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Higher Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCHigherLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetMLL(barIndex); + double pValue = helper.GetMLL(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCHHSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetMHH(barIndex); + double pValue = helper.GetMHH(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Lower High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCLowerHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetMHH(barIndex); + double pValue = helper.GetMHH(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Higher High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsMCHigherHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetMHH(barIndex); + double pValue = helper.GetMHH(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Count Cycle Same LL(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountMCSameLLs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsMCLLSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Cycle Same HH(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountMCSameHHs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsMCHHSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last Cycle Lower Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastMCLowerLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsMCLowerLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastMCHigherLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsMCHigherLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Lower High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastMCLowerHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsMCLowerHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastMCHigherHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsMCHigherHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Has Trend or not ... + * + * @param trend: XTrend, reference to holds Detected Trend ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool HasMCTrend( + XTrend &trend, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + trend.Clean(); + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Detecte Lower Lows ... + int cLowerLowIDX = -1; + int pLowerLowIDX = -1; + bool hasCLowerLow = FindLastMCLowerLow(cLowerLowIDX, barIndex, loopback); + bool hasPLowerLow = + hasCLowerLow && + FindLastMCLowerLow(pLowerLowIDX, cLowerLowIDX, loopback); + + // + // Detect Lower Highs ... + int cLowerHighIDX = -1; + int pLowerHighIDX = -1; + bool hasCLowerHigh = FindLastMCLowerHigh(cLowerHighIDX, barIndex, loopback); + bool hasPLowerHigh = + hasCLowerHigh && + FindLastMCLowerHigh(pLowerHighIDX, cLowerHighIDX, loopback); + + // + // Detect Higher Lows ... + int cHigherLowIDX = -1; + int pHigherLowIDX = -1; + bool hasCHigherLow = FindLastMCHigherLow(cHigherLowIDX, barIndex, loopback); + bool hasPHigherLow = + hasCHigherLow && + FindLastMCHigherLow(pHigherLowIDX, cHigherLowIDX, loopback); + + // + // Detect Higher Highs ... + int cHigherHighIDX = -1; + int pHigherHighIDX = -1; + bool hasCHigherHigh = FindLastMCHigherHigh(cHigherHighIDX, barIndex, loopback); + bool hasPHigherHigh = + hasCHigherHigh && + FindLastMCHigherHigh(pHigherHighIDX, cHigherHighIDX, loopback); + + // + // Detect Direction ... + + // + // Bullish ... + bool isBullish = + hasCHigherLow && + hasPHigherLow && + hasCHigherHigh && + hasPHigherHigh; + + // + // Bearish ... + bool isBearish = + hasCLowerLow && + hasPLowerLow && + hasCLowerHigh && + hasPLowerHigh; + + // + // Summarize Result ... + result = isBullish || isBearish; + + // + // Preparing XTrend ... + if (result) + { + // + // Define Requirements ... + + // + datetime toTime = NULL; + datetime fromTime = NULL; + + // + double toValue = EMPTY_VALUE; + double fromValue = EMPTY_VALUE; + + // + // Validating Directions ... + + // + // Bullish Validation ... + if (isBullish) + { + // + datetime cHL = GetBarTime(symbol, period, cHigherLowIDX); + datetime pHL = GetBarTime(symbol, period, pHigherLowIDX); + + // + toTime = cHL; + fromTime = pHL; + + // + toValue = helper.GetMLL(cHigherLowIDX); + fromValue = helper.GetMLL(pHigherLowIDX); + + // + // Validate Conditions ... + isBullish = + isBullish && + fromValue < toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Bearish Validation ... + if (isBearish) + { + // + datetime cLH = GetBarTime(symbol, period, cLowerHighIDX); + datetime pLH = GetBarTime(symbol, period, pLowerHighIDX); + + // + toTime = cLH; + fromTime = pLH; + + // + toValue = helper.GetMHH(cLowerHighIDX); + fromValue = helper.GetMHH(pLowerHighIDX); + + // + // Validate Conditions ... + isBearish = + isBearish && + fromValue > toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Validate Values ... + result = + IsXValid(toTime) && + IsXValid(fromTime) && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + + // + // Try to Initialized Trend ... + if (result) + { + // + // Initialize Trend ... + result = trend.Init( + symbol, + period, + TimeCurrent(), + fromValue, + fromTime, + toValue, + toTime // + ); + } + + // + // Validate Trend ... + result = trend.IsValid(); + } + + // + // Validate Result ... + result = trend.IsValid() && + trend.HasTrend(); + + // + // Cleanup ... + if (!result) + { + trend.Clean(); + } + + // + return result; + } + + // + // LC ... + + /** + * Check Short Cycle is Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCMABullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetLCMAState(barIndex); + + // + result = state >= 1; + + // + return result; + } + + /** + * Check Short Cycle is Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCMABearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetLCMAState(barIndex); + + // + result = state <= -1; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCMASwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsLCMABullish(barIndex); + bool isP = IsLCMABullish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCMASwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsLCMABearish(barIndex); + bool isP = IsLCMABearish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Count Bullish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBullishLCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsLCMABullish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Bearish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBearishLCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsLCMABearish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last MA Bullish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastLCMASwitchedToBullish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsLCMASwitchedToBullish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last MA Bearish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastLCMASwitchedToBearish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsLCMASwitchedToBearish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Lows is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCLLSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetLLL(barIndex); + double pValue = helper.GetLLL(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Lower Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCLowerLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetLLL(barIndex); + double pValue = helper.GetLLL(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Higher Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCHigherLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetLLL(barIndex); + double pValue = helper.GetLLL(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCHHSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetLHH(barIndex); + double pValue = helper.GetLHH(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Lower High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCLowerHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetLHH(barIndex); + double pValue = helper.GetLHH(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Higher High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsLCHigherHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetLHH(barIndex); + double pValue = helper.GetLHH(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Count Cycle Same LL(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountLCSameLLs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsLCLLSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Cycle Same HH(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountLCSameHHs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsLCHHSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last Cycle Lower Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastLCLowerLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsLCLowerLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastLCHigherLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsLCHigherLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Lower High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastLCLowerHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsLCLowerHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastLCHigherHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsLCHigherHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Has Trend or not ... + * + * @param trend: XTrend, reference to holds Detected Trend ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool HasLCTrend( + XTrend &trend, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + trend.Clean(); + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Detecte Lower Lows ... + int cLowerLowIDX = -1; + int pLowerLowIDX = -1; + bool hasCLowerLow = FindLastLCLowerLow(cLowerLowIDX, barIndex, loopback); + bool hasPLowerLow = + hasCLowerLow && + FindLastLCLowerLow(pLowerLowIDX, cLowerLowIDX, loopback); + + // + // Detect Lower Highs ... + int cLowerHighIDX = -1; + int pLowerHighIDX = -1; + bool hasCLowerHigh = FindLastLCLowerHigh(cLowerHighIDX, barIndex, loopback); + bool hasPLowerHigh = + hasCLowerHigh && + FindLastLCLowerHigh(pLowerHighIDX, cLowerHighIDX, loopback); + + // + // Detect Higher Lows ... + int cHigherLowIDX = -1; + int pHigherLowIDX = -1; + bool hasCHigherLow = FindLastLCHigherLow(cHigherLowIDX, barIndex, loopback); + bool hasPHigherLow = + hasCHigherLow && + FindLastLCHigherLow(pHigherLowIDX, cHigherLowIDX, loopback); + + // + // Detect Higher Highs ... + int cHigherHighIDX = -1; + int pHigherHighIDX = -1; + bool hasCHigherHigh = FindLastLCHigherHigh(cHigherHighIDX, barIndex, loopback); + bool hasPHigherHigh = + hasCHigherHigh && + FindLastLCHigherHigh(pHigherHighIDX, cHigherHighIDX, loopback); + + // + // Detect Direction ... + + // + // Bullish ... + bool isBullish = + hasCHigherLow && + hasPHigherLow && + hasCHigherHigh && + hasPHigherHigh; + + // + // Bearish ... + bool isBearish = + hasCLowerLow && + hasPLowerLow && + hasCLowerHigh && + hasPLowerHigh; + + // + // Summarize Result ... + result = isBullish || isBearish; + + // + // Preparing XTrend ... + if (result) + { + // + // Define Requirements ... + + // + datetime toTime = NULL; + datetime fromTime = NULL; + + // + double toValue = EMPTY_VALUE; + double fromValue = EMPTY_VALUE; + + // + // Validating Directions ... + + // + // Bullish Validation ... + if (isBullish) + { + // + datetime cHL = GetBarTime(symbol, period, cHigherLowIDX); + datetime pHL = GetBarTime(symbol, period, pHigherLowIDX); + + // + toTime = cHL; + fromTime = pHL; + + // + toValue = helper.GetLLL(cHigherLowIDX); + fromValue = helper.GetLLL(pHigherLowIDX); + + // + // Validate Conditions ... + isBullish = + isBullish && + fromValue < toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Bearish Validation ... + if (isBearish) + { + // + datetime cLH = GetBarTime(symbol, period, cLowerHighIDX); + datetime pLH = GetBarTime(symbol, period, pLowerHighIDX); + + // + toTime = cLH; + fromTime = pLH; + + // + toValue = helper.GetLHH(cLowerHighIDX); + fromValue = helper.GetLHH(pLowerHighIDX); + + // + // Validate Conditions ... + isBearish = + isBearish && + fromValue > toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Validate Values ... + result = + IsXValid(toTime) && + IsXValid(fromTime) && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + + // + // Try to Initialized Trend ... + if (result) + { + // + // Initialize Trend ... + result = trend.Init( + symbol, + period, + TimeCurrent(), + fromValue, + fromTime, + toValue, + toTime // + ); + } + + // + // Validate Trend ... + result = trend.IsValid(); + } + + // + // Validate Result ... + result = trend.IsValid() && + trend.HasTrend(); + + // + // Cleanup ... + if (!result) + { + trend.Clean(); + } + + // + return result; + } + + // + // HC ... + + /** + * Check Short Cycle is Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCMABullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetHCMAState(barIndex); + + // + result = state >= 1; + + // + return result; + } + + /** + * Check Short Cycle is Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCMABearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetHCMAState(barIndex); + + // + result = state <= -1; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bullish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCMASwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsHCMABullish(barIndex); + bool isP = IsHCMABullish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Check Short Cycle is Switched to Bearish ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCMASwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isC = IsHCMABearish(barIndex); + bool isP = IsHCMABearish(barIndex + 1); + + // + result = isC && !isP; + + // + return result; + } + + /** + * Count Bullish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBullishHCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsHCMABullish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Bearish MA(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountBearishHCMAs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsHCMABearish(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last MA Bullish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastHCMASwitchedToBullish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsHCMASwitchedToBullish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last MA Bearish Switches ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastHCMASwitchedToBearish( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsHCMASwitchedToBearish(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Lows is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCLLSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetHLL(barIndex); + double pValue = helper.GetHLL(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Lower Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCLowerLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetHLL(barIndex); + double pValue = helper.GetHLL(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Lows is Higher Low ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCHigherLow(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetHLL(barIndex); + double pValue = helper.GetHLL(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Same ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCHHSame(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetHHH(barIndex); + double pValue = helper.GetHHH(barIndex + 1); + + // + result = cValue == pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Lower High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCLowerHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetHHH(barIndex); + double pValue = helper.GetHHH(barIndex + 1); + + // + result = cValue < pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Check Cycle Highss is Higher High ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsHCHigherHigh(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double cValue = helper.GetHHH(barIndex); + double pValue = helper.GetHHH(barIndex + 1); + + // + result = cValue > pValue && + NotEmptyZero(cValue) && + NotEmptyZero(pValue); + + // + return result; + } + + /** + * Count Cycle Same LL(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountHCSameLLs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsHCLLSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Count Cycle Same HH(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( int ) + */ + int CountHCSameHHs( + int barIndex = 0, + int loopback = 500 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return result; + } + + // + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + has = IsHCHHSame(idx); + if (has) + { + result++; + } + if (!has) + { + break; + } + } + + // + return result; + } + + /** + * Detect Last Cycle Lower Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastHCLowerLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsHCLowerLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher Low ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastHCHigherLow( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsHCHigherLow(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Lower High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastHCLowerHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsHCLowerHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Detect Last Cycle Higher High ... + * + * @param index: int, reference to hold change index ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool FindLastHCHigherHigh( + int &index, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + index = -1; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Loop ... + int idx = barIndex; + while (idx < barIndex + loopback) + { + // + idx++; + result = IsHCHigherHigh(idx); + if (result) + { + // + index = idx; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + /** + * Check Cycle Has Trend or not ... + * + * @param trend: XTrend, reference to holds Detected Trend ... + * @param barIndex: int, Specified Bar Index ... + * @param loopback: int, Max Allowed Loopback Length ... + * + * @return ( bool ) + */ + bool HasHCTrend( + XTrend &trend, + int barIndex = 0, + int loopback = 500 // + ) + { + // + bool result = false; + + // + // Prepare ... + trend.Clean(); + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Detecte Lower Lows ... + int cLowerLowIDX = -1; + int pLowerLowIDX = -1; + bool hasCLowerLow = FindLastHCLowerLow(cLowerLowIDX, barIndex, loopback); + bool hasPLowerLow = + hasCLowerLow && + FindLastHCLowerLow(pLowerLowIDX, cLowerLowIDX, loopback); + + // + // Detect Lower Highs ... + int cLowerHighIDX = -1; + int pLowerHighIDX = -1; + bool hasCLowerHigh = FindLastHCLowerHigh(cLowerHighIDX, barIndex, loopback); + bool hasPLowerHigh = + hasCLowerHigh && + FindLastHCLowerHigh(pLowerHighIDX, cLowerHighIDX, loopback); + + // + // Detect Higher Lows ... + int cHigherLowIDX = -1; + int pHigherLowIDX = -1; + bool hasCHigherLow = FindLastHCHigherLow(cHigherLowIDX, barIndex, loopback); + bool hasPHigherLow = + hasCHigherLow && + FindLastHCHigherLow(pHigherLowIDX, cHigherLowIDX, loopback); + + // + // Detect Higher Highs ... + int cHigherHighIDX = -1; + int pHigherHighIDX = -1; + bool hasCHigherHigh = FindLastHCHigherHigh(cHigherHighIDX, barIndex, loopback); + bool hasPHigherHigh = + hasCHigherHigh && + FindLastHCHigherHigh(pHigherHighIDX, cHigherHighIDX, loopback); + + // + // Detect Direction ... + + // + // Bullish ... + bool isBullish = + hasCHigherLow && + hasPHigherLow && + hasCHigherHigh && + hasPHigherHigh; + + // + // Bearish ... + bool isBearish = + hasCLowerLow && + hasPLowerLow && + hasCLowerHigh && + hasPLowerHigh; + + // + // Summarize Result ... + result = isBullish || isBearish; + + // + // Preparing XTrend ... + if (result) + { + // + // Define Requirements ... + + // + datetime toTime = NULL; + datetime fromTime = NULL; + + // + double toValue = EMPTY_VALUE; + double fromValue = EMPTY_VALUE; + + // + // Validating Directions ... + + // + // Bullish Validation ... + if (isBullish) + { + // + datetime cHL = GetBarTime(symbol, period, cHigherLowIDX); + datetime pHL = GetBarTime(symbol, period, pHigherLowIDX); + + // + toTime = cHL; + fromTime = pHL; + + // + toValue = helper.GetHLL(cHigherLowIDX); + fromValue = helper.GetHLL(pHigherLowIDX); + + // + // Validate Conditions ... + isBullish = + isBullish && + fromValue < toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Bearish Validation ... + if (isBearish) + { + // + datetime cLH = GetBarTime(symbol, period, cLowerHighIDX); + datetime pLH = GetBarTime(symbol, period, pLowerHighIDX); + + // + toTime = cLH; + fromTime = pLH; + + // + toValue = helper.GetHHH(cLowerHighIDX); + fromValue = helper.GetHHH(pLowerHighIDX); + + // + // Validate Conditions ... + isBearish = + isBearish && + fromValue > toValue && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + } + + // + // Validate Values ... + result = + IsXValid(toTime) && + IsXValid(fromTime) && + NotEmptyZero(toValue) && + NotEmptyZero(fromValue); + + // + // Try to Initialized Trend ... + if (result) + { + // + // Initialize Trend ... + result = trend.Init( + symbol, + period, + TimeCurrent(), + fromValue, + fromTime, + toValue, + toTime // + ); + } + + // + // Validate Trend ... + result = trend.IsValid(); + } + + // + // Validate Result ... + result = trend.IsValid() && + trend.HasTrend(); + + // + // Cleanup ... + if (!result) + { + trend.Clean(); + } + + // + return result; + } + // // Boundary Tools ... // ============================= @@ -3499,10 +8254,10 @@ class XCXFIMAHelperParser : XCBase /** * Check Has Boundary Trend or not ... - * + * * @param trend: XTrend, refrence to holds Detected trend ... * @param barIndex: int, Specified Bar Index ... - * + * * @return ( bool ) */ bool HasBoundaryTrend( diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index b5bbe800..9ccc0b4c 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -287,6 +287,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller drawLeg = true; drawZones = true; drawIZones = true; + drawTrends = true; + drawSCTrend = true; + drawMCTrend = true; + drawLCTrend = true; + drawHCTrend = true; drawSupport = true; drawISupport = true; drawOrderFlow = true; @@ -604,6 +609,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // ManageLeg(bar); + ManageTrends(bar); ManageZones(p2Bar); ManageIZones(p2Bar); ManageOrderFlow(p3Bar); @@ -1364,6 +1370,160 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } } + // + // Trends ... + + // + XTrend scTrend; + XTrend mcTrend; + XTrend lcTrend; + XTrend hcTrend; + + // + bool drawTrends; + bool drawSCTrend; + bool drawMCTrend; + bool drawLCTrend; + bool drawHCTrend; + + // + bool HasTrend() + { + // + bool result = + HasSCTrend() || + HasMCTrend() || + HasLCTrend() || + HasHCTrend(); + + // + return result; + } + + // + bool HasSCTrend() + { + return scTrend.IsValid() && + scTrend.HasTrend(); + } + + // + bool HasMCTrend() + { + return mcTrend.IsValid() && + mcTrend.HasTrend(); + } + + // + bool HasLCTrend() + { + return lcTrend.IsValid() && + lcTrend.HasTrend(); + } + + // + bool HasHCTrend() + { + return hcTrend.IsValid() && + hcTrend.HasTrend(); + } + + // + void DrawTrends() + { + // + if (!drawTrends || !HasTrend()) + { + return; + } + + // + // SC ... + if (drawSCTrend && HasSCTrend()) + { + poiDrawer.DrawTrendLine(scTrend, structureDrawConfig.drawConfig); + } + + // + // MC ... + if (drawMCTrend && HasMCTrend()) + { + poiDrawer.DrawTrendLine(mcTrend, structureDrawConfig.drawConfig); + } + + // + // LC ... + if (drawLCTrend && HasLCTrend()) + { + poiDrawer.DrawTrendLine(lcTrend, structureDrawConfig.drawConfig); + } + + // + // HC ... + if (drawHCTrend && HasHCTrend()) + { + poiDrawer.DrawTrendLine(hcTrend, structureDrawConfig.drawConfig); + } + } + + // + void ManageTrends(XOHCL &bar) + { + // + // Validate ... + bool has = bar.IsValid(); + if (!has) + { + return; + } + + // + XTrend tmpTrend; + + // + // SC ... + tmpTrend.Clean(); + has = fimaParser.HasSCTrend(tmpTrend, bar.Index()); + if (has) + { + scTrend = tmpTrend; + } + + // + // MC ... + tmpTrend.Clean(); + has = fimaParser.HasMCTrend(tmpTrend, bar.Index()); + if (has) + { + mcTrend = tmpTrend; + } + + // + // LC ... + tmpTrend.Clean(); + has = fimaParser.HasLCTrend(tmpTrend, bar.Index()); + if (has) + { + lcTrend = tmpTrend; + } + + // + // HC ... + tmpTrend.Clean(); + has = fimaParser.HasHCTrend(tmpTrend, bar.Index()); + if (has) + { + hcTrend = tmpTrend; + } + + // + DrawTrends(); + + // + // Cleanup ... + tmpTrend.Clean(); + } + // // Implementing Strategies ... @@ -1422,6 +1582,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller drawLeg = false; drawZones = false; drawIZones = false; + drawTrends = false; + drawSCTrend = false; + drawMCTrend = false; + drawLCTrend = false; + drawHCTrend = false; drawSupport = false; drawISupport = false; drawOrderFlow = false;