/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // -------------------------------------- // Name: XSCX121Strategy // Description: provides all based classes for use ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Imports ... // #include "../../Classes/x-saherelm.x-poi.class.mq5" #include "../../Classes/x-saherelm.xalert.class.mq5" #include "../../Classes/x-saherelm.xtrade.class.mq5" #include "../Libraries/x-121.smc.lib.mq5" // // Helper(s) ... // // XStrategy Class Implementation(s) ... class XCX121SMCStrategy : public XSCBaseAlert { // // Public ... public: // // // Constructor(s) ... void XCX121SMCStrategy( // // Base ... string _symbol, // Trading Symbol ENUM_TIMEFRAMES _period // Trading TimeFrame ) { // mSymbol = _symbol; mPeriod = _period; // Init(); } // // Deconstructor ... void ~XCX121SMCStrategy() { DeInit(); } // // Getter / Setter (s) ... /** * Retrieve Symbol ... * * @return ( string ) */ string Symbol() { return mSymbol; } /** * Retrieve TimeFrame ... * * @return ( ENUM_TIMEFRAMES ) */ ENUM_TIMEFRAMES Period() { return mPeriod; } /** * Check Strategy is Disabled or not ... * * @return ( bool ) */ bool IsDisabled() { return mForceDisabled; } /** * Get Chart Id ... * * @return ( long ) */ long ChartIdentification() { return mChartID; } /** * Set Chart Id ... * * @param value: Long ... */ void ChartIdentification(long value) { // if (value < 0) { value = 0; } // mChartID = value; if (mPOIDrawer != NULL) { mPOIDrawer.ChartIdentification(value); } } /** * Get Sub Window Id ... * * @return ( int ) */ int SubWindowIdentification() { return mSubWindow; } /** * Set Sub Window Id ... * * @param value: Integer ... */ void SubWindowIdentification(int value) { // if (value < 0) { value = 0; } // mSubWindow = value; if (mPOIDrawer != NULL) { mPOIDrawer.SubWindowIdentification(value); } } /** * Get Signal Volume ... * * @return ( double ) */ double Volume() { return mVolume; } /** * Set Signal Volume ... * * @param value: Double ... */ void Volume(double value) { // if (value < 0.01) { value = 0.01; } // mVolume = value; } /** * Get Risk/Reward Ratio ... * * @return ( double ) */ double R2R() { return mR2R; } /** * Set Risk/Reward Ratio ... * * @param value: Double ... */ void R2R(double value) { // if (value < 0) { value = 1.5; } // mR2R = value; } /** * Get Max Allowed Spread ... * * @return ( double ) */ double MaxAllowedSpread() { return mMaxAllowedSpread; } /** * Set Max Allowed Spread ... * * @param value: Double ... */ void MaxAllowedSpread(double value) { mMaxAllowedSpread = value; } /** * Get Long Signalling State ... * * @return ( bool ) */ bool AllowLong() { return mAllowLong; } /** * Set Long Signalling State ... * * @param value: Boolean ... */ void AllowLong(bool value) { mAllowLong = value; } /** * Get Short Signalling State ... * * @return ( bool ) */ bool AllowShort() { return mAllowShort; } /** * Set Short Signalling State ... * * @param value: Argument 1 */ void AllowShort(bool value) { mAllowShort = value; } // // Actions ... /** * Disable Strategy ... */ void Disable() { mForceDisabled = true; } /** * Enable Strategy ... */ void Enable() { mForceDisabled = false; } /** * Register Signal Event Handler ... * * @param handler: an Instance of TOnXSignal ... */ void AddXSignalEventHandler(TOnX121SMCSignal handler) { // Add( handler, mSignalEventHandlers // ); } // // Virtual Actions ... // // Check Conditions For Signal and Execute Signal ... virtual void HandleTick() { // // Check State ... if (IsDisabled()) { return; } // // Check Signalling State ... if (!AllowLong() && !AllowShort()) { return; } // // Check Bar Tracker State ... if (!mBarTracker.CanProcessBar()) { return; } // // Retrieve Current Tick and Check it's Time // by Last Issued Tick ... MqlTick cTick; bool hasTick = GetTick( mSymbol, cTick // ); bool isSameAsLast = cTick.time == mLastTick.time; if (isSameAsLast) { return; } // // Update Last Issued Tick ... mLastTick = cTick; SaveTickData(); CleanupTicks(); // // Update POIs ... // ENUM_XPOI_EVENTS _4HStates[]; m4HPOI.Update(_4HStates); // ENUM_XPOI_EVENTS _4HSupDemStates[]; m4HSupDemPOI.Update(_4HSupDemStates); // ENUM_XPOI_EVENTS _15MStates[]; m15MPOI.Update(_15MStates); // ENUM_XPOI_EVENTS _5MStates[]; m5MPOI.Update(_5MStates); // // Check Current Processing Tick has Signal or not ... XSignal signal; X121SMCStrategyConditions conditions; bool hasSignal = HasSignal( signal, conditions // ); if (!hasSignal) { return; } // // Waits Until Next Candle if Current Tick has Signal ... mBarTracker.Waits(); // // Notify Signal Event Handlers ... NotifyOnSignalEventHandlers( signal, conditions // ); // // TODO: ... // DrawSignal( // signal, // conditions // // ); // // ClearDraws(); } // // Check Conditions For Signal ... virtual bool HasSignal( XSignal &signal, X121SMCStrategyConditions &conditions // ) { // bool result = false; // signal.Clean(); conditions.Clean(); // int pushers = 0; // double sl = 0; double tp = 0; double risk = 0; double entry = 0; double reward = 0; double r2r = R2R(); double volume = Volume(); ENUM_POSITION_TYPE type = POSITION_TYPE_BUY; ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; // bool hasLong = false; bool hasShort = false; // // Start Calculations ... // double points = GetPoints(mSymbol); // int zIndex = 0; int cIndex = zIndex + 1; int pIndex = cIndex + 1; int ppIndex = pIndex + 1; // // Retrieve Bars ... // // Zero Bar ... XOHCL zBar; result = zBar.Init( mSymbol, mPeriod, zIndex // ); if (!result) { return result; } // // Last Bar ... XOHCL cBar; result = cBar.Init( mSymbol, mPeriod, cIndex // ); if (!result) { return result; } // // Prepare Conditions ... // conditions.symbol = mSymbol; conditions.period = mPeriod; conditions.time = cBar.time; // // Reading POI(s) ... // XPOIState _4HSupDemState; m4HSupDemPOI.GetState(_4HSupDemState); // // 4H ... XPOIState _4HState; m4HPOI.GetState(_4HState); // // 15M ... XPOIState _15MState; m15MPOI.GetState(_15MState); // // 5M ... XPOIState _5MState; m5MPOI.GetState(_5MState); // // Try to Implement SMC Based Conditions ... // // 1- First Step is Find a Supply and Demand Zone ... // - [] this Zone must be Fresh ... // - [] contains Engulfing ... // - [] has Order Block ... // - [] has FVG ... bool isDetected = DetectImportantPOIs( conditions, _4HSupDemState, _4HState, _15MState, _5MState // ); if (isDetected) { // AddRef( conditions, mConditions // ); } // conditions.Clean(); // // Check Conditions for Signal ... int conditionsCount = ArraySize(mConditions); if (!IsValidSize(conditionsCount)) { // result = false; return result; } // // Loop through Conditions for Filter Based on POIs ... int conditionsIDX = -1; for (int i = 0; i < conditionsCount; i++) { // result = false; X121SMCStrategyConditions iConditions = mConditions[i]; // bool isSpreadPassed = IsSpreadPass(); if (!isSpreadPassed) { break; } // DrawConditions(iConditions); // // Longs ... bool isAllowLong = AllowLong(); if (isAllowLong) { // hasLong = false; // // Find Demand Zone ... hasLong = iConditions.demandZone.IsValid(); // if (hasLong) { // conditionsIDX = i; // type = POSITION_TYPE_BUY; entry = GetEntry(mSymbol, type); sl = iConditions.demandZone.lower - (10 * points); risk = entry - sl; reward = risk * r2r; tp = entry + reward; // break; } } // // Shorts ... bool isAllowShort = AllowShort(); if (isAllowShort) { // hasShort = false; // if (hasShort) { // conditionsIDX = i; // type = POSITION_TYPE_SELL; entry = GetEntry(mSymbol, type); sl = iConditions.supplyZone.upper + (10 * points); risk = sl - entry; reward = risk * r2r; tp = entry - reward; // break; } } } // result = hasLong || hasShort; // // Rmove Signal Condition ... if (result && IsValidIndex(conditionsIDX)) { // ArrayRemove( mConditions, conditionsIDX, 1 // ); // signal.sl = sl; signal.tp = tp; signal.type = type; signal.mode = mode; signal.entry = entry; signal.volume = volume; signal.symbol = mSymbol; signal.pushers = pushers; signal.provider = GetTag(); signal.time = TimeCurrent(); signal.period = _5MState.period; // result = PrepareSignal(signal); // hasLong = false; hasShort = false; } // return result; } // // Overrides ... // // Customize Strategy Identifier ... string GetTag() override { return X121SMCStrategyToken; } // // Protected ... protected: // // // Props ... // // Private ... private: // // Props ... // string mSymbol; // Trading Symbol ... ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ... bool mForceDisabled; // Force Disabled ... bool mAllowLong; // Allow Long Signals bool mAllowShort; // Allow Short Signals double mR2R; // Risk/Rewar Ratio ... double mVolume; // Static Volume Per Trades ... double mMaxAllowedSpread; // Max Allowed Spread ... // XTick mTicks[]; // Hold Ticks Data ... MqlTick mLastTick; // Last Issued Tick ... /** * Cleanup Ticks Size ... */ void CleanupTicks() { // int maxRequiredTicks = 50; int ticksCount = ArraySize(mTicks); if (!IsValidSize(ticksCount) || ticksCount <= maxRequiredTicks) { return; } // int removeCount = ticksCount - maxRequiredTicks; if (!IsValidSize(removeCount)) { return; } // ArrayRemove( mTicks, 0, removeCount // ); } /** * Add new Tick Data to Collection ... */ void SaveTickData() { // XTick tick; bool isInited = tick.Init(mSymbol); if (!isInited) { return; } // AddRef( tick, mTicks // ); } /** * Check Spread Passed for Positions... * * @return ( bool ) */ bool IsSpreadPass() { // bool result = false; // int length = 5; double pointValue = GetPoints(mSymbol); double maxAllowedSpread = MaxAllowedSpread(); if (maxAllowedSpread > 0) { maxAllowedSpread *= pointValue; } // int ticksCount = ArraySize(mTicks); if (ticksCount <= length) { return result; } // int start = -1; int end = -1; CalculateTicksParams( start, end, length + 1 // ); result = IsValidIndex(start) && IsValidIndex(end); if (!result) { return result; } // end -= 1; double spreadAVG = 0; for (int i = start; i < end; i++) { spreadAVG += mTicks[i].spread; } spreadAVG /= length; // double lastSpread = mTicks[ticksCount - 1].spread; // result = lastSpread <= spreadAVG && (maxAllowedSpread <= 0 ? true : lastSpread <= maxAllowedSpread); // return result; } /** * Calculate Ticks Param for Looping through Last n items ... * * @param start: Integer Reference to Start ... * @param end: Integer Reference to End ... * @param numOfLastTicks: Integer Max Number of Required N Last Ticks ... */ void CalculateTicksParams( int &start, int &end, int numOfLastTicks = 5 // ) { // start = -1; end = -1; // int count = ArraySize(mTicks); // start = count - numOfLastTicks; if (start < 0) { start = 0; } // end = start + numOfLastTicks; if (end > count) { end = count; } } /** * Check Ticks is Bullish or not ... * * @return ( bool ) */ bool IsTicksBullish() { // bool result = false; // int start = -1; int end = -1; CalculateTicksParams( start, end // ); result = IsValidIndex(start) && IsValidIndex(end); if (!result) { return result; } // result = true; for (int i = start + 1; i < end; i++) { // XTick iTick = mTicks[i]; XTick prevTick = mTicks[i - 1]; // bool isBullish = iTick.bid >= prevTick.bid; result = result && isBullish; if (!result) { break; } } // return result; } /** * Check Ticks is Bearish or not ... * * @return ( bool ) */ bool IsTicksBearish() { // bool result = false; // int start = -1; int end = -1; CalculateTicksParams( start, end // ); result = IsValidIndex(start) && IsValidIndex(end); if (!result) { return result; } // result = true; for (int i = start + 1; i < end; i++) { // XTick iTick = mTicks[i]; XTick prevTick = mTicks[i - 1]; // bool isBearish = iTick.bid <= prevTick.bid; result = result && isBearish; if (!result) { break; } } // return result; } /** * Check Ticks Has Momentum or not ... * * @return ( bool ) */ bool IsTicksHasMomentum() { // bool result = false; // int start = -1; int end = -1; CalculateTicksParams( start, end // ); result = IsValidIndex(start) && IsValidIndex(end); if (!result) { return result; } // result = true; int lastDiff = 0; for (int i = start + 1; i < end; i++) { // XTick iTick = mTicks[i]; XTick prevTick = mTicks[i - 1]; // int timeDiff = MathAbs((int)iTick.time - (int)prevTick.bid); result = result && timeDiff >= lastDiff; if (!result) { break; } // lastDiff = timeDiff; } // return result; } // XBarTracker mBarTracker; // Strategy Time Tracker ... // // Point Of Interests ... XCPOI *m4HPOI; XCPOI *m4HSupDemPOI; XCPOI *m15MPOI; XCPOI *m5MPOI; // // Collect all Drawn Objects ... CArrayObj mDrawnObjects; /** * Clear all Drawn Objects ... */ void ClearDraws() { mDrawnObjects.Clear(); } /** * Remove Specified Drawn Object ... * * @param name: Object name ... */ void RemoveObject(string name) { // if (!IsValid(name)) { return; } // int count = mDrawnObjects.Total(); if (!IsValidSize(count)) { return; } // int idx = -1; for (int i = 0; i < count; i++) { // string iName = ((CChartObject *)mDrawnObjects.At(i)).Name(); string iObjName = NULL; if (!IsValid(iName)) { iObjName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); } // if ((IsValid(iName) && iName == name) || (IsValid(iObjName) && iObjName == name)) { // idx = i; break; } } // if (IsValidIndex(idx)) { mDrawnObjects.Delete(idx); } } // XOHCL mSwingHigh; CChartObjectHLine *mSwingHighObject; // XOHCL mSwingLow; CChartObjectHLine *mSwingLowObject; // // Holding Supply and Demand Zones ... // XZone mSupplyZones[]; // XZone mDemandZones[]; // // XZone mBearishOrderBlocks[]; // XZone mBullishOrderBlocks[]; // // XZone mBearishFVGs[]; // XZone mBullishFVGs[]; // X121SMCStrategyConditions mConditions[]; // // Actions ... /** * Install all Helpers and Prepare all Configurations for required Indicators ... */ void Init() { // mForceDisabled = false; // R2R(2); Volume(0.01); // ChartIdentification(0); SubWindowIdentification(0); // // Configure POI Drawer if Required ... mPOIDrawer = new XCPOIDrawer(); mPOIDrawer.ChartIdentification(0); mPOIDrawer.SubWindowIdentification(0); // mPOIDrawer.DemandZoneFill(false); mPOIDrawer.SupplyZoneFill(false); mPOIDrawer.BullishFVGFill(false); mPOIDrawer.BearishFVGFill(false); mPOIDrawer.SupportZoneFill(false); mPOIDrawer.ResistanceZoneFill(false); mPOIDrawer.BullishOrderBlockFill(false); mPOIDrawer.BearishOrderBlockFill(false); // string symbol = Symbol(); ENUM_TIMEFRAMES period = Period(); // // Initialize Bar Tracker ... mBarTracker.Init( symbol, period // ); // // Initialize POIs ... // // this used only for Supply and // Demand Zone for H4 Time Frame .., // POI Detector ... m4HSupDemPOI = new XCPOI( symbol, PERIOD_M15 // ); m4HSupDemPOI.DisablePOIs(); m4HSupDemPOI.DisableDrawPOIs(); m4HSupDemPOI.AllowSupplyZones(true); m4HSupDemPOI.AllowDemandZones(true); m4HSupDemPOI.SupplyZonePeriod(PERIOD_H4); m4HSupDemPOI.DemandZonePeriod(PERIOD_H4); m4HSupDemPOI.SubWindowIdentification(0); m4HSupDemPOI.ChartIdentification(ChartID()); // m4HSupDemPOI.Init(); // // 4H Period ... // POI Detector ... m4HPOI = new XCPOI( symbol, PERIOD_H4 // ); // m4HPOI.DisableDrawPOIs(); m4HPOI.SupplyZonePeriod(PERIOD_H4); m4HPOI.DemandZonePeriod(PERIOD_H4); m4HPOI.SubWindowIdentification(0); m4HPOI.ChartIdentification(ChartID()); // m4HPOI.Init(); // // 15M Period ... // POI Detector ... m15MPOI = new XCPOI( symbol, PERIOD_M15 // ); // m15MPOI.DisableDrawPOIs(); m15MPOI.MaxNumberOfRequiredPOIs(2); m15MPOI.SupplyZonePeriod(PERIOD_M15); m15MPOI.DemandZonePeriod(PERIOD_M15); m15MPOI.SubWindowIdentification(0); m15MPOI.ChartIdentification(ChartID()); // m15MPOI.Init(); // // Trigger Period ... // POI Detector ... m5MPOI = new XCPOI( symbol, PERIOD_M5 // ); // m5MPOI.DisableDrawPOIs(); m5MPOI.MaxNumberOfRequiredPOIs(2); m5MPOI.SupplyZonePeriod(PERIOD_M5); m5MPOI.DemandZonePeriod(PERIOD_M5); m5MPOI.SubWindowIdentification(0); m5MPOI.ChartIdentification(ChartID()); // m5MPOI.Init(); // } /** * De Initialize all Tools ... */ void DeInit() { // delete m4HPOI; delete m5MPOI; delete m15MPOI; delete m4HSupDemPOI; // delete mPOIDrawer; // ClearDraws(); } /** * Reste Bar Tracker ... */ void ResetBarTracker() { mBarTracker.Clean(); } /** * Prepare and Normalize Signal for Execution in Strategy ... * * @param signal: XSignal instance ... * * @return ( bool ) */ bool PrepareSignal(XSignal &signal) { // bool result = false; // // Check Strategy Is Enables ... result = !IsDisabled(); if (!result) { return result; } // // Validate Signal ... result = signal.IsValid(); if (!result) { return result; } // bool isLong = IsLong(signal.type); // // TODO: Implement Signal Preparation Mechanism here ... // return result; } /** * Update Supply and Demand Zones ... * * @param state: Argument 1 */ bool DetectImportantPOIs( X121SMCStrategyConditions &conditions, XPOIState &supplyAndDemandZoneState, XPOIState &orderBlocksState, XPOIState &fvgsState, XPOIState &triggerState // ) { // bool result = false; // int supplyZonesCount = ArraySize(supplyAndDemandZoneState.supplyZones); int demandZonesCount = ArraySize(supplyAndDemandZoneState.demandZones); // XOHCL swingHighs[]; Copy( orderBlocksState.swingHighs, swingHighs // ); Copy( fvgsState.swingHighs, swingHighs, false // ); Copy( triggerState.swingHighs, swingHighs, false // ); // XOHCL swingLows[]; Copy( orderBlocksState.swingLows, swingLows // ); Copy( fvgsState.swingLows, swingLows, false // ); Copy( triggerState.swingLows, swingLows, false // ); // int swingHighsCount = ArraySize(swingHighs); int swingLowsCount = ArraySize(swingLows); if (!IsValidSize(swingLowsCount) || !IsValidSize(swingHighsCount) || !IsValidSize(supplyZonesCount) || !IsValidSize(demandZonesCount)) { return result; } // XOHCL zBar; bool isInited = zBar.Init( Symbol(), Period(), 0 // ); if (!isInited) { return result; } // // Detect Swing High and Low as Market Structure Boundaries ... // // Swing High ... XOHCL tmpBar; for (int i = 0; i < swingHighsCount; i++) { // XOHCL iSwing = swingHighs[i]; // if (!tmpBar.IsValid() || tmpBar.high < iSwing.high) { tmpBar = iSwing; } } if (tmpBar.IsValid()) { // mSwingHigh = tmpBar; string name = tmpBar.GetTag(ToString(X_POI_SWING_HIGH)); if (mSwingHighObject != NULL) { mSwingHighObject.Delete(); } mSwingHighObject = new CChartObjectHLine(); bool isCreated = mSwingHighObject.Create( ChartIdentification(), name, SubWindowIdentification(), tmpBar.high // ); if (isCreated) { // mSwingHighObject.Width(2); mSwingHighObject.Color(clrRed); mSwingHighObject.Style(STYLE_DASHDOTDOT); } } // // Swing Low ... tmpBar.Clean(); for (int i = 0; i < swingLowsCount; i++) { // XOHCL iSwing = swingLows[i]; // if (!tmpBar.IsValid() || tmpBar.low > iSwing.low) { tmpBar = iSwing; } } if (tmpBar.IsValid()) { // mSwingLow = tmpBar; string name = tmpBar.GetTag(ToString(X_POI_SWING_LOW)); if (mSwingLowObject != NULL) { mSwingLowObject.Delete(); } mSwingLowObject = new CChartObjectHLine(); bool isCreated = mSwingLowObject.Create( ChartIdentification(), name, SubWindowIdentification(), tmpBar.low // ); if (isCreated) { // mSwingLowObject.Width(2); mSwingLowObject.Color(clrLime); mSwingLowObject.Style(STYLE_DASHDOTDOT); } } tmpBar.Clean(); // // Demand Zone ... for (int i = 0; i < demandZonesCount; i++) { // // Demand Zone ... XZone iDemandZone = supplyAndDemandZoneState.demandZones[i]; conditions.demandZone = iDemandZone; // // Order Blocks ... int orderBlocksCount = ArraySize(orderBlocksState.bullishOrderBlocks); if (IsValidSize(orderBlocksCount)) { // for (int j = 0; j < orderBlocksCount; j++) { // XZone jZone = orderBlocksState.bullishOrderBlocks[j]; // bool isInside = jZone.from >= iDemandZone.from && jZone.lower > iDemandZone.lower && jZone.lower < iDemandZone.upper; if (isInside) { // AddRef( jZone, conditions.bullishOrderBlocks // ); } } } // // Support Zones ... int supportsCount = ArraySize(fvgsState.supportZones); if (IsValidSize(supportsCount)) { // for (int j = 0; j < supportsCount; j++) { // XOHCL jBar = fvgsState.supportZones[j]; // bool isInside = jBar.time > iDemandZone.from && jBar.low > iDemandZone.lower && jBar.low < iDemandZone.upper; if (isInside) { // AddRef( jBar, conditions.supports // ); } } } // // Bullish FVGs ... int fvgsCount = ArraySize(fvgsState.bullishFVGs); if (IsValidSize(fvgsCount)) { // for (int j = 0; j < fvgsCount; j++) { // XZone jFVG = fvgsState.bullishFVGs[j]; // bool isInside = jFVG.from > iDemandZone.from; if (isInside) { // AddRef( jFVG, conditions.bullishFVGs // ); } } } // // Swing Lows ... int swingLowsCount = ArraySize(triggerState.swingLows); if (IsValidSize(swingLowsCount)) { // for (int j = 0; j < swingLowsCount; j++) { // XOHCL jBar = triggerState.swingLows[j]; // bool isInside = jBar.time > iDemandZone.from && jBar.low > iDemandZone.lower && jBar.GetDown() < iDemandZone.upper; if (isInside) { // AddRef( jBar, conditions.swingLows // ); } } } // // Bullish Momentum Bars ... int bullishMomentumBarsCount = ArraySize(triggerState.momentumBars); if (IsValidSize(bullishMomentumBarsCount)) { // for (int j = 0; j < bullishMomentumBarsCount; j++) { // XOHCL jBar = triggerState.momentumBars[j]; // bool isInside = jBar.IsBullish() && jBar.time > iDemandZone.from && jBar.low > iDemandZone.lower && jBar.low < iDemandZone.upper; if (isInside) { // AddRef( jBar, conditions.bullishMomentumBars // ); } } } // // Bullish Rejection Bars ... int bullishRejectionBarsCount = ArraySize(triggerState.rejectionBars); if (IsValidSize(bullishRejectionBarsCount)) { // for (int j = 0; j < bullishRejectionBarsCount; j++) { // XOHCL jBar = triggerState.rejectionBars[j]; // bool isInside = jBar.GetLowShadow() > jBar.GetHighShadow() && jBar.time > iDemandZone.from && jBar.low > iDemandZone.lower && jBar.low < iDemandZone.upper; if (isInside) { // AddRef( jBar, conditions.bullishRejectionBars // ); } } } } // // Supply Zone ... for (int i = 0; i < demandZonesCount; i++) { // // Supply Zone ... XZone iSupplyZone = supplyAndDemandZoneState.supplyZones[i]; conditions.supplyZone = iSupplyZone; // // Order Blocks ... int orderBlocksCount = ArraySize(orderBlocksState.bearishOrderBlocks); if (IsValidSize(orderBlocksCount)) { // for (int j = 0; j < orderBlocksCount; j++) { // XZone jZone = orderBlocksState.bearishOrderBlocks[j]; // bool isInside = jZone.from > iSupplyZone.from && jZone.upper > iSupplyZone.lower && jZone.upper < iSupplyZone.upper; if (isInside) { // AddRef( jZone, conditions.bearishOrderBlocks // ); } } } // // Resistance Zones ... int resistancesCount = ArraySize(fvgsState.resistanceZones); if (IsValidSize(resistancesCount)) { // for (int j = 0; j < resistancesCount; j++) { // XOHCL jBar = fvgsState.resistanceZones[j]; // bool isInside = jBar.time > iSupplyZone.from && jBar.high > iSupplyZone.lower && jBar.high < iSupplyZone.upper; if (isInside) { // AddRef( jBar, conditions.resistances // ); } } } // // Bearish FVGs ... int fvgsCount = ArraySize(fvgsState.bearishFVGs); if (IsValidSize(fvgsCount)) { // for (int j = 0; j < fvgsCount; j++) { // XZone jZone = fvgsState.bearishFVGs[j]; // bool isInside = jZone.from > iSupplyZone.from && jZone.upper > iSupplyZone.lower && jZone.upper < iSupplyZone.upper; if (isInside) { // AddRef( jZone, conditions.bearishFVGs // ); } } } // // Swing Highs ... int swingHighsCount = ArraySize(triggerState.swingHighs); if (IsValidSize(swingHighsCount)) { // for (int j = 0; j < swingHighsCount; j++) { // XOHCL jBar = triggerState.swingHighs[j]; // bool isInside = jBar.time > iSupplyZone.from && jBar.high > iSupplyZone.lower && jBar.high < iSupplyZone.upper; if (isInside) { // AddRef( jBar, conditions.swingHighs // ); } } } // // Bearish Momentum Bars ... int bearishMomentumBarsCount = ArraySize(triggerState.momentumBars); if (IsValidSize(bearishMomentumBarsCount)) { // for (int j = 0; j < bearishMomentumBarsCount; j++) { // XOHCL jBar = fvgsState.momentumBars[j]; // bool isInside = jBar.IsBearish() && jBar.time > iSupplyZone.from && jBar.high > iSupplyZone.lower && jBar.high < iSupplyZone.upper; if (isInside) { // AddRef( jBar, conditions.bearishMomentumBars // ); } } } // // Bearish Rejection Bars ... int bearishRejectionBarsCount = ArraySize(triggerState.rejectionBars); if (IsValidSize(bearishRejectionBarsCount)) { // for (int j = 0; j < bearishRejectionBarsCount; j++) { // XOHCL jBar = fvgsState.rejectionBars[j]; // bool isInside = jBar.GetHighShadow() > jBar.GetLowShadow() && jBar.time > iSupplyZone.from && jBar.high > iSupplyZone.lower && jBar.high < iSupplyZone.upper; if (isInside) { // AddRef( jBar, conditions.bearishRejectionBars // ); } } } } // bool isConditionReadyForDemand = conditions.demandZone.IsValid() && (ArraySize(conditions.supports) > 0 || ArraySize(conditions.swingLows) > 0 || ArraySize(conditions.bullishFVGs) > 0 || ArraySize(conditions.bullishOrderBlocks) > 0 || ArraySize(conditions.bullishMomentumBars) > 0 || ArraySize(conditions.bullishRejectionBars) > 0); // bool isConditionReadyForSupply = conditions.supplyZone.IsValid() && (ArraySize(conditions.swingHighs) > 0 || ArraySize(conditions.bearishFVGs) > 0 || ArraySize(conditions.resistances) > 0 || ArraySize(conditions.bearishOrderBlocks) > 0 || ArraySize(conditions.bearishMomentumBars) > 0 || ArraySize(conditions.bearishRejectionBars) > 0); // result = isConditionReadyForDemand || isConditionReadyForSupply; // return result; } // // On X121 Signal Recieved Event Handler(s) ... TOnX121SMCSignal mSignalEventHandlers[]; // /** * Notified Signal Event Handler(s) ... * * @param signal: XSignal instance ... * @param conditions: XStrategyConditions instance ... */ void NotifyOnSignalEventHandlers( XSignal &signal, X121SMCStrategyConditions &conditions // ) { // if (!signal.IsValid() || !conditions.IsValid()) { return; } // int count = ArraySize(mSignalEventHandlers); if (!IsValidSize(count)) { return; } // for (int i = 0; i < count; i++) { // mSignalEventHandlers[i]( signal, conditions // ); } } // // Draw Functions ... // long mChartID; // Chart ID ... int mSubWindow; // Sub Window ID ... XCPOIDrawer *mPOIDrawer; // POI Drawer Class ... /** * Draw Specific Condition ... * * @param conditions: X121SMCStrategyConditions instance ... */ void DrawConditions(X121SMCStrategyConditions &conditions) { // if (!conditions.IsValid()) { return; } // // Demand Zone ... if (conditions.demandZone.IsValid()) { // // Demand ... XCDemandZoneObject *iObj; bool isCreated = mPOIDrawer.CreateDemandZone( conditions.demandZone, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } // // Order Blocks ... int obsCount = ArraySize(conditions.bullishOrderBlocks); if (IsValidSize(obsCount)) { // for (int i = 0; i < obsCount; i++) { // XZone iZone = conditions.bullishOrderBlocks[i]; // XCBullishOrderBlockObject *iObj; bool isCreated = mPOIDrawer.CreateBullishOrderBlock( iZone, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Fair Value Gaps ... int fvgsCount = ArraySize(conditions.bullishFVGs); if (IsValidSize(fvgsCount)) { // for (int i = 0; i < fvgsCount; i++) { // XZone iZone = conditions.bullishFVGs[i]; // XCBullishFVGObject *iObj; bool isCreated = mPOIDrawer.CreateBullishFVG( iZone, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Supports ... int supportsCount = ArraySize(conditions.supports); if (IsValidSize(supportsCount)) { // for (int i = 0; i < supportsCount; i++) { // XOHCL iBar = conditions.supports[i]; // XCSupportZoneObject *iObj; bool isCreated = mPOIDrawer.CreateSupportZone( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Swings ... int swingsCount = ArraySize(conditions.swingLows); if (IsValidSize(swingsCount)) { // for (int i = 0; i < swingsCount; i++) { // XOHCL iBar = conditions.swingLows[i]; // XCSwingLowObject *iObj; bool isCreated = mPOIDrawer.CreateSwingLow( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Momentum Bars ... int momentumBarsCount = ArraySize(conditions.bullishMomentumBars); if (IsValidSize(momentumBarsCount)) { // for (int i = 0; i < momentumBarsCount; i++) { // XOHCL iBar = conditions.bullishMomentumBars[i]; // XCBullishMomentumBarObject *iObj; bool isCreated = mPOIDrawer.CreateBullishMomentumBar( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Rejection Bars ... int rejectionBarsCount = ArraySize(conditions.bullishRejectionBars); if (IsValidSize(rejectionBarsCount)) { // for (int i = 0; i < rejectionBarsCount; i++) { // XOHCL iBar = conditions.bullishRejectionBars[i]; // XCBullishRejectionBarObject *iObj; bool isCreated = mPOIDrawer.CreateBullishRejectionBar( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } } // // Supply Zone ... if (conditions.supplyZone.IsValid()) { // // Supply ... XCSupplyZoneObject *iObj; bool isCreated = mPOIDrawer.CreateSupplyZone( conditions.supplyZone, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } // // Order Blocks ... int obsCount = ArraySize(conditions.bearishOrderBlocks); if (IsValidSize(obsCount)) { // for (int i = 0; i < obsCount; i++) { // XZone iZone = conditions.bearishOrderBlocks[i]; // XCBearishOrderBlockObject *iObj; bool isCreated = mPOIDrawer.CreateBearishOrderBlock( iZone, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Fair Value Gaps ... int fvgsCount = ArraySize(conditions.bearishFVGs); if (IsValidSize(fvgsCount)) { // for (int i = 0; i < fvgsCount; i++) { // XZone iZone = conditions.bearishFVGs[i]; // XCBearishFVGObject *iObj; bool isCreated = mPOIDrawer.CreateBearishFVG( iZone, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Resistances ... int resistancesCount = ArraySize(conditions.resistances); if (IsValidSize(resistancesCount)) { // for (int i = 0; i < resistancesCount; i++) { // XOHCL iBar = conditions.resistances[i]; // XCResistanceZoneObject *iObj; bool isCreated = mPOIDrawer.CreateResistanceZone( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Swings ... int swingsCount = ArraySize(conditions.swingHighs); if (IsValidSize(swingsCount)) { // for (int i = 0; i < swingsCount; i++) { // XOHCL iBar = conditions.swingHighs[i]; // XCSwingHighObject *iObj; bool isCreated = mPOIDrawer.CreateSwingHigh( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Momentum Bars ... int momentumBarsCount = ArraySize(conditions.bearishMomentumBars); if (IsValidSize(momentumBarsCount)) { // for (int i = 0; i < momentumBarsCount; i++) { // XOHCL iBar = conditions.bearishMomentumBars[i]; // XCBearishMomentumBarObject *iObj; bool isCreated = mPOIDrawer.CreateBearishMomentumBar( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } // // Rejection Bars ... int rejectionBarsCount = ArraySize(conditions.bearishRejectionBars); if (IsValidSize(rejectionBarsCount)) { // for (int i = 0; i < rejectionBarsCount; i++) { // XOHCL iBar = conditions.bearishRejectionBars[i]; // XCBearishRejectionBarObject *iObj; bool isCreated = mPOIDrawer.CreateBearishRejectionBar( iBar, iObj // ); if (isCreated) { // // RemoveObject(iObj.ObjName()); mDrawnObjects.Add(iObj); } } } } } /** * Draw Specified Signal ... * * @param signal: XSignal instance ... * @param conditions: X121SMCStrategyConditions instance ... */ void DrawSignal( XSignal &signal, X121SMCStrategyConditions &conditions // ) { // if (!signal.IsValid() || !conditions.IsValid()) { // return; } // // DrawConditions(conditions); // string name = signal.GetTag(); RemoveObject(name); // XCSignalObject *iObj; iObj = new XCSignalObject(); // bool isCreated = iObj.Create( ChartID(), name, 0, signal // ); if (!isCreated) { return; } // iObj.TPWidth(1); iObj.TPColor(clrGreen); iObj.TPWidth(STYLE_DOT); // iObj.SLWidth(1); iObj.SLColor(clrRed); iObj.SLWidth(STYLE_DOT); // iObj.EntryWidth(1); iObj.EntryColor(clrYellow); iObj.EntryWidth(STYLE_DOT); // mDrawnObjects.Add(iObj); } // }; //