/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 X121 SMC Signal Class // ------------------------------------------------- // Name: XWZ // Description: provide all Signalling functions ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Imports ... // #include "../../Libraries/x-trade.lib" #include "../Classes/x-121.smc.market.cycle.helper.class.mq5" #include "../Libraries/x-121.smc.guard.lib.mq5" #include "../Libraries/x-121.smc.lib.mq5" // enum ENUM_X121SMC_XWZ_PROVIDERS { X121SMC_XWZ_PROVIDER_NONE, X121SMC_XWZ_PROVIDER_PV_ZONE, X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, }; // enum ENUM_X121SMC_XWZ_PRIORITY { X121SMC_XWZ_PRIORITY_NONE, X121SMC_XWZ_PRIORITY_WEAK, X121SMC_XWZ_PRIORITY_LOW, X121SMC_XWZ_PRIORITY_REGULAR, X121SMC_XWZ_PRIORITY_HIGH, X121SMC_XWZ_PRIORITY_STRONG_HIGH, }; // struct X121SMCStrategyXWZWorkingZone { // // Props ... // string symbol; ENUM_TIMEFRAMES period; // double quarter1; double quarter2; double quarter3; // XCSupplyZone *supplyZone; XCDemandZone *demandZone; // XCSupplyZone *supplyZones[]; XCDemandZone *demandZones[]; // XCSupportZone *supportZones[]; XCResistanceZone *resistanceZones[]; // XBoxZone insideBoxes[]; XBoxZone breakedBoxes[]; XBoxZone waitingBoxes[]; XConsolidationZone consolidationZones[]; // CArrayObj mInsideZoneObjects; CArrayObj mBreakedZoneObjects; CArrayObj mWaitingZoneObjects; CArrayObj mWorkingZoneObjects; // bool mUseOrderBlocks; bool mUseFairValueGaps; // // Constructor ... X121SMCStrategyXWZWorkingZone() { Clean(); } // // Tools ... // void Clean() { // quarter1 = 0; quarter2 = 0; quarter3 = 0; // symbol = NULL; period = NULL; // Clean(supplyZones); Clean(demandZones); // Clean(insideBoxes); Clean(breakedBoxes); Clean(waitingBoxes); // Clean(supportZones); Clean(resistanceZones); // ZeroMemory(supplyZone); ZeroMemory(demandZone); // mInsideZoneObjects.Clear(); mBreakedZoneObjects.Clear(); mWaitingZoneObjects.Clear(); mWorkingZoneObjects.Clear(); // mUseOrderBlocks = true; mUseFairValueGaps = false; } // bool IsValid() { // bool result = false; // result = // quarter1 > 0 && quarter2 > 0 && quarter3 > 0 && HasSupplyZone() && HasDemandZone() && quarter1 > quarter2 && quarter2 > quarter3 // ; // return result; } // bool Init( string _symbol, ENUM_TIMEFRAMES _period, int barIndex, XPOIState &htfState, XPOIState &mtfState, XPOIState &stfState, // XPOIState &ttfState // ) { // bool result = false; // if (barIndex < 0) { barIndex = 0; } // result = // IsValid(_symbol) && IsValid(_period) && // htfState.IsValid() && mtfState.IsValid() && stfState.IsValid() && ttfState.IsValid() && // htfState.HasChild() && mtfState.HasChild() && stfState.HasChild() && ttfState.HasChild() // ; if (!result) { return result; } // symbol = _symbol; period = _period; // int idx = -1; int count = 0; bool has = false; // XOHCL zBar; has = zBar.Init( symbol, period, barIndex // ); result = has; if (!result) { zBar.Clean(); return result; } double ll5 = zBar.FindLowest(5, MODE_LOW); double hh5 = zBar.FindHighest(5, MODE_HIGH); zBar.Clean(); // // Supply Zone ... has = HasSupplyZone(); if (!has) { // idx = GetHighest(mtfState.supplyZones); has = IsValidIndex(idx); if (has) { // supplyZone = mtfState.supplyZones[idx]; has = hh5 < supplyZone.Lower(); if (!has) { supplyZone = NULL; } } } // // Demand Zone ... has = HasDemandZone(); if (!has) { // idx = GetLowest(mtfState.demandZones); has = IsValidIndex(idx); if (has) { // demandZone = mtfState.demandZones[idx]; has = ll5 > demandZone.Upper(); if (!has) { demandZone = NULL; } } } // // Supply Zones ... has = HasSupplyZones(); if (!has) { // count = mtfState.FilterSupplyZones( supplyZones, period, XZONE_STATE_PASSED, false, XZONE_STATE_FAILED, false, XZONE_STATE_FAILED, false, XZONE_STATE_IGNORED, false // ); } // // Demand Zones ... has = HasDemandZones(); if (!has) { // count = mtfState.FilterDemandZones( demandZones, period, XZONE_STATE_PASSED, false, XZONE_STATE_FAILED, false, XZONE_STATE_FAILED, false, XZONE_STATE_IGNORED, false // ); } // // Support Zones ... // has = HasSupportZones(); // if (!has) // { // // // count = mtfState.FilterSupportZones( // supportZones, // period, // XZONE_STATE_PASSED, // false, // XZONE_STATE_FAILED, // false, // XZONE_STATE_FAILED, // false, // XZONE_STATE_IGNORED, // false // // ); // } // // Resistance Zones ... // has = HasResistanceZones(); // if (!has) // { // // // count = mtfState.FilterResistanceZones( // resistanceZones, // period, // XZONE_STATE_PASSED, // false, // XZONE_STATE_FAILED, // false, // XZONE_STATE_FAILED, // false, // XZONE_STATE_IGNORED, // false // // ); // } // has = ttfState.HasConsolidationZones(); if (has) { // Copy( ttfState.consolidationZones, consolidationZones // ); CleanupArray( consolidationZones, 50 // ); } // if (supplyZone != NULL && demandZone != NULL && supplyZone.IsValid() && demandZone.IsValid()) { // double upper = supplyZone.Lower(); double lower = demandZone.Upper(); // double delta = ((upper - lower) / 100) * 25; // quarter1 = upper - (1 * delta); quarter2 = upper - (2 * delta); quarter3 = upper - (3 * delta); } // // Waiting Zone Detection ... XPOIState iState = mtfState; // // Detect Waiting Zones ... // // Using Order Blocks ... if (mUseOrderBlocks) { // has = iState.HasOrderBlocks(); if (has) { // XCOrderBlock *obs[]; count = iState.FilterOrderBlocks( obs, period, XZONE_STATE_PASSED, false, XZONE_STATE_FAILED, false, XZONE_STATE_FAILED, false, XZONE_STATE_IGNORED, false // ); // has = IsValidSize(count); if (has) { // ToBox( obs, waitingBoxes // ); } // Clean(obs); } } // // Using Fair Value Gaps ... if (mUseFairValueGaps) { // has = iState.HasFairValueGaps(); if (has) { // XBoxZone boxes[]; XCFVG *fvgs[]; count = iState.FilterFairValueGaps( fvgs, period, XZONE_STATE_PASSED, false, XZONE_STATE_FAILED, false, XZONE_STATE_FAILED, false, XZONE_STATE_IGNORED, false // ); // has = IsValidSize(count); if (has) { // count = ToBox( fvgs, boxes // ); // for (int i = 0; i < count; i++) { // XBoxZone iBox = boxes[i]; // int idx = FindIndex( iBox, waitingBoxes // ); has = !IsValidIndex(idx); if (has) { // AddRef( iBox, waitingBoxes // ); } // iBox.Clean(); } } // Clean(fvgs); Clean(boxes); } } // // Cleaning State ... iState.Clean(); // result = IsValid(); if (!result) { Clean(); } // return result; } // void Update( int barIndex, XPOIState &htfState, XPOIState &mtfState, XPOIState &stfState, XPOIState &ttfState // ) { // int idx = -1; int count = 0; bool has = false; // if (barIndex < 0) { barIndex = 0; } // has = // IsValid() && // htfState.IsValid() && mtfState.IsValid() && stfState.IsValid() && // htfState.HasChild() && mtfState.HasChild() && stfState.HasChild() // ; if (!has) { return; } // XOHCL zBar; has = zBar.Init( symbol, period, barIndex // ); if (!has) { // zBar.Clean(); return; } // XOHCL cBar; has = zBar.GetPreviousBar(cBar); if (!has) { // zBar.Clean(); cBar.Clean(); // return; } // // Update Exists Zones ... // // Supply Zones ... has = HasSupplyZones(); if (has) { // int removeIDXs[]; count = CountSupplyZones(); for (int i = 0; i < count; i++) { // XCSupplyZone *iZone = supplyZones[i]; ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; // XBoxZone iBox; bool hasBox = ToBox( iBox, iZone // ); if (!hasBox) { // iBox.Clean(); continue; } // XOHCL passedBar; bool isBodyIn = false; bool isBodyOut = false; // // Check Activation ... bool isActivated = iZone.IsActivated( iDir, passedBar, isBodyIn, true, period // ); if (isActivated) { // // AddRef( // iBox, // insideBoxes // // ); // Add( i, removeIDXs // ); // iBox.Clean(); passedBar.Clean(); continue; } // // Checking Breaked ... bool isBreaked = iZone.IsBreaked( iDir, passedBar, isBodyOut, false, true, period // ); if (isBreaked) { // // // AddRef( // iBox, // breakedBoxes // // ); // Add( i, removeIDXs // ); // iBox.Clean(); passedBar.Clean(); continue; } // passedBar.Clean(); } // count = ArraySize(removeIDXs); has = IsValidSize(count); if (has) { // CleanupArray( removeIDXs, supplyZones // ); } // Clean(removeIDXs); } // // Demand Zones ... has = HasDemandZones(); if (has) { // int removeIDXs[]; count = CountDemandZones(); for (int i = 0; i < count; i++) { // XCDemandZone *iZone = demandZones[i]; ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; // XBoxZone iBox; bool hasBox = ToBox( iBox, iZone // ); if (!hasBox) { // iBox.Clean(); continue; } // XOHCL passedBar; bool isBodyIn = false; bool isBodyOut = false; // // Check Activation ... bool isActivated = iZone.IsActivated( iDir, passedBar, isBodyIn, true, period // ); if (isActivated) { // // AddRef( // iBox, // insideBoxes // // ); // Add( i, removeIDXs // ); // iBox.Clean(); passedBar.Clean(); continue; } // // Checking Breaked ... bool isBreaked = iZone.IsBreaked( iDir, passedBar, isBodyOut, false, true, period // ); if (isBreaked) { // // // AddRef( // iBox, // breakedBoxes // // ); // Add( i, removeIDXs // ); // iBox.Clean(); passedBar.Clean(); continue; } // passedBar.Clean(); } // count = ArraySize(removeIDXs); has = IsValidSize(count); if (has) { // CleanupArray( removeIDXs, demandZones // ); } // Clean(removeIDXs); } // // Update Boxes ... // // Waiting Boxes ... has = HasWaitingBoxes(); if (has) { // int removeIDXs[]; count = CountWaitingBoxes(); for (int i = 0; i < count; i++) { // XBoxZone iBox = waitingBoxes[i]; ENUM_X_DIRECTION iDir = iBox.dir; bool isBullish = IsBullish(iDir); // bool isInside = // zBar.low < iBox.upper && zBar.low > iBox.lower // ; if (isInside) { // AddRef( iBox, insideBoxes // ); // Add( i, removeIDXs // ); // iBox.Clean(); break; } // bool isBreakedUpper = // cBar.low < iBox.upper && cBar.low > iBox.lower && zBar.low > iBox.upper // ; // bool isBreakedLower = // cBar.high > iBox.lower && cBar.high < iBox.upper && zBar.high < iBox.lower // ; // bool isBreaked = (isBullish && isBreakedLower) || (!isBullish && isBreakedUpper); // if (isBreaked) { // AddRef( iBox, breakedBoxes // ); // Add( i, removeIDXs // ); // iBox.Clean(); break; } } // count = ArraySize(removeIDXs); has = IsValidSize(count); if (has) { // CleanupArray( removeIDXs, waitingBoxes // ); } // Clean(removeIDXs); } // // Inside Boxes ... has = HasInsideBoxes(); if (has) { // int removeIDXs[]; count = CountInsideBoxes(); for (int i = 0; i < count; i++) { // XBoxZone iBox = insideBoxes[i]; ENUM_X_DIRECTION iDir = iBox.dir; bool isBullish = IsBullish(iDir); // bool isBreakedUpper = // cBar.low < iBox.upper && cBar.low > iBox.lower && zBar.low > iBox.upper // ; // bool isBreakedLower = // cBar.high > iBox.lower && cBar.high < iBox.upper && zBar.high < iBox.lower // ; // bool isBreaked = (isBullish && isBreakedLower) || (!isBullish && isBreakedUpper); // if (isBreaked) { // AddRef( iBox, breakedBoxes // ); // Add( i, removeIDXs // ); // iBox.Clean(); break; } } // count = ArraySize(removeIDXs); has = IsValidSize(count); if (has) { // CleanupArray( removeIDXs, insideBoxes // ); } // Clean(removeIDXs); } // // Update Waiting Boxes ... // XPOIState iState = mtfState; // // Use Order Blocks ... if (mUseOrderBlocks) { // has = iState.HasOrderBlocks(); if (has) { // XCOrderBlock *obs[]; count = iState.FilterOrderBlocks( obs, period, XZONE_STATE_PASSED, false, XZONE_STATE_FAILED, false, XZONE_STATE_FAILED, false, XZONE_STATE_IGNORED, false // ); // has = IsValidSize(count); if (has) { // // Try to Add new OBs into Waiting Zones ... // if it's not exists ... for (int i = 0; i < count; i++) { // XBoxZone iBox; bool hasBox = ToBox( iBox, obs[i] // ); if (!hasBox) { // iBox.Clean(); continue; } // // Check Index in Waiting Boxes ... idx = FindIndex( iBox, waitingBoxes // ); has = !IsValidIndex(idx); if (!has) { // iBox.Clean(); continue; } // // Check Index in Inside Boxes ... idx = FindIndex( iBox, insideBoxes // ); has = !IsValidIndex(idx); if (!has) { // iBox.Clean(); continue; } // // Check Index in Breaked Boxes ... idx = FindIndex( iBox, breakedBoxes // ); has = !IsValidIndex(idx); if (!has) { // iBox.Clean(); continue; } // AddRef( iBox, waitingBoxes // ); } } // Clean(obs); } } // // Use Fair Value Gaps ... if (mUseFairValueGaps) { // has = iState.HasFairValueGaps(); if (has) { // XCFVG *fvgs[]; count = iState.FilterFairValueGaps( fvgs, period, XZONE_STATE_PASSED, false, XZONE_STATE_FAILED, false, XZONE_STATE_FAILED, false, XZONE_STATE_IGNORED, false // ); // has = IsValidSize(count); if (has) { // for (int i = 0; i < count; i++) { // XBoxZone iBox; bool hasBox = ToBox( iBox, fvgs[i] // ); if (!hasBox) { // iBox.Clean(); continue; } // // Check Index in Waiting Boxes ... idx = FindIndex( iBox, waitingBoxes // ); has = !IsValidIndex(idx); if (!has) { // iBox.Clean(); continue; } // // Check Index in Inside Boxes ... idx = FindIndex( iBox, insideBoxes // ); has = !IsValidIndex(idx); if (!has) { // iBox.Clean(); continue; } // // Check Index in Breaked Boxes ... idx = FindIndex( iBox, breakedBoxes // ); has = !IsValidIndex(idx); if (!has) { // iBox.Clean(); continue; } // AddRef( iBox, waitingBoxes // ); // iBox.Clean(); } } // Clean(fvgs); } } // iState.Clean(); // // Cleanup Resource ... // zBar.Clean(); cBar.Clean(); } // bool IsDestroyed( int barIndex = 0, ENUM_TIMEFRAMES forPeriod = NULL // ) { // bool result = false; // if (barIndex < 0) { barIndex = 0; } // if (!IsValid(forPeriod)) { forPeriod = period; } // result = IsValid(); if (!result) { return result; } // XOHCL bar; result = bar.Init( symbol, period, barIndex // ); if (!result) { // bar.Clean(); return result; } // XOHCL cBar; result = bar.GetPreviousBar(cBar); if (!result) { // bar.Clean(); cBar.Clean(); // return result; } // bool isSupplyZoneBreaked = // bar.low > supplyZone.Upper() && cBar.low > supplyZone.Upper() // ; // bool isDemandZoneBreaked = // bar.high < demandZone.Lower() && cBar.high < demandZone.Lower() // ; // bar.Clean(); cBar.Clean(); // result = isSupplyZoneBreaked || isDemandZoneBreaked; // return result; } // bool DetectPriority( ENUM_X121SMC_XWZ_PRIORITY &priority, ENUM_X_DIRECTION forDir, int barIndex = 0, ENUM_TIMEFRAMES forPeriod = NULL // ) { // bool result = false; // priority = X121SMC_XWZ_PRIORITY_NONE; // if (barIndex < 0) { barIndex = 0; } // if (!IsValid(forPeriod)) { forPeriod = period; } // result = IsValid() && HasDirection(forDir); if (!result) { return result; } // bool isBullish = IsBullish(forDir); // XOHCL bar; result = bar.Init( symbol, forPeriod, barIndex // ); if (!result) { // bar.Clean(); return result; } // if (bar.high < supplyZone.Upper() && bar.low > supplyZone.Lower()) { // priority = isBullish ? X121SMC_XWZ_PRIORITY_NONE : X121SMC_XWZ_PRIORITY_STRONG_HIGH; } else if (bar.high < supplyZone.Lower() && bar.low > quarter1) { // priority = isBullish ? X121SMC_XWZ_PRIORITY_WEAK : X121SMC_XWZ_PRIORITY_HIGH; } else if (bar.high < quarter1 && bar.low > quarter2) { // priority = isBullish ? X121SMC_XWZ_PRIORITY_LOW : X121SMC_XWZ_PRIORITY_REGULAR; } else if (bar.high < quarter2 && bar.low > quarter3) { // priority = isBullish ? X121SMC_XWZ_PRIORITY_REGULAR : X121SMC_XWZ_PRIORITY_LOW; } else if (bar.high < quarter3 && bar.low > demandZone.Upper()) { // priority = isBullish ? X121SMC_XWZ_PRIORITY_HIGH : X121SMC_XWZ_PRIORITY_WEAK; } else if (bar.high < demandZone.Upper() && bar.low > demandZone.Lower()) { // priority = isBullish ? X121SMC_XWZ_PRIORITY_STRONG_HIGH : X121SMC_XWZ_PRIORITY_NONE; } // result = priority != X121SMC_XWZ_PRIORITY_NONE && priority != X121SMC_XWZ_PRIORITY_WEAK; // bar.Clean(); // return result; } // bool DetectSenarioASignalBox( XBoxZone &signalBox, ENUM_X_DIRECTION &signalDir, X121Conditions &decisionXConditions, X121Conditions &analyseXConditions, XC121SMCCycleHelper *decisionCycleHelper, XCPOIDrawer *drawer = NULL, int barIndex = 0 // ) { // bool result = false; // signalBox.Clean(); signalDir = X_DIRECTION_NONE; // if (barIndex < 0) { barIndex = 0; } // result = decisionCycleHelper != NULL; if (!result) { return result; } // // Decision ... double decisionBullishScore = 0; double decisionBearishScore = 0; decisionXConditions.GenerateScore( decisionBullishScore, decisionBearishScore // ); // // Analyse ... double analyseBullishScore = 0; double analyseBearishScore = 0; analyseXConditions.GenerateScore( analyseBullishScore, analyseBearishScore // ); // // Score Conditions ... double scoreMultiplier = 3; bool isBullishScorePassed = // analyseBullishScore > (analyseBearishScore * scoreMultiplier) && decisionBullishScore > (decisionBearishScore * scoreMultiplier) // ; bool isBearishScorePassed = // analyseBearishScore > (analyseBullishScore * scoreMultiplier) && decisionBearishScore > (decisionBullishScore * scoreMultiplier) // ; // // Checking Other Conditions // bool isCommonBullish = // decisionXConditions.isSarBullish && decisionXConditions.isStrBullish && decisionXConditions.isCheBullish && decisionXConditions.isSMHKBullish && decisionXConditions.isRawHKBullish && decisionXConditions.isRawHKClosedOverSMHK // ; // bool isCommonBearish = // decisionXConditions.isSarBearish && decisionXConditions.isStrBearish && decisionXConditions.isCheBearish && decisionXConditions.isSMHKBearish && decisionXConditions.isRawHKBearish && decisionXConditions.isRawHKClosedUnderSMHK // ; // // X3Ma ... // // X3Ma Bullish ... bool isX3MaBullish = // decisionXConditions.isX3MaBullishState && decisionXConditions.isX3MaSwitchedToBullishOrdered && decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] // ; // // X3Ma Bearish ... bool isX3MaBearish = // decisionXConditions.isX3MaBearishState && decisionXConditions.isX3MaSwitchedToBearishOrdered && decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] // ; // bool isX3MaHasCondition = (isX3MaBullish && isCommonBullish && isBullishScorePassed) || (isX3MaBearish && isCommonBearish && isBearishScorePassed); // // VWap ... // // VWap Bullish ... bool isVWapBullish = // decisionXConditions.isVWapBullishState && decisionXConditions.isVWapSwitchedToBullishOrdered && decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] // ; // // VWap Bearish ... bool isVWapBearish = // decisionXConditions.isVWapBearishState && decisionXConditions.isVWapSwitchedToBearishOrdered && decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] // ; // bool isVWapHasCondition = (isVWapBullish && isBullishScorePassed) || (isVWapBearish && isBearishScorePassed); // // Senario .... // - a vale Under X3MA Slow when X3MA Bullish Ordered ... // bool isX3MASenarioBBullish = // decisionXConditions.isX3MaBullishOrdered && decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] // ; if (isX3MASenarioBBullish) { } // bool isX3MASenarioBBearish = // decisionXConditions.isX3MaBearishOrdered && decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] // ; if (isX3MASenarioBBearish) { } // // Checking Other Conditions XWZ Reject on EMA 20 ... // // Check Has Conditions ... bool hasXConditions = (isX3MaHasCondition || isVWapHasCondition); // result = hasXConditions; if (!result) { return result; } // if (isX3MaHasCondition) { // signalDir = isX3MaBullish ? X_DIRECTION_BULLISH : isX3MaBearish ? X_DIRECTION_BEARISH : X_DIRECTION_NONE; } // if (isVWapHasCondition) { // signalDir = isVWapBullish ? X_DIRECTION_BULLISH : isVWapBearish ? X_DIRECTION_BEARISH : X_DIRECTION_NONE; } // // Creating SignalBox ... // // Detect Box based on PV ... bool hasSignalBox = decisionCycleHelper.GeneratePVBox( signalBox, barIndex // ); // result = hasSignalBox && signalDir == signalBox.dir; // if (result) { // XCBoxObject *iObj; bool isCreated= drawer.DrawBox( signalBox, iObj // ); if (isCreated) { // iObj.BoxWidth(1); iObj.BoxColor(clrYellow); iObj.BoxStyle(STYLE_SOLID); } // Print("Senario A ..."); } // return result; } // bool DetetctSenarioBSignalBox( XBoxZone &signalBox, ENUM_X_DIRECTION &signalDir, X121Conditions &decisionXConditions, X121Conditions &analyseXConditions, XC121SMCCycleHelper *decisionCycleHelper, int barIndex = 0 // ) { // bool result = false; // signalBox.Clean(); signalDir = X_DIRECTION_NONE; // if (barIndex < 0) { barIndex = 0; } // result = decisionCycleHelper != NULL; if (!result) { return result; } // // Decision ... double decisionBullishScore = 0; double decisionBearishScore = 0; decisionXConditions.GenerateScore( decisionBullishScore, decisionBearishScore // ); // // Analyse ... double analyseBullishScore = 0; double analyseBearishScore = 0; analyseXConditions.GenerateScore( analyseBullishScore, analyseBearishScore // ); // // Score Conditions ... double scoreMultiplier = 3; bool isBullishScorePassed = // analyseBullishScore > (analyseBearishScore * scoreMultiplier) && decisionBullishScore > (decisionBearishScore * scoreMultiplier) // ; bool isBearishScorePassed = // analyseBearishScore > (analyseBullishScore * scoreMultiplier) && decisionBearishScore > (decisionBullishScore * scoreMultiplier) // ; // // Senario .... // - a vale Under X3MA Slow when X3MA Bullish Ordered ... // bool isX3MASenarioBBullish = // decisionXConditions.isX3MaBullishOrdered && decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] // ; if (isX3MASenarioBBullish) { } // bool isX3MASenarioBBearish = // decisionXConditions.isX3MaBearishOrdered && decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] // ; if (isX3MASenarioBBearish) { } // return result; } // bool HasInsideBox( XBoxZone &box // ) { // bool result = false; // int index = -1; // result = box.IsValid(); if (!result) { return result; } // int count = 0; bool has = false; // has = HasWaitingBoxes(); if (has) { // result = HasInsideBox( index, box, waitingBoxes // ); } // // Supply Zones ... if (!result) { // has = HasSupplyZones(); if (has) { // XBoxZone tmpBoxes[]; count = ToBox( supplyZones, tmpBoxes // ); // has = IsValidSize(count); if (has) { // result = HasInsideBox( index, box, tmpBoxes // ); } // Clean(tmpBoxes); } } // // Demand Zones ... if (!result) { // has = HasDemandZones(); if (has) { // XBoxZone tmpBoxes[]; count = ToBox( demandZones, tmpBoxes // ); // has = IsValidSize(count); if (has) { // result = HasInsideBox( index, box, tmpBoxes // ); } // Clean(tmpBoxes); } } // result = IsValidIndex(index); // return result; } // void UpdateTo(datetime value = NULL) { // value = NormalizeTime(value); // int count = 0; bool has = false; // has = HasSupplyZone(); if (has) { supplyZone.To(value); } // has = HasDemandZone(); if (has) { demandZone.To(value); } // has = HasSupplyZones(); if (has) { // count = CountSupplyZones(); for (int i = 0; i < count; i++) { supplyZones[i].To(value); } } // has = HasDemandZones(); if (has) { // count = CountDemandZones(); for (int i = 0; i < count; i++) { demandZones[i].To(value); } } // has = HasSupportZones(); if (has) { // count = CountSupportZones(); for (int i = 0; i < count; i++) { supportZones[i].To(value); } } // has = HasResistanceZones(); if (has) { // count = CountResistanceZones(); for (int i = 0; i < count; i++) { resistanceZones[i].To(value); } } // // // // has = HasWaitingBoxes(); if (has) { // count = ArraySize(waitingBoxes); for (int i = 0; i < count; i++) { waitingBoxes[i].to = value; } } // has = HasInsideBoxes(); if (has) { // count = CountInsideBoxes(); for (int i = 0; i < count; i++) { insideBoxes[i].to = value; } } // } // void Draw( XCPOIDrawer *drawer, bool drawWaitingBoxes = true, bool drawInsideBoxes = false, bool drawBreakedBoxes = false, bool drawSupplyZone = false, bool drawDemandZone = false, bool drawSupplyZones = false, bool drawDemandZones = false, bool drawSupportZones = false, bool drawResistanceZones = false // ) { // if (drawer == NULL) { return; } // int count = 0; bool has = false; bool isCreated = false; // ulong chartID = drawer.ChartIdentification(); int subWindow = drawer.SubWindowIdentification(); color bullishColor = drawer.BarBullishColor(); color bearishColor = drawer.BarBearishColor(); // // Supply Zone ... if (drawSupplyZone) { // has = HasSupplyZone(); if (has) { // XCSupplyZoneObject *iObj; isCreated = drawer.CreateSupplyZone( supplyZone, iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } } } // // Demand Zone ... if (drawDemandZone) { // has = HasDemandZone(); if (has) { // XCDemandZoneObject *iObj; isCreated = drawer.CreateDemandZone( demandZone, iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } } } // // // // // Supply Zones ... if (drawSupplyZones) { // has = HasSupplyZones(); if (has) { // count = CountSupplyZones(); for (int i = 0; i < count; i++) { // XCSupplyZoneObject *iObj; isCreated = drawer.CreateSupplyZone( supplyZones[i], iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } } } } // // Demand Zones ... if (drawDemandZones) { // has = HasDemandZones(); if (has) { // count = CountDemandZones(); for (int i = 0; i < count; i++) { // XCDemandZoneObject *iObj; isCreated = drawer.CreateDemandZone( demandZones[i], iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } } } } // // Support Zones ... if (drawSupportZones) { // has = HasSupportZones(); if (has) { // count = CountSupportZones(); for (int i = 0; i < count; i++) { // XCSupportZoneObject *iObj; isCreated = drawer.CreateSupportZone( supportZones[i], iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } } } } // // Resistance Zones ... if (drawResistanceZones) { // has = HasResistanceZones(); if (has) { // count = CountResistanceZones(); for (int i = 0; i < count; i++) { // XCResistanceZoneObject *iObj; isCreated = drawer.CreateResistanceZone( resistanceZones[i], iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } } } } // // // // // Waiting Boxes ... if (drawWaitingBoxes) { // has = HasWaitingBoxes(); if (has) { // count = CountWaitingBoxes(); for (int i = 0; i < count; i++) { // XBoxZone iBox = waitingBoxes[i]; // XCBoxObject *iObj; bool isCreated = drawer.DrawBox( iBox, iObj // ); // if (isCreated) { mWorkingZoneObjects.Add(iObj); } // iBox.Clean(); } } } // // Inside Boxes ... if (drawInsideBoxes) { } // // Breaked Boxes ... if (drawBreakedBoxes) { } // // // // // Quarters ... has = IsValid(); if (has) { // double zoneUpper = supplyZone.Upper(); double upper = supplyZone.Lower(); // double lower = demandZone.Upper(); double zoneLower = demandZone.Lower(); // string prefix = "X121WZone_" + symbol + "_" + ToString(period); // // Zone Upper ... CChartObjectHLine *zoneUpperLine; zoneUpperLine = new CChartObjectHLine(); isCreated = zoneUpperLine.Create( chartID, prefix + "_ZoneTop", subWindow, zoneUpper // ); if (isCreated) { // zoneUpperLine.Color(clrRed); // mWaitingZoneObjects.Add(zoneUpperLine); } // // Zone Lower ... CChartObjectHLine *zoneLowerLine; zoneLowerLine = new CChartObjectHLine(); isCreated = zoneLowerLine.Create( chartID, prefix + "_ZoneDown", subWindow, zoneLower // ); if (isCreated) { // zoneLowerLine.Color(clrRed); // mWaitingZoneObjects.Add(zoneLowerLine); } // // Upper ... CChartObjectHLine *upperLine; upperLine = new CChartObjectHLine(); isCreated = upperLine.Create( chartID, prefix + "_Upper", subWindow, upper // ); if (isCreated) { // upperLine.Color(clrLime); // mWaitingZoneObjects.Add(upperLine); } // // Lower ... CChartObjectHLine *lowerLine; lowerLine = new CChartObjectHLine(); isCreated = lowerLine.Create( chartID, prefix + "_Lower", subWindow, lower // ); if (isCreated) { // lowerLine.Color(clrLime); // mWaitingZoneObjects.Add(lowerLine); } // // Quarters ... // // Quarter 1 ... CChartObjectHLine *q1Line; q1Line = new CChartObjectHLine(); isCreated = q1Line.Create( chartID, prefix + "_Q1", subWindow, quarter1 // ); if (isCreated) { // q1Line.Color(clrYellow); // mWaitingZoneObjects.Add(q1Line); } // // Quarter 2 ... CChartObjectHLine *q2Line; q2Line = new CChartObjectHLine(); isCreated = q2Line.Create( chartID, prefix + "_Q2", subWindow, quarter2 // ); if (isCreated) { // q2Line.Color(clrYellow); // mWaitingZoneObjects.Add(q2Line); } // // Quarter 3 ... CChartObjectHLine *q3Line; q3Line = new CChartObjectHLine(); isCreated = q3Line.Create( chartID, prefix + "_Q3", subWindow, quarter3 // ); if (isCreated) { // q3Line.Color(clrYellow); // mWaitingZoneObjects.Add(q3Line); } } } // // // // bool HasSupplyZone() { return supplyZone != NULL && supplyZone.IsValid(); } // bool HasDemandZone() { return demandZone != NULL && demandZone.IsValid(); } // bool HasSupplyZones() { return HasChild(supplyZones); } // int CountSupplyZones() { return ArraySize(supplyZones); } // bool HasDemandZones() { return HasChild(demandZones); } // int CountDemandZones() { return ArraySize(demandZones); } // bool HasSupportZones() { return HasChild(supportZones); } // int CountSupportZones() { return ArraySize(supportZones); } // bool HasResistanceZones() { return HasChild(resistanceZones); } // int CountResistanceZones() { return ArraySize(resistanceZones); } // bool HasConsolidationZones() { return HasChild(consolidationZones); } // int CountConsolidationZones() { return ArraySize(consolidationZones); } // bool HasWaitingBoxes() { return HasChild(waitingBoxes); } // int CountWaitingBoxes() { return ArraySize(waitingBoxes); } // bool HasInsideBoxes() { return HasChild(insideBoxes); } // int CountInsideBoxes() { return ArraySize(insideBoxes); } // bool HasBreakedBoxes() { return HasChild(breakedBoxes); } // int CountBreakedBoxes() { return ArraySize(breakedBoxes); } // }; // // Definitions ... struct X121SMCStrategyXWZSignalConditions { // // Props ... // string symbol; ENUM_TIMEFRAMES period; // double sl; double reward; double amountPercent; ENUM_X_DIRECTION dir; ENUM_X_POSITION_TYPES type; // // Setup Props ... // datetime setupTime; datetime triggerTime; // double pivot; double point; double sls[]; double targets[]; // XBoxZone signalBox; // ENUM_X121SMC_XWZ_PRIORITY priority; ENUM_X121SMC_XWZ_PROVIDERS provider; // // Constructor ... X121SMCStrategyXWZSignalConditions() { Clean(); } // // Tools ... /** * Cleaning Up ... */ void Clean() { // sl = 0; // dir = X_DIRECTION_NONE; type = X_POSITION_TYPE_NONE; // symbol = NULL; period = NULL; setupTime = NULL; triggerTime = NULL; // ExtensionClean(); // ZeroMemory(this); } /** * Check Condition is Setting Up ... * * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... * * @return ( bool ) */ bool IsSetuped() { // bool result = false; // result = IsValid(setupTime) && HasDirection(dir); if (!result) { return result; } // return result; } /** * Calculate Setup Age ... * * @return ( int ) */ int GetSetupAge() { // int result = 0; // if (!IsSetuped()) { return result; } // result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); // return result; } /** * Detect How we Can Trigger Signal ... * * @return ( bool ) */ bool CanTrigger() { // bool result = false; // result = // sl > 0 && IsValid(symbol) && IsValid(period) && IsValid(triggerTime) && type != X_POSITION_TYPE_ALL && type != X_POSITION_TYPE_NONE // ; // return result; } // // Extensions ... /** * Clean Additional Properties ... */ void ExtensionClean() { // pivot = 0; point = 0; // reward = 0; amountPercent = 0; // Clean(sls); Clean(targets); signalBox.Clean(); // provider = X121SMC_XWZ_PROVIDER_NONE; } // // // // void UpdateTo(datetime value = NULL) { // value = NormalizeTime(value); // int count = 0; bool has = false; } // }; // // Extension Functions ... //