diff --git a/Documents/BKP/tmp.x121.smc.mq5 b/Documents/BKP/tmp.x121.smc.mq5 index 5af02e04..b2aac98e 100644 --- a/Documents/BKP/tmp.x121.smc.mq5 +++ b/Documents/BKP/tmp.x121.smc.mq5 @@ -2076,3 +2076,75 @@ // m1.Fill(mOrderFlow[pivotIDX].state); // } // } + + +////////////////////////////////// + + /** + * Detect SL Candidates based on Strategy and Conditions ... + * + * @param result: Double array reference ... + * @param entry: Double, Position Entry Price ... + * @param conditions: X121SMCStrategyConditions instance, Provides Configurations ... + * @param type: ENUM_X_POSITION_TYPES member, Specified Position Type ... + */ + void DetectSLCandidates( + double &result[], + double entry, + X121SMCStrategyConditions &conditions, + ENUM_X_POSITION_TYPES type // + ) override + { + // + Clean(result); + + // + int cIndex = 1; + + // + if (entry <= 0 || + !conditions.IsValid() || + type == X_POSITION_TYPE_ALL || + type == X_POSITION_TYPE_NONE) + { + return; + } + + // + Add( + conditions.x3vwapConditions.fasts[cIndex], + result // + ); + + // + Add( + conditions.x3vwapConditions.mids[cIndex], + result // + ); + + // + Add( + conditions.x3vwapConditions.slows[cIndex], + result // + ); + + // + Add( + conditions.x3maConditions.fasts[cIndex], + result // + ); + + // + Add( + conditions.xpvConditions.vales[cIndex], + result // + ); + + // + Add( + conditions.xpvConditions.peaks[cIndex], + result // + ); + + // + } diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index a4e09093..329aa265 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -9,7 +9,7 @@ // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // -//////////////////////////////////////////////////////x +////////////////////////////////////////////////////// // // Global Properties ... #property copyright "Copyright 2023, SaherElm IT Center" diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index 489b8877..547ea974 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -262,6 +262,40 @@ ENUM_X_POSITION_TYPES GetOppositPositionType(ENUM_POSITION_TYPE type) return result; } +// +ENUM_X_DIRECTION ToDirection(ENUM_POSITION_TYPE value) +{ + // + ENUM_X_DIRECTION result = X_DIRECTION_NONE; + + // + result = IsLong(value) + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; +} + +// +ENUM_X_DIRECTION ToDirection(ENUM_X_POSITION_TYPES value) +{ + // + ENUM_X_DIRECTION result = X_DIRECTION_NONE; + + // + result = value == X_POSITION_TYPE_ALL + ? X_DIRECTION_ALL + : value == X_POSITION_TYPE_LONG + ? X_DIRECTION_BULLISH + : value == X_POSITION_TYPE_SHORT + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + return result; +} + // // Structs ... diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 526f1418..614c1ee7 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -359,6 +359,10 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + // + // Detect Fair Value Gaps ... + + // bool isOrderFlowBullish = IsBullish(mOrderFlowDir); @@ -419,14 +423,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // ; - // - if (hasCHOCH) - { - // RedrawOrderFlow(); - mLastCHOCHOn = TimeCurrent(); - // ClearDraws(); - } - // // Check PSar is Equals to Peak or Vale ... bool isSAREqualsToPeak = @@ -751,17 +747,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ); // - // double candidates[]; - // DetectSLCandidates( - // candidates, - // entry, - // conditions, - // xType // - // ); - // double selectedSL = - // hasLong - // ? GetMax(candidates) - // : GetMin(candidates); sl = hasLong ? selectedSL - pip2 @@ -798,7 +783,75 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy { // Print("PRV: ", provider); - RedrawOrderFlow(); + + // + ENUM_X_DIRECTION forDir = ToDirection(signal.type); + bool ignoreSwingHighs = false; + bool ignoreSwingLows = false; + bool ignoreSupportZones = false; + bool ignoreResistanceZones = false; + bool ignoreSupplyZones = false; + bool ignoreDemandZones = false; + bool ignoreBullishOrderBlocks = false; + bool ignoreBearishOrderBlocks = false; + bool ignoreBullishFairValueGaps = false; + bool ignoreBearishFairValueGaps = false; + bool ignoreBullishRejectionBars = false; + bool ignoreBearishRejectionBars = false; + bool ignoreBullishMomentumBars = false; + bool ignoreBearishMomentumBars = false; + if (IsBullish(forDir)) + { + // + ignoreSwingLows = false; + ignoreDemandZones = false; + ignoreSupportZones = false; + ignoreBullishOrderBlocks = false; + ignoreBullishFairValueGaps = false; + ignoreBullishRejectionBars = false; + ignoreBullishMomentumBars = false; + } + else + { + // + ignoreSwingHighs = true; + ignoreSupplyZones = true; + ignoreResistanceZones = true; + ignoreBearishOrderBlocks = true; + ignoreBearishFairValueGaps = false; + ignoreBearishRejectionBars = true; + ignoreBearishMomentumBars = true; + } + + // + RedrawOrderFlow( + true, // Force Clean ... + false, // Same Period ... + true, // Order Flow ... + true, // Order Flow State ... + false, // Only Last Order Flow ... + true, // Only Last Order Flow State ... + // + forDir, // Direction Force ... + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars, + // + false, // Vision State ... + false, // Analyse State ... + false // Trigger State ... + ); DrawSignal(signal); ClearDraws(); @@ -815,75 +868,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } - /** - * Detect SL Candidates based on Strategy and Conditions ... - * - * @param result: Double array reference ... - * @param entry: Double, Position Entry Price ... - * @param conditions: X121SMCStrategyConditions instance, Provides Configurations ... - * @param type: ENUM_X_POSITION_TYPES member, Specified Position Type ... - */ - void DetectSLCandidates( - double &result[], - double entry, - X121SMCStrategyConditions &conditions, - ENUM_X_POSITION_TYPES type // - ) override - { - // - Clean(result); - - // - int cIndex = 1; - - // - if (entry <= 0 || - !conditions.IsValid() || - type == X_POSITION_TYPE_ALL || - type == X_POSITION_TYPE_NONE) - { - return; - } - - // - Add( - conditions.x3vwapConditions.fasts[cIndex], - result // - ); - - // - Add( - conditions.x3vwapConditions.mids[cIndex], - result // - ); - - // - Add( - conditions.x3vwapConditions.slows[cIndex], - result // - ); - - // - Add( - conditions.x3maConditions.fasts[cIndex], - result // - ); - - // - Add( - conditions.xpvConditions.vales[cIndex], - result // - ); - - // - Add( - conditions.xpvConditions.peaks[cIndex], - result // - ); - - // - } - /** * Customize Strategy Identifier ... */ @@ -1043,7 +1027,13 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy int lastPivotIDX = ArraySize(mOrderFlow) - 1; if (IsValidSize(lastPivotIDX)) { - FillPivotSate(lastPivotIDX); + // + FillPivotSate( + lastPivotIDX, + true, // Use Vision State ... + true, // Use Analyse State ... + false // Use Trigger State ... + ); } } @@ -1352,7 +1342,13 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // Loop Through Order Flow ... for (int i = 0; i < orderFlowCount; i++) { - FillPivotSate(i); + // + FillPivotSate( + i, + true, // Use Vision State ... + true, // Use Analyse State ... + false // Use Trigger State ... + ); } } @@ -1380,7 +1376,10 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy * @param lookupBearishMomentumBars: Boolean ... */ void FillPivotSate( - int pivotIDX, // + int pivotIDX, // + bool useVisionState = true, // Use Vision State ... + bool useAnalyseState = true, // Use Analyse State ... + bool useTriggerState = true, // Use Trigger State ... bool lookupSwingHighs = true, bool lookupSwingLows = true, bool lookupSupportZones = true, @@ -1403,7 +1402,8 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Trigger ... XPOIState mTriggerState; - if (mTriggerPOIState.HasChild()) + if (useTriggerState && + mTriggerPOIState.HasChild()) { // DetectPivotPOIs( @@ -1436,12 +1436,13 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Analyse ... XPOIState mAnalyseState; - if (mAnalysePOIState.HasChild()) + if (useAnalyseState && + mAnalysePOIState.HasChild()) { // DetectPivotPOIs( mOrderFlow[pivotIDX], - mTriggerPOIState, + mAnalysePOIState, mAnalyseState, lookupSwingHighs, lookupSwingLows, @@ -1469,12 +1470,13 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Vision ... XPOIState mVisionState; - if (mVisionPOIState.HasChild()) + if (useVisionState && + mVisionPOIState.HasChild()) { // DetectPivotPOIs( mOrderFlow[pivotIDX], - mTriggerPOIState, + mVisionPOIState, mVisionState, lookupSwingHighs, lookupSwingLows, @@ -1630,7 +1632,30 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy bool drawOrderFlow = true, bool drawOrderFlowState = true, bool drawOnlyLastOrderFlow = false, - bool drawOnlyLastOrderFlowState = true // + bool drawOnlyLastOrderFlowState = true, + // + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + // + // Ignores List ... + bool ignoreSwingHighs = false, + bool ignoreSwingLows = false, + bool ignoreSupportZones = false, + bool ignoreResistanceZones = false, + bool ignoreSupplyZones = false, + bool ignoreDemandZones = false, + bool ignoreBullishOrderBlocks = false, + bool ignoreBearishOrderBlocks = false, + bool ignoreBullishFairValueGaps = false, + bool ignoreBearishFairValueGaps = false, + bool ignoreBullishRejectionBars = false, + bool ignoreBearishRejectionBars = false, + bool ignoreBullishMomentumBars = false, + bool ignoreBearishMomentumBars = false, + // + // States Drawing ... + bool drawVisionState = false, + bool drawAnalyseState = false, + bool drawTriggerState = false // ) { // @@ -1685,7 +1710,22 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // CustomStateDrawing( iPivot.state, - forceDrawSamePeriod // + forceDrawSamePeriod, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // ); } @@ -1713,6 +1753,84 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy AddObjectIfNotExists(iObj); } } + + // + // Vision ... + if (drawVisionState) + { + // + CustomStateDrawing( + mTriggerPOIState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Analyse ... + if (drawAnalyseState) + { + // + CustomStateDrawing( + mAnalysePOIState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Trigger ... + if (drawTriggerState) + { + // + CustomStateDrawing( + mVisionPOIState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } } /** @@ -1723,7 +1841,24 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy */ void CustomStateDrawing( XPOIState &state, - bool forceDrawSamePeriod = false // + bool forceDrawSamePeriod = false, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + // + // Ignores List ... + bool ignoreSwingHighs = false, + bool ignoreSwingLows = false, + bool ignoreSupportZones = false, + bool ignoreResistanceZones = false, + bool ignoreSupplyZones = false, + bool ignoreDemandZones = false, + bool ignoreBullishOrderBlocks = false, + bool ignoreBearishOrderBlocks = false, + bool ignoreBullishFairValueGaps = false, + bool ignoreBearishFairValueGaps = false, + bool ignoreBullishRejectionBars = false, + bool ignoreBearishRejectionBars = false, + bool ignoreBullishMomentumBars = false, + bool ignoreBearishMomentumBars = false // ) { // @@ -2185,25 +2320,172 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // } + // + bool drawSwingHighs = true; + bool drawSwingLows = true; + bool drawSupportZones = true; + bool drawResistanceZones = true; + bool drawSupplyZones = true; + bool drawDemandZones = true; + bool drawBullishOrderBlocks = true; + bool drawBearishOrderBlocks = true; + bool drawBullishFairValueGaps = true; + bool drawBearishFairValueGaps = true; + bool drawBullishRejectionBars = true; + bool drawBearishRejectionBars = true; + bool drawBullishMomentumBars = true; + bool drawBearishMomentumBars = true; + + // + // Change Drawing Specs Conditions based on + // Provided Direction ... + if (forDir == X_DIRECTION_BULLISH) + { + // + drawSwingLows = true; + drawDemandZones = true; + drawSupportZones = true; + drawBullishOrderBlocks = true; + drawBullishFairValueGaps = true; + drawBullishRejectionBars = true; + drawBullishMomentumBars = true; + + // + drawSwingHighs = false; + drawSupplyZones = false; + drawResistanceZones = false; + drawBearishOrderBlocks = false; + drawBearishFairValueGaps = false; + drawBearishRejectionBars = false; + drawBearishMomentumBars = false; + } + else if (forDir == X_DIRECTION_BEARISH) + { + // + drawSwingLows = false; + drawDemandZones = false; + drawSupportZones = false; + drawBullishOrderBlocks = false; + drawBullishFairValueGaps = false; + drawBullishRejectionBars = false; + drawBullishMomentumBars = false; + + // + drawSwingHighs = true; + drawSupplyZones = true; + drawResistanceZones = true; + drawBearishOrderBlocks = true; + drawBearishFairValueGaps = true; + drawBearishRejectionBars = true; + drawBearishMomentumBars = true; + } + + // + // Apply Ignore List ... + + // + if (ignoreSwingHighs) + { + drawSwingHighs = false; + } + + // + if (ignoreSwingLows) + { + drawSwingLows = false; + } + + // + if (ignoreSupportZones) + { + drawSupportZones = false; + } + + // + if (ignoreResistanceZones) + { + drawResistanceZones = false; + } + + // + if (ignoreSupplyZones) + { + drawSupplyZones = false; + } + + // + if (ignoreDemandZones) + { + drawDemandZones = false; + } + + // + if (ignoreBullishOrderBlocks) + { + drawBullishOrderBlocks = false; + } + + // + if (ignoreBearishOrderBlocks) + { + drawBearishOrderBlocks = false; + } + + // + if (ignoreBullishFairValueGaps) + { + drawBullishFairValueGaps = false; + } + + // + if (ignoreBearishFairValueGaps) + { + drawBearishFairValueGaps = false; + } + + // + if (ignoreBullishRejectionBars) + { + drawBullishRejectionBars = false; + } + + // + if (ignoreBearishRejectionBars) + { + drawBearishRejectionBars = false; + } + + // + if (ignoreBullishMomentumBars) + { + drawBullishMomentumBars = false; + } + + // + if (ignoreBearishMomentumBars) + { + drawBearishMomentumBars = false; + } + // DrawState( - tmpState, // State ... - true, // Update To of all Drawings Till now ... - true, // Draw SwingHighs .. - true, // Draw SwingLows .. - false, // Draw SupportZones .. - false, // Draw ResistanceZones .. - false, // Draw SupplyZones .. - false, // Draw DemandZones .. - false, // Draw BullishOrderBlocks .. - false, // Draw BearishOrderBlocks .. - false, // Draw BullishFairValueGaps .. - false, // Draw BearishFairValueGaps .. - true, // Draw BullishRejectionBars .. - true, // Draw BearishRejectionBars .. - true, // Draw BullishMomentumBars .. - true, // Draw BearishMomentumBars .. - true // Draw Ticks Zone ... + tmpState, // State ... + true, // Update To of all Drawings Till now ... + drawSwingHighs, // Draw SwingHighs .. + drawSwingLows, // Draw SwingLows .. + drawSupportZones, // Draw SupportZones .. + drawResistanceZones, // Draw ResistanceZones .. + drawSupplyZones, // Draw SupplyZones .. + drawDemandZones, // Draw DemandZones .. + drawBullishOrderBlocks, // Draw BullishOrderBlocks .. + drawBearishOrderBlocks, // Draw BearishOrderBlocks .. + drawBullishFairValueGaps, // Draw BullishFairValueGaps .. + drawBearishFairValueGaps, // Draw BearishFairValueGaps .. + drawBullishRejectionBars, // Draw BullishRejectionBars .. + drawBearishRejectionBars, // Draw BearishRejectionBars .. + drawBullishMomentumBars, // Draw BullishMomentumBars .. + drawBearishMomentumBars, // Draw BearishMomentumBars .. + true // Draw Ticks Zone ... ); }