diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 5a138486..ea635ad0 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -1601,6 +1601,67 @@ class XCBarAnalyser : public XCBase return result; } + /** + * Check Fibonacci Level 382 Pressure ... + * + * @param bar: XOHCL instance ... + * @param dir: ENUM_X_DIRECTION member ... + * + * @return ( bool ) + */ + bool HasFiboPressure( + XOHCL &bar, + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + double bearishFib382 = GetFibonacciLevel( + bar.high, + bar.low, + 0.382, + 1 // + ); + double bullishFib382 = GetFibonacciLevel( + bar.high, + bar.low, + 0.382, + -1 // + ); + + // + bool isBullish = bar.GetDown() > bearishFib382; + bool isBearish = bar.GetUp() < bullishFib382; + + // + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + // // Support and Resistance Zones ... diff --git a/Documents/BKP/tmp.x121.smc.mq5 b/Documents/BKP/tmp.x121.smc.mq5 index 637d3f23..ab72212b 100644 --- a/Documents/BKP/tmp.x121.smc.mq5 +++ b/Documents/BKP/tmp.x121.smc.mq5 @@ -1,74 +1,73 @@ +// +// Peaks ... +int peaksCount = ArraySize(conditions.peaks); +if (IsValidSize(peaksCount)) +{ + // + for (int i = 0; i < peaksCount; i++) + { + // + XPVPivot iPivot = conditions.peaks[i]; + // - // Peaks ... - int peaksCount = ArraySize(conditions.peaks); - if (IsValidSize(peaksCount)) - { - // - for (int i = 0; i < peaksCount; i++) - { - // - XPVPivot iPivot = conditions.peaks[i]; - - // - XCXPVPivotObject *iObj; - iObj = new XCXPVPivotObject(); - - // - bool isCreated = iObj.Create( - mPOIDrawer.ChartIdentification(), - mPOIDrawer.SubWindowIdentification(), - iPivot // - ); - if (isCreated) - { - // - iObj.PivotWidth(1); - iObj.PivotFill(false); - iObj.PivotColor(clrAqua); - iObj.PivotStyle(STYLE_SOLID); - - // - AddObjectIfNotExists(iObj); - } - } - } + XCXPVPivotObject *iObj; + iObj = new XCXPVPivotObject(); // - // Vales ... - int valesCount = ArraySize(conditions.vales); - if (IsValidSize(valesCount)) + bool isCreated = iObj.Create( + mPOIDrawer.ChartIdentification(), + mPOIDrawer.SubWindowIdentification(), + iPivot // + ); + if (isCreated) { // - for (int i = 0; i < valesCount; i++) - { - // - XPVPivot iPivot = conditions.vales[i]; + iObj.PivotWidth(1); + iObj.PivotFill(false); + iObj.PivotColor(clrAqua); + iObj.PivotStyle(STYLE_SOLID); - // - XCXPVPivotObject *iObj; - iObj = new XCXPVPivotObject(); - - // - bool isCreated = iObj.Create( - mPOIDrawer.ChartIdentification(), - mPOIDrawer.SubWindowIdentification(), - iPivot // - ); - if (isCreated) - { - // - iObj.PivotWidth(1); - iObj.PivotFill(false); - iObj.PivotStyle(STYLE_SOLID); - iObj.PivotColor(clrMagenta); - - // - AddObjectIfNotExists(iObj); - } - } + // + AddObjectIfNotExists(iObj); } + } +} +// +// Vales ... +int valesCount = ArraySize(conditions.vales); +if (IsValidSize(valesCount)) +{ + // + for (int i = 0; i < valesCount; i++) + { + // + XPVPivot iPivot = conditions.vales[i]; + + // + XCXPVPivotObject *iObj; + iObj = new XCXPVPivotObject(); + + // + bool isCreated = iObj.Create( + mPOIDrawer.ChartIdentification(), + mPOIDrawer.SubWindowIdentification(), + iPivot // + ); + if (isCreated) + { + // + iObj.PivotWidth(1); + iObj.PivotFill(false); + iObj.PivotStyle(STYLE_SOLID); + iObj.PivotColor(clrMagenta); + + // + AddObjectIfNotExists(iObj); + } + } +} /////////////////////////////////////////////////////////////////// // Conditions Parsing ... @@ -77,2905 +76,3285 @@ // // Conditions Props ... - // - // D1 ... +// +// D1 ... - // - XPOIState d1State; - ENUM_X_DIRECTION d1MarketDirection; - XCSupportZone *d1SupportZones[]; - XCResistanceZone *d1ResistanceZones[]; +// +XPOIState d1State; +ENUM_X_DIRECTION d1MarketDirection; +XCSupportZone *d1SupportZones[]; +XCResistanceZone *d1ResistanceZones[]; - // - XCSwing *d1SwingHigh; - XCSwing *d1SwingLow; +// +XCSwing *d1SwingHigh; +XCSwing *d1SwingLow; - // - // H4 ... +// +// H4 ... - // - XPOIState h4State; - ENUM_X_DIRECTION h4MarketDirection; - XCSupportZone *h4SupportZones[]; - XCResistanceZone *h4ResistanceZones[]; +// +XPOIState h4State; +ENUM_X_DIRECTION h4MarketDirection; +XCSupportZone *h4SupportZones[]; +XCResistanceZone *h4ResistanceZones[]; - // - XCSwing *h4SwingHigh; - XCSwing *h4SwingLow; +// +XCSwing *h4SwingHigh; +XCSwing *h4SwingLow; - // - // H2 ... +// +// H2 ... - // - XPOIState h2State; - ENUM_X_DIRECTION h2MarketDirection; - XCSupportZone *h2SupportZones[]; - XCResistanceZone *h2ResistanceZones[]; +// +XPOIState h2State; +ENUM_X_DIRECTION h2MarketDirection; +XCSupportZone *h2SupportZones[]; +XCResistanceZone *h2ResistanceZones[]; - // - XCSwing *h2SwingHigh; - XCSwing *h2SwingLow; +// +XCSwing *h2SwingHigh; +XCSwing *h2SwingLow; - // - // H1 ... +// +// H1 ... - // - XPOIState h1State; - ENUM_X_DIRECTION h1MarketDirection; - XCSupportZone *h1SupportZones[]; - XCResistanceZone *h1ResistanceZones[]; +// +XPOIState h1State; +ENUM_X_DIRECTION h1MarketDirection; +XCSupportZone *h1SupportZones[]; +XCResistanceZone *h1ResistanceZones[]; - // - XCSwing *h1SwingHigh; - XCSwing *h1SwingLow; +// +XCSwing *h1SwingHigh; +XCSwing *h1SwingLow; - // - // M15 ... +// +// M15 ... - // - XPOIState m15State; - ENUM_X_DIRECTION m15MarketDirection; - XCSupportZone *m15SupportZones[]; - XCResistanceZone *m15ResistanceZones[]; +// +XPOIState m15State; +ENUM_X_DIRECTION m15MarketDirection; +XCSupportZone *m15SupportZones[]; +XCResistanceZone *m15ResistanceZones[]; - // - XCSwing *m15SwingHigh; - XCSwing *m15SwingLow; +// +XCSwing *m15SwingHigh; +XCSwing *m15SwingLow; - // - // M5 ... +// +// M5 ... - // - XPOIState m5State; - ENUM_X_DIRECTION m5MarketDirection; - XCSupportZone *m5SupportZones[]; - XCResistanceZone *m5ResistanceZones[]; +// +XPOIState m5State; +ENUM_X_DIRECTION m5MarketDirection; +XCSupportZone *m5SupportZones[]; +XCResistanceZone *m5ResistanceZones[]; - // - XCSwing *m5SwingHigh; - XCSwing *m5SwingLow; +// +XCSwing *m5SwingHigh; +XCSwing *m5SwingLow; - // - // M1 ... - - // - XPOIState m1State; - ENUM_X_DIRECTION m1MarketDirection; - XCSupportZone *m1SupportZones[]; - XCResistanceZone *m1ResistanceZones[]; - - // - XCSwing *m1SwingHigh; - XCSwing *m1SwingLow; +// +// M1 ... +// +XPOIState m1State; +ENUM_X_DIRECTION m1MarketDirection; +XCSupportZone *m1SupportZones[]; +XCResistanceZone *m1ResistanceZones[]; +// +XCSwing *m1SwingHigh; +XCSwing *m1SwingLow; // // Clean Method ... - // - // D1 ... +// +// D1 ... - // - d1State.Clean(); - d1MarketDirection = X_DIRECTION_NONE; - Clean(d1SupportZones); - Clean(d1ResistanceZones); +// +d1State.Clean(); +d1MarketDirection = X_DIRECTION_NONE; +Clean(d1SupportZones); +Clean(d1ResistanceZones); - // - d1SwingHigh = NULL; - d1SwingLow = NULL; +// +d1SwingHigh = NULL; +d1SwingLow = NULL; - // - // H4 ... +// +// H4 ... - // - h4State.Clean(); - h4MarketDirection = X_DIRECTION_NONE; - Clean(h4SupportZones); - Clean(h4ResistanceZones); +// +h4State.Clean(); +h4MarketDirection = X_DIRECTION_NONE; +Clean(h4SupportZones); +Clean(h4ResistanceZones); - // - h4SwingHigh = NULL; - h4SwingLow = NULL; +// +h4SwingHigh = NULL; +h4SwingLow = NULL; - // - // H2 ... +// +// H2 ... - // - h2State.Clean(); - h2MarketDirection = X_DIRECTION_NONE; - Clean(h2SupportZones); - Clean(h2ResistanceZones); +// +h2State.Clean(); +h2MarketDirection = X_DIRECTION_NONE; +Clean(h2SupportZones); +Clean(h2ResistanceZones); - // - h2SwingHigh = NULL; - h2SwingLow = NULL; +// +h2SwingHigh = NULL; +h2SwingLow = NULL; - // - // H1 ... +// +// H1 ... - // - h1State.Clean(); - h1MarketDirection = X_DIRECTION_NONE; - Clean(h1SupportZones); - Clean(h1ResistanceZones); +// +h1State.Clean(); +h1MarketDirection = X_DIRECTION_NONE; +Clean(h1SupportZones); +Clean(h1ResistanceZones); - // - h1SwingHigh = NULL; - h1SwingLow = NULL; +// +h1SwingHigh = NULL; +h1SwingLow = NULL; - // - // M15 ... +// +// M15 ... - // - m15State.Clean(); - m15MarketDirection = X_DIRECTION_NONE; - Clean(m15SupportZones); - Clean(m15ResistanceZones); +// +m15State.Clean(); +m15MarketDirection = X_DIRECTION_NONE; +Clean(m15SupportZones); +Clean(m15ResistanceZones); - // - m15SwingHigh = NULL; - m15SwingLow = NULL; +// +m15SwingHigh = NULL; +m15SwingLow = NULL; - // - // M5 ... +// +// M5 ... - // - m5State.Clean(); - m5MarketDirection = X_DIRECTION_NONE; - Clean(m5SupportZones); - Clean(m5ResistanceZones); +// +m5State.Clean(); +m5MarketDirection = X_DIRECTION_NONE; +Clean(m5SupportZones); +Clean(m5ResistanceZones); - // - m5SwingHigh = NULL; - m5SwingLow = NULL; +// +m5SwingHigh = NULL; +m5SwingLow = NULL; - // - // M1 ... +// +// M1 ... - // - m1State.Clean(); - m1MarketDirection = X_DIRECTION_NONE; - Clean(m1SupportZones); - Clean(m1ResistanceZones); +// +m1State.Clean(); +m1MarketDirection = X_DIRECTION_NONE; +Clean(m1SupportZones); +Clean(m1ResistanceZones); - // - m1SwingHigh = NULL; - m1SwingLow = NULL; +// +m1SwingHigh = NULL; +m1SwingLow = NULL; // // Tools Functions ... // +// +// Custom Tools ... + +/** + * Check Conditions for Detect Market Structure ... + * + * @param structure: ENUM_X_DIRECTION member, Market Structure Direction reference ... + * + * @return ( bool ) + */ +bool HasMarketStructure( + ENUM_X_DIRECTION &structure // +) +{ + // + bool result = false; // - // Custom Tools ... + structure = X_DIRECTION_NONE; - /** - * Check Conditions for Detect Market Structure ... - * - * @param structure: ENUM_X_DIRECTION member, Market Structure Direction reference ... - * - * @return ( bool ) - */ - bool HasMarketStructure( - ENUM_X_DIRECTION &structure // - ) + // + result = IsValid(); + if (!result) { - // - bool result = false; - - // - structure = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - bool is1DBullish = IsBullish(d1MarketDirection); - bool is1DBearish = IsBearish(d1MarketDirection); - - // - bool is4HBullish = IsBullish(h4MarketDirection); - bool is4HBearish = IsBearish(h4MarketDirection); - - // - bool is2HBullish = IsBullish(h2MarketDirection); - bool is2HBearish = IsBearish(h2MarketDirection); - - // - bool is1HBullish = IsBullish(h1MarketDirection); - bool is1HBearish = IsBearish(h1MarketDirection); - - // - bool is15MBullish = IsBullish(m15MarketDirection); - bool is15MBearish = IsBearish(m15MarketDirection); - - // - bool is5MBullish = IsBullish(m5MarketDirection); - bool is5MBearish = IsBearish(m5MarketDirection); - - // - bool is1MBullish = IsBullish(m1MarketDirection); - bool is1MBearish = IsBearish(m1MarketDirection); - - // - bool isStructuresBullish = - // - is1HBullish && - is15MBullish && - is5MBullish - // - ; - - // - bool isStructuresBearish = - // - is1HBearish && - is15MBearish && - is5MBearish - // - ; - - // - bool hasMarketStructure = - isStructuresBullish || - isStructuresBearish; - result = hasMarketStructure; - if (!result) - { - return result; - } - - // - structure = - isStructuresBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // return result; } + // + bool is1DBullish = IsBullish(d1MarketDirection); + bool is1DBearish = IsBearish(d1MarketDirection); + + // + bool is4HBullish = IsBullish(h4MarketDirection); + bool is4HBearish = IsBearish(h4MarketDirection); + + // + bool is2HBullish = IsBullish(h2MarketDirection); + bool is2HBearish = IsBearish(h2MarketDirection); + + // + bool is1HBullish = IsBullish(h1MarketDirection); + bool is1HBearish = IsBearish(h1MarketDirection); + + // + bool is15MBullish = IsBullish(m15MarketDirection); + bool is15MBearish = IsBearish(m15MarketDirection); + + // + bool is5MBullish = IsBullish(m5MarketDirection); + bool is5MBearish = IsBearish(m5MarketDirection); + + // + bool is1MBullish = IsBullish(m1MarketDirection); + bool is1MBearish = IsBearish(m1MarketDirection); + + // + bool isStructuresBullish = + // + is1HBullish && + is15MBullish && + is5MBullish + // + ; + + // + bool isStructuresBearish = + // + is1HBearish && + is15MBearish && + is5MBearish + // + ; + + // + bool hasMarketStructure = + isStructuresBullish || + isStructuresBearish; + result = hasMarketStructure; + if (!result) + { + return result; + } + + // + structure = + isStructuresBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; +} + // // Strategy Class Calling on Conditions Detections ... - - // - // Detect Market Structures ... - - // - // 1D ... - conditions.d1State = _1DState; - result = DetectMarketStructure( - conditions.d1MarketDirection, - conditions.d1SupportZones, - conditions.d1ResistanceZones, - _1DState // - ); - if (!result) - { - return result; - } - - // - // 4H ... - conditions.h4State = _4HState; - result = DetectMarketStructure( - conditions.h4MarketDirection, - conditions.h4SupportZones, - conditions.h4ResistanceZones, - _4HState // - ); - if (!result) - { - return result; - } - - // - // 2H ... - conditions.h2State = _2HState; - result = DetectMarketStructure( - conditions.h2MarketDirection, - conditions.h2SupportZones, - conditions.h2ResistanceZones, - _2HState // - ); - if (!result) - { - return result; - } - - // - // 1H ... - conditions.h1State = _1HState; - result = DetectMarketStructure( - conditions.h1MarketDirection, - conditions.h1SupportZones, - conditions.h1ResistanceZones, - _1HState // - ); - if (!result) - { - return result; - } - - // - // 15M ... - conditions.m15State = _15MState; - result = DetectMarketStructure( - conditions.m15MarketDirection, - conditions.m15SupportZones, - conditions.m15ResistanceZones, - _15MState // - ); - if (!result) - { - return result; - } - - // - // 5M ... - conditions.m5State = _5MState; - result = DetectMarketStructure( - conditions.m5MarketDirection, - conditions.m5SupportZones, - conditions.m5ResistanceZones, - _5MState // - ); - if (!result) - { - return result; - } - - // - // 1M ... - conditions.m1State = _1MState; - result = DetectMarketStructure( - conditions.m1MarketDirection, - conditions.m1SupportZones, - conditions.m1ResistanceZones, - _1MState // - ); - if (!result) - { - return result; - } - - // - // 1H-15M-5M ... - ENUM_X_DIRECTION marketStructure = X_DIRECTION_NONE; - result = conditions.HasMarketStructure(marketStructure); - if (!result) - { - return result; - } - - // - // Detect Swing High and Swing Low ... - // 1H-15M-5M ... - int count = 0; - - // - // 1H ... - - // - XCSwing *h1SwingLows[]; - XCSwing *h1SwingHighs[]; - XCSupportZone *h1SupportZone = NULL; - XCResistanceZone *h1ResistanceZone = NULL; - - // - count = ArraySize(conditions.h1SupportZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone *item = conditions.h1SupportZones[i]; - - // - bool canSelect = - h1SupportZone == NULL || - h1SupportZone.Lower() < item.Lower(); - if (canSelect) - { - h1SupportZone = item; - } - } - } - if (h1SupportZone != NULL) - { - // - // Detect Swings ... - count = ArraySize(conditions.h1State.swingLows); - if (IsValidSize(count)) - { - // - double upper = h1SupportZone.Upper(); - double lower = h1SupportZone.Lower(); - - // - for (int i = 0; i < count; i++) - { - // - XCSwing *item = conditions.h1State.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = item.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool canSelect = (iBar.high <= upper && - iBar.low >= lower) || - (iBar.high >= upper && - iBar.low <= lower); - if (canSelect) - { - // - Add( - item, - h1SwingLows // - ); - - // - // Draw ... - XCSwingLowObject *iObj; - bool isCreated = mPOIDrawer.CreateSwingLow( - item, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - } - } - - // - // Draw ... - XCSupportZoneObject *iObj; - bool isCreated = mPOIDrawer.CreateSupportZone( - h1SupportZone, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - - // - count = ArraySize(conditions.h1ResistanceZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *item = conditions.h1ResistanceZones[i]; - - // - bool canSelect = - h1ResistanceZone == NULL || - h1ResistanceZone.Upper() > item.Upper(); - if (canSelect) - { - h1ResistanceZone = item; - } - } - } - if (h1ResistanceZone != NULL) - { - // - // Detect Swings ... - count = ArraySize(conditions.h1State.swingHighs); - if (IsValidSize(count)) - { - // - double upper = h1ResistanceZone.Upper(); - double lower = h1ResistanceZone.Lower(); - - // - for (int i = 0; i < count; i++) - { - // - XCSwing *item = conditions.h1State.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = item.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool canSelect = (iBar.high <= upper && - iBar.low >= lower) || - (iBar.high >= upper && - iBar.low <= lower); - if (canSelect) - { - // - Add( - item, - h1SwingHighs // - ); - - // - // Draw ... - XCSwingHighObject *iObj; - bool isCreated = mPOIDrawer.CreateSwingHigh( - item, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - } - } - - // - // Draw ... - XCResistanceZoneObject *iObj; - bool isCreated = mPOIDrawer.CreateResistanceZone( - h1ResistanceZone, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - - // - // 15M ... - - // - XCSupportZone *m15SupportZone = NULL; - count = ArraySize(conditions.m15SupportZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone *item = conditions.m15SupportZones[i]; - - // - bool canSelect = - m15SupportZone == NULL || - m15SupportZone.Lower() < item.Lower(); - if (canSelect) - { - m15SupportZone = item; - } - } - } - if (m15SupportZone != NULL) - { - // - XCSupportZoneObject *iObj; - bool isCreated = mPOIDrawer.CreateSupportZone( - m15SupportZone, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - - // - XCResistanceZone *m15ResistanceZone = NULL; - count = ArraySize(conditions.m15ResistanceZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *item = conditions.m15ResistanceZones[i]; - - // - bool canSelect = - m15ResistanceZone == NULL || - m15ResistanceZone.Upper() > item.Upper(); - if (canSelect) - { - m15ResistanceZone = item; - } - } - } - if (m15ResistanceZone != NULL) - { - // - XCResistanceZoneObject *iObj; - bool isCreated = mPOIDrawer.CreateResistanceZone( - m15ResistanceZone, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - - // - // 5M ... - - // - XCSupportZone *m5SupportZone = NULL; - count = ArraySize(conditions.m5SupportZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone *item = conditions.m5SupportZones[i]; - - // - bool canSelect = - m5SupportZone == NULL || - m5SupportZone.Lower() < item.Lower(); - if (canSelect) - { - m5SupportZone = item; - } - } - } - if (m5SupportZone != NULL) - { - // - XCSupportZoneObject *iObj; - bool isCreated = mPOIDrawer.CreateSupportZone( - m5SupportZone, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - - // - XCResistanceZone *m5ResistanceZone = NULL; - count = ArraySize(conditions.m5ResistanceZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *item = conditions.m5ResistanceZones[i]; - - // - bool canSelect = - m5ResistanceZone == NULL || - m5ResistanceZone.Upper() > item.Upper(); - if (canSelect) - { - m5ResistanceZone = item; - } - } - } - if (m5ResistanceZone != NULL) - { - // - XCResistanceZoneObject *iObj; - bool isCreated = mPOIDrawer.CreateResistanceZone( - m5ResistanceZone, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - - // - // DrawState(_5MState); - +// +// Detect Market Structures ... // +// 1D ... +conditions.d1State = _1DState; +result = DetectMarketStructure( + conditions.d1MarketDirection, + conditions.d1SupportZones, + conditions.d1ResistanceZones, + _1DState // +); +if (!result) +{ + return result; +} + // -// Strategy Class Tools Functions ... +// 4H ... +conditions.h4State = _4HState; +result = DetectMarketStructure( + conditions.h4MarketDirection, + conditions.h4SupportZones, + conditions.h4ResistanceZones, + _4HState // +); +if (!result) +{ + return result; +} +// +// 2H ... +conditions.h2State = _2HState; +result = DetectMarketStructure( + conditions.h2MarketDirection, + conditions.h2SupportZones, + conditions.h2ResistanceZones, + _2HState // +); +if (!result) +{ + return result; +} - /** - * Detect Specified States Market Structure ... - * - * @param dir: ENUM_X_DIRECTION member, Refrence ... - * @param state: XPOIState instance ... - * - * @return ( bool ) - */ - bool DetectMarketStructure( - ENUM_X_DIRECTION &dir, - XCSupportZone *&supportZones[], - XCResistanceZone *&resistanceZones[], - XPOIState &state // - ) +// +// 1H ... +conditions.h1State = _1HState; +result = DetectMarketStructure( + conditions.h1MarketDirection, + conditions.h1SupportZones, + conditions.h1ResistanceZones, + _1HState // +); +if (!result) +{ + return result; +} + +// +// 15M ... +conditions.m15State = _15MState; +result = DetectMarketStructure( + conditions.m15MarketDirection, + conditions.m15SupportZones, + conditions.m15ResistanceZones, + _15MState // +); +if (!result) +{ + return result; +} + +// +// 5M ... +conditions.m5State = _5MState; +result = DetectMarketStructure( + conditions.m5MarketDirection, + conditions.m5SupportZones, + conditions.m5ResistanceZones, + _5MState // +); +if (!result) +{ + return result; +} + +// +// 1M ... +conditions.m1State = _1MState; +result = DetectMarketStructure( + conditions.m1MarketDirection, + conditions.m1SupportZones, + conditions.m1ResistanceZones, + _1MState // +); +if (!result) +{ + return result; +} + +// +// 1H-15M-5M ... +ENUM_X_DIRECTION marketStructure = X_DIRECTION_NONE; +result = conditions.HasMarketStructure(marketStructure); +if (!result) +{ + return result; +} + +// +// Detect Swing High and Swing Low ... +// 1H-15M-5M ... +int count = 0; + +// +// 1H ... + +// +XCSwing *h1SwingLows[]; +XCSwing *h1SwingHighs[]; +XCSupportZone *h1SupportZone = NULL; +XCResistanceZone *h1ResistanceZone = NULL; + +// +count = ArraySize(conditions.h1SupportZones); +if (IsValidSize(count)) +{ + // + for (int i = 0; i < count; i++) { // - bool result = false; + XCSupportZone *item = conditions.h1SupportZones[i]; // - int count = 0; - - // - // Filter Untouched Supports ... - Clean(supportZones); - int untouchedSupportsCount = 0; - count = ArraySize(state.supportZones); - if (IsValidSize(count)) + bool canSelect = + h1SupportZone == NULL || + h1SupportZone.Lower() < item.Lower(); + if (canSelect) { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone *item = state.supportZones[i]; - - // - // Find Breakout Bar - XOHCL iBar; - bool isFilled = item.FillBar(iBar); - if (!isFilled) - { - break; - } - - // - int iBarIndex = iBar.Index(); - int iBarUnTouchedCount = 0; - for (int j = 0; j < iBarIndex; j++) - { - // - XOHCL jBar; - bool isInited = jBar.Init( - iBar.symbol, - iBar.period, - j // - ); - if (!isInited) - { - break; - } - - // - bool isUntouched = - jBar.low > item.Upper(); - if (isUntouched) - { - iBarUnTouchedCount++; - } - else - { - iBarUnTouchedCount--; - } - } - - // - if (iBarUnTouchedCount > 0) - { - // - Add( - item, - supportZones // - ); - } - } - - // - untouchedSupportsCount = ArraySize(supportZones); - if (IsValidSize(untouchedSupportsCount)) - { - // - // Draw ... - // for (int i = 0; i < untouchedSupportsCount; i++) - // { - // // - // XCSupportZone *item = supportZones[i]; - - // // - // XCSupportZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateSupportZone( - // item, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - } + h1SupportZone = item; } - - // - // Filter Untouched Resistances ... - Clean(resistanceZones); - int untouchedResistancesCount = 0; - count = ArraySize(state.resistanceZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *item = state.resistanceZones[i]; - - // - // Find Breakout Bar - XOHCL iBar; - bool isFilled = item.FillBar(iBar); - if (!isFilled) - { - break; - } - - // - int iBarIndex = iBar.Index(); - int iBarUnTouchedCount = 0; - for (int j = 0; j < iBarIndex; j++) - { - // - XOHCL jBar; - bool isInited = jBar.Init( - iBar.symbol, - iBar.period, - j // - ); - if (!isInited) - { - break; - } - - // - bool isUntouched = - jBar.high < item.Lower(); - if (isUntouched) - { - iBarUnTouchedCount++; - } - else - { - iBarUnTouchedCount--; - } - } - - // - if (iBarUnTouchedCount > 0) - { - // - Add( - item, - resistanceZones // - ); - } - } - - // - untouchedResistancesCount = ArraySize(resistanceZones); - if (IsValidSize(untouchedResistancesCount)) - { - // - // Draw ... - // for (int i = 0; i < untouchedResistancesCount; i++) - // { - // // - // XCResistanceZone *item = resistanceZones[i]; - - // // - // XCResistanceZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateResistanceZone( - // item, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - } - } - - // - bool hasBullishStructure = - IsValidSize(untouchedSupportsCount) && - untouchedSupportsCount > untouchedResistancesCount; - bool hasBearishStructure = - IsValidSize(untouchedResistancesCount) && - untouchedResistancesCount > untouchedSupportsCount; - - // - result = (hasBullishStructure && - !hasBearishStructure) || - (hasBearishStructure && - !hasBullishStructure); - - // - if (result) - { - // - dir = - hasBullishStructure - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; } - - -//////////////////////////////////////////////////////////////////////////// - - - - // - // Detect Order Blocks ... - // int obsCount = 0; - - // - // Find Bullish Order Block ... - // XCOrderBlock *bullishOB = NULL; - // XCRejectionBar *bullishOBRejectionBar = NULL; - // obsCount = lastPivot.state.CountBullishOrderBlocks(); - // if (IsValidSize(obsCount)) - // { - // // - // for (int i = 0; i < obsCount; i++) - // { - // // - // XCOrderBlock *iOB = lastPivot.state.bullishOrderBlocks[i]; - - // // - // XOHCL iBar; - // bool hasBar = iOB.FillBar(iBar); - // bool isPeriodSame = hasBar && - // iBar.period == _period; - - // // - // if (iOB.Upper() <= pivotMid && - // iOB.Lower() >= lastPivot.lower) - // { - // // - // bullishOB = iOB; - // break; - // } - // } - // } - // bool hasBullishOB = bullishOB != NULL; - // bool isBullishOBRejected = false; - // if (hasBullishOB) - // { - // // - // int bullishRejectedBarsCount = lastPivot.state.CountBullishRejectionBars(); - // if (IsValidSize(bullishRejectedBarsCount)) - // { - // // - // for (int i = 0; i < bullishRejectedBarsCount; i++) - // { - // // - // XCRejectionBar *item = lastPivot.state.bullishRejectionBars[i]; - - // // - // XOHCL iBar; - // bool isFilled = item.FillBar(iBar); - // if (!isFilled) - // { - // continue; - // } - - // // - // bool isRejected = iBar.low <= bullishOB.Lower() && - // (iBar.GetDown() <= bullishOB.Upper() || - // iBar.GetDown() > bullishOB.Upper()); - - // // - // isBullishOBRejected = - // bullishOBRejectionBar == NULL - // ? isRejected - // : isRejected && - // item.From() > bullishOBRejectionBar.From(); - // if (isBullishOBRejected) - // { - // bullishOBRejectionBar = item; - // } - // } - // } - // if (isBullishOBRejected) - // { - // // - // bullishOBRejectionBar.To(cTime); - // XCBullishRejectionBarObject *iObj; - // bool isCreated = mPOIDrawer.CreateBullishRejectionBar( - // bullishOBRejectionBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // // - // bullishOB.To(cTime); - // XCBullishOrderBlockObject *iObj; - // bool isCreated = mPOIDrawer.CreateBullishOrderBlock( - // bullishOB, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // - // Find Bearish Order Block ... - // XCOrderBlock *bearishOB = NULL; - // XCRejectionBar *bearishOBRejectionBar = NULL; - // obsCount = lastPivot.state.CountBearishOrderBlocks(); - // if (IsValidSize(obsCount)) - // { - // // - // for (int i = 0; i < obsCount; i++) - // { - // // - // XCOrderBlock *iOB = lastPivot.state.bearishOrderBlocks[i]; - - // // - // XOHCL iBar; - // bool hasBar = iOB.FillBar(iBar); - // bool isPeriodSame = hasBar && - // iBar.period == _period; - - // // - // if (iOB.Lower() >= pivotMid && - // iOB.Upper() <= lastPivot.upper) - // { - // // - // bearishOB = iOB; - // break; - // } - // } - // } - // bool hasBearishOB = bearishOB != NULL; - // bool isBearishOBRejected = false; - // if (hasBearishOB) - // { - // // - // int bearishRejectedBarsCount = lastPivot.state.CountBearishRejectionBars(); - // if (IsValidSize(bearishRejectedBarsCount)) - // { - // // - // for (int i = 0; i < bearishRejectedBarsCount; i++) - // { - // // - // XCRejectionBar *item = lastPivot.state.bearishRejectionBars[i]; - - // // - // XOHCL iBar; - // bool isFilled = item.FillBar(iBar); - // if (!isFilled) - // { - // continue; - // } - - // // - // bool isRejected = iBar.high >= bearishOB.Upper() && - // (iBar.GetUp() <= bearishOB.Lower() || - // iBar.GetUp() > bearishOB.Lower()); - - // // - // isBearishOBRejected = - // bearishOBRejectionBar == NULL - // ? isRejected - // : isRejected && - // item.From() > bearishOBRejectionBar.From(); - // if (isBearishOBRejected) - // { - // bearishOBRejectionBar = item; - // } - // } - // } - // if (isBearishOBRejected) - // { - // // - // bearishOBRejectionBar.To(cTime); - // XCBearishRejectionBarObject *iObj; - // bool isCreated = mPOIDrawer.CreateBearishRejectionBar( - // bearishOBRejectionBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // // - // bearishOB.To(cTime); - // XCBearishOrderBlockObject *iObj; - // bool isCreated = mPOIDrawer.CreateBearishOrderBlock( - // bearishOB, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // // - // // Find an Order Block ... - // bool isBearishOrderBlockRejected = false; - - -///////////////////////////////////////////////////////////////////////////// - - - - // - RedrawOrderFlow(); - - // - // Check Candlestick PullBacks ... - ENUM_X_DIRECTION pullBackDir; - bool hasPullBack = mBarAnalyser.HasPullBack( - pullBackDir, - cBar, - 3, // Loopback ... - true // Force Body ... - ); - bool hasBullishPullback = - hasPullBack && - pullBackDir == X_DIRECTION_BULLISH; - bool hasBearishPullback = - hasPullBack && - pullBackDir == X_DIRECTION_BEARISH; - - - - // - bool isInDiscount = - bid < pivotMid && - bid > lastPivot.lower; - - // - bool isInPremium = - bid > pivotMid && - bid < lastPivot.upper; - - // - // Check Order Flow Validation ... - - // - // For Bullish Order Flow ... - // if Price Breakes Lower to Down, means Change of Charcter Happens ... - bool isCHOCHHappens = - isBullishOrderFlow ? bid < lastPivot.lower - pip - : bid > lastPivot.upper + pip; - - // - // For Bullish Order Flow ... - // if Price Breakes Upper to Up, means Breake of Structure Happens ... - bool isBOSHappens = - isBullishOrderFlow ? bid > lastPivot.upper + pip - : bid < lastPivot.lower - pip; - - // - if (isBOSHappens) - { - // - // RedrawOrderFlow(); - Print(""); - } - - // - if (isCHOCHHappens) - { - // - result = false; - ResetOrderFlow(); - return result; - } - - - - // - // Check 3MA and 3VWAP State ... - - // - bool isVWAPBullishOrdered = - // - ( - // - (conditions.x3vwapConditions.isBullishOrdered || - conditions.x3vwapConditions.isSwitchedToBullishOrdered) - // - || - // - conditions.x3vwapConditions.fasts[cIndex] > conditions.x3vwapConditions.mids[cIndex] - // - || - // - conditions.x3vwapConditions.mids[cIndex] > conditions.x3vwapConditions.slows[cIndex] - // - ) - // - ; - - // - bool isVWAPBearishOrdered = - // - ( - // - (conditions.x3vwapConditions.isBearishOrdered || - conditions.x3vwapConditions.isSwitchedToBearishOrdered) - // - || - // - conditions.x3vwapConditions.fasts[cIndex] < conditions.x3vwapConditions.mids[cIndex] - // - || - // - conditions.x3vwapConditions.mids[cIndex] < conditions.x3vwapConditions.slows[cIndex] - // - ) - // - ; - - // - bool isVWapBullishState = - // - ( - // - (conditions.x3vwapConditions.isBullishState || - conditions.x3vwapConditions.isSwitchedToBullishState) - // - || - // - (x3vwapHelper.IsBullish(conditions.x3vwapConditions.fastStates[cIndex]) && - x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex])) - // - || - // - (x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex]) && - x3vwapHelper.IsBullish(conditions.x3vwapConditions.slowStates[cIndex])) - // - ) - // - ; - - // - bool isVWapBearishState = - // - ( - // - (conditions.x3vwapConditions.isBearishState || - conditions.x3vwapConditions.isSwitchedToBearishState) - // - || - // - (x3vwapHelper.IsBearish(conditions.x3vwapConditions.fastStates[cIndex]) && - x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex])) - // - || - // - (x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex]) && - x3vwapHelper.IsBearish(conditions.x3vwapConditions.slowStates[cIndex])) - // - ) - // - ; - - // - bool isVWapOverFastMA = - // - ( - // - (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex]) - // - || - // - (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.slows[cIndex] > conditions.x3maConditions.fasts[cIndex]) - // - ) - // - ; - - // - bool isVWapUnderFastMA = - // - ( - // - (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex]) - // - || - // - (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.slows[cIndex] < conditions.x3maConditions.fasts[cIndex]) - // - ) - // - ; - - // - bool is3Bullish = - // - ( - // - (isVWAPBullishOrdered && - isVWapBullishState) - // - || - // - (isVWAPBullishOrdered && - isVWapOverFastMA) - // - || - // - (isVWapBullishState && - isVWapOverFastMA) - // - ) - // - ; - - // - bool is3Bearish = - // - ( - // - (isVWAPBearishOrdered && - isVWapBearishState) - // - || - // - (isVWAPBearishOrdered && - isVWapUnderFastMA) - // - || - // - (isVWapBearishState && - isVWapUnderFastMA) - // - ) - // - ; - - // - // Check Parabolic Sars State ... - - // - bool isSarBullish = - // - (conditions.xchsarConditions.isCBullish && - conditions.xchsarConditions.isSSwitchedBullish) - // - || - // - (conditions.xchsarConditions.isSBullish && - conditions.xchsarConditions.isCSwitchedBullish) - // - ; - bool isSarBearish = - // - (conditions.xchsarConditions.isCBearish && - conditions.xchsarConditions.isSSwitchedBearish) - // - || - // - (conditions.xchsarConditions.isSBearish && - conditions.xchsarConditions.isCSwitchedBearish) - // - ; - - - - // // - // hasLong = - // // - // is3Bullish && - // // isInDiscount && - // isSarBullish // && - // // hasBullishPullback && - // // bullishLiquidityPercent > 30 - // // - // ; - - // // - // hasShort = - // // - // is3Bearish && - // // isInPremium && - // isSarBearish // && - // // hasBearishPullback && - // // bearishLiquidityPercent > 30 - // // - // ; - - - - -////////////////////// - - // - XPVPivot lastPivot; - result = GetLastItem( - lastPivot, - mOrderFlow // - ); - if (!result) - { - return result; - } - bool isBullishOrderFlow = IsBullish(mOrderFlowDir); - bool isBearishOrderFlow = IsBearish(mOrderFlowDir); - double pivotMid = lastPivot.CalculateMid(); - - // - // Calculate Liquidity Percent ... - double bullishLiquidityPercent = lastPivot - .CalculateLiquidityPercent(X_DIRECTION_BULLISH); - double bearishLiquidityPercent = lastPivot - .CalculateLiquidityPercent(X_DIRECTION_BEARISH); - double minLiquidityPercent = 35; - bool hasBullishLiquidity = bullishLiquidityPercent >= minLiquidityPercent; - bool hasBearishLiquidity = bearishLiquidityPercent >= minLiquidityPercent; - result = hasBullishLiquidity || - hasBearishLiquidity; - if (!result) - { - return result; - } - - -///////////////////////////////////////////////////////////////// - - // // - // // 1D Period ... - // // POI Detector ... - // m1DPOI = new XCPOIDetector( - // symbol, - // PERIOD_D1 // - // ); - - // // - // m1DPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m1DPOI.Init(); - - // // - // // 4H Period ... - // // POI Detector ... - // m4HPOI = new XCPOIDetector( - // symbol, - // PERIOD_H4 // - // ); - - // // - // m4HPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m4HPOI.Init(); - - // // - // // 2H Period ... - // // POI Detector ... - // m2HPOI = new XCPOIDetector( - // symbol, - // PERIOD_H2 // - // ); - - // // - // m2HPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m2HPOI.Init(); - - // - // 1H Period ... - // POI Detector ... - // m1HPOI = new XCPOIDetector( - // symbol, - // PERIOD_H1 // - // ); - - // // - // m1HPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m1HPOI.Init(); - - // - // 15M Period ... - // POI Detector ... - // m15MPOI = new XCPOIDetector( - // symbol, - // PERIOD_M15 // - // ); - - // // - // m15MPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m15MPOI.Init(); - - // // - // // 5M Period ... - // // POI Detector ... - // m5MPOI = new XCPOIDetector( - // symbol, - // PERIOD_M5 // - // ); - - // // - // m5MPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m5MPOI.Init(); - - // // - // // 1M Period ... - // // POI Detector ... - // m1MPOI = new XCPOIDetector( - // symbol, - // PERIOD_M1 // - // ); - - // // - // m1MPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // // - // m1MPOI.Init(); - - -//////////////////////////////// - - // delete m1DPOI; - // delete m4HPOI; - // delete m2HPOI; - delete m1HPOI; - delete m15MPOI; - // delete m5MPOI; - // delete m1MPOI; - - -/////////////////////////////////// - - +} +if (h1SupportZone != NULL) +{ // - // Point Of Interests ... - XCPOIDetector *mTriggerPOIDetector; - XCPOIDetector *mAnalysePOIDetector; - XCPOIDetector *mVisionPOIDetector; - - // - // XCPOIDetector *m1DPOI; - // XCPOIDetector *m4HPOI; - // XCPOIDetector *m2HPOI; - // XCPOIDetector *m1HPOI; - // XCPOIDetector *m15MPOI; - // XCPOIDetector *m5MPOI; - // XCPOIDetector *m1MPOI; - - // - XPOIState mTriggerPOIState; - XPOIState mAnalysePOIState; - XPOIState mVisionPOIState; - - // XPOIState _1DState; - // XPOIState _4HState; - // XPOIState _2HState; - // XPOIState _1HState; - // XPOIState _15MState; - // XPOIState _5MState; - // XPOIState _1MState; - // XPOIState _CombineState; - - - -/////////////////////////////////////////// - - // - // Update POIs ... - - // - ENUM_XPOI_EVENTS _events[]; - mPOIDetector.Update(_events); - - // // - // ENUM_XPOI_EVENTS _1DStates[]; - // m1DPOI.Update(_1DStates); - - // // - // ENUM_XPOI_EVENTS _4HStates[]; - // m4HPOI.Update(_4HStates); - - // // - // ENUM_XPOI_EVENTS _2HStates[]; - // m2HPOI.Update(_2HStates); - - // - ENUM_XPOI_EVENTS _1HStates[]; - m1HPOI.Update(_1HStates); - - // // - // ENUM_XPOI_EVENTS _15MStates[]; - // m15MPOI.Update(_15MStates); - - // // - // ENUM_XPOI_EVENTS _5MStates[]; - // m5MPOI.Update(_5MStates); - - // // - // ENUM_XPOI_EVENTS _1MStates[]; - // m1MPOI.Update(_1MStates); - - // // - // // Read all POI States ... - mPOIDetector.GetState(_state); - // m1DPOI.GetState(_1DState); - // m4HPOI.GetState(_4HState); - // m2HPOI.GetState(_2HState); - m1HPOI.GetState(_1HState); - // m15MPOI.GetState(_15MState); - // m5MPOI.GetState(_5MState); - // m1MPOI.GetState(_1MState); - - // - // Combine States ... - // XPOIState _States[]; - // AddRef( - // _1DState, - // _States // - // ); - // AddRef( - // _4HState, - // _States // - // ); - // AddRef( - // _2HState, - // _States // - // ); - // AddRef( - // _1HState, - // _States // - // ); - // AddRef( - // _15MState, - // _States // - // ); - // AddRef( - // _5MState, - // _States // - // ); - // AddRef( - // _1MState, - // _States // - // ); - // CombineStates( - // _CombineState, - // _States // - // ); - - -//////////////////////////////////////////////////////////////// - - // - // Works by WVAP and PSar ... - bool long1 = - // - conditions.x3vwapConditions.isBullishState && - conditions.x3vwapConditions.isBullishOrdered && - // conditions.xpvConditions.vales[cIndex] == conditions.xchsarConditions.cSars[cIndex] && - conditions.xchsarConditions.cSars[cIndex] < conditions.x3vwapConditions.slows[cIndex] - // - ; - if (long1) - { - // - CustomStateDrawing(_1HState); - selectedSL = conditions.xpvConditions.vales[cIndex]; - } - - // - // Works by WVAP and PSar ... - bool short1 = - // - conditions.x3vwapConditions.isBearishState && - conditions.x3vwapConditions.isBearishOrdered && - // conditions.xpvConditions.peaks[cIndex] == conditions.xchsarConditions.cSars[cIndex] && - conditions.xchsarConditions.cSars[cIndex] > conditions.x3vwapConditions.slows[cIndex] - // - ; - if (short1) - { - // - CustomStateDrawing(_1HState); - selectedSL = conditions.xpvConditions.peaks[cIndex]; - } - - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - // mOrderFlow[pivotIDX].state.ticksZone = - //_15MState.ticksZone; - - // // - // // D1 ... - // XPOIState d1; - // if (_1DState.HasChild()) - // { - // // - // DetectPivotPOIs( - // mOrderFlow[pivotIDX], - // _1DState, - // d1, - // lookupSwingHighs, - // lookupSwingLows, - // lookupSupportZones, - // lookupResistanceZones, - // lookupSupplyZones, - // lookupDemandZones, - // lookupBullishOrderBlocks, - // lookupBearishOrderBlocks, - // lookupBullishFairValueGaps, - // lookupBearishFairValueGaps, - // lookupBullishRejectionBars, - // lookupBearishRejectionBars, - // lookupBullishMomentumBars, - // lookupBearishMomentumBars // - // ); - - // // - // if (d1.HasChild()) - // { - // d1.Fill(mOrderFlow[pivotIDX].state); - // } - // } - - // // - // // H4 ... - // XPOIState h4; - // if (_4HState.HasChild()) - // { - // // - // DetectPivotPOIs( - // mOrderFlow[pivotIDX], - // _4HState, - // h4, - // lookupSwingHighs, - // lookupSwingLows, - // lookupSupportZones, - // lookupResistanceZones, - // lookupSupplyZones, - // lookupDemandZones, - // lookupBullishOrderBlocks, - // lookupBearishOrderBlocks, - // lookupBullishFairValueGaps, - // lookupBearishFairValueGaps, - // lookupBullishRejectionBars, - // lookupBearishRejectionBars, - // lookupBullishMomentumBars, - // lookupBearishMomentumBars // - // ); - - // // - // if (h4.HasChild()) - // { - // h4.Fill(mOrderFlow[pivotIDX].state); - // } - // } - - // - // H2 ... - // XPOIState h2; - // if (_2HState.HasChild()) - // { - // // - // DetectPivotPOIs( - // mOrderFlow[pivotIDX], - // _2HState, - // h2, - // lookupSwingHighs, - // lookupSwingLows, - // lookupSupportZones, - // lookupResistanceZones, - // lookupSupplyZones, - // lookupDemandZones, - // lookupBullishOrderBlocks, - // lookupBearishOrderBlocks, - // lookupBullishFairValueGaps, - // lookupBearishFairValueGaps, - // lookupBullishRejectionBars, - // lookupBearishRejectionBars, - // lookupBullishMomentumBars, - // lookupBearishMomentumBars // - // ); - - // // - // if (h2.HasChild()) - // { - // h2.Fill(mOrderFlow[pivotIDX].state); - // } - // } - - // - // H1 ... - XPOIState h1; - if (_1HState.HasChild()) - { - // - DetectPivotPOIs( - mOrderFlow[pivotIDX], - _1HState, - h1, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (h1.HasChild()) - { - h1.Fill(mOrderFlow[pivotIDX].state); - } - } - - // - // M15 ... - // XPOIState m15; - // if (_15MState.HasChild()) - // { - // // - // DetectPivotPOIs( - // mOrderFlow[pivotIDX], - // _15MState, - // m15, - // lookupSwingHighs, - // lookupSwingLows, - // lookupSupportZones, - // lookupResistanceZones, - // lookupSupplyZones, - // lookupDemandZones, - // lookupBullishOrderBlocks, - // lookupBearishOrderBlocks, - // lookupBullishFairValueGaps, - // lookupBearishFairValueGaps, - // lookupBullishRejectionBars, - // lookupBearishRejectionBars, - // lookupBullishMomentumBars, - // lookupBearishMomentumBars // - // ); - - // // - // if (m15.HasChild()) - // { - // m15.Fill(mOrderFlow[pivotIDX].state); - // } - // } - - // - // M5 ... - // XPOIState m5; - // if (_5MState.HasChild()) - // { - // // - // DetectPivotPOIs( - // mOrderFlow[pivotIDX], - // _5MState, - // m5, - // lookupSwingHighs, - // lookupSwingLows, - // lookupSupportZones, - // lookupResistanceZones, - // lookupSupplyZones, - // lookupDemandZones, - // lookupBullishOrderBlocks, - // lookupBearishOrderBlocks, - // lookupBullishFairValueGaps, - // lookupBearishFairValueGaps, - // lookupBullishRejectionBars, - // lookupBearishRejectionBars, - // lookupBullishMomentumBars, - // lookupBearishMomentumBars // - // ); - - // // - // if (m5.HasChild()) - // { - // m5.Fill(mOrderFlow[pivotIDX].state); - // } - // } - - // - // M1 ... - // XPOIState m1; - // if (_1MState.HasChild()) - // { - // // - // DetectPivotPOIs( - // mOrderFlow[pivotIDX], - // _1MState, - // m1, - // lookupSwingHighs, - // lookupSwingLows, - // lookupSupportZones, - // lookupResistanceZones, - // lookupSupplyZones, - // lookupDemandZones, - // lookupBullishOrderBlocks, - // lookupBearishOrderBlocks, - // lookupBullishFairValueGaps, - // lookupBearishFairValueGaps, - // lookupBullishRejectionBars, - // lookupBearishRejectionBars, - // lookupBullishMomentumBars, - // lookupBearishMomentumBars // - // ); - - // // - // if (m1.HasChild()) - // { - // 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 + // Detect Swings ... + count = ArraySize(conditions.h1State.swingLows); + if (IsValidSize(count)) { // - Clean(result); + double upper = h1SupportZone.Upper(); + double lower = h1SupportZone.Lower(); // - int cIndex = 1; - - // - if (entry <= 0 || - !conditions.IsValid() || - type == X_POSITION_TYPE_ALL || - type == X_POSITION_TYPE_NONE) + for (int i = 0; i < count; i++) { - return; - } + // + XCSwing *item = conditions.h1State.swingLows[i]; - // - 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 // - ); - - // - } - - -//////////////////////////////////////// - - - bool canContinue = true; - while (canContinue) - { // XOHCL iBar; - bool isBarInited = iBar.Init( - mBar.symbol, - mBar.period, - barIndex // - ); - if (!isBarInited) - { - break; - } - - // - if (bullOB == NULL) - { - // - XCOrderBlock *ob; - bool isBullOB = cycleHelper - .mPOIDetector - .DetectBullishOrderBlock( - mBar, - ob // - ); - if (isBullOB) - { - // - bool isPricePassed = bar.low > ob.Upper(); - if (isPricePassed) - { - // - if (mBullOB == NULL) - { - // - mBullOB = ob; - } - else - { - // - bool isRefined = mBullOB.Upper() < ob.Upper(); - if (isRefined) - { - mBullOB = ob; - } - } - } - } - } - - // - if (bearOB == NULL) - { - // - XCOrderBlock *ob; - bool isBearOB = cycleHelper - .mPOIDetector - .DetectBearishOrderBlock( - mBar, - ob // - ); - if (isBearOB) - { - // - bool isPricePassed = bar.high < ob.Lower(); - if (isPricePassed) - { - // - if (mBearOB == NULL) - { - // - mBearOB = ob; - } - else - { - // - bool isRefined = mBearOB.Lower() > ob.Lower(); - if (isRefined) - { - mBearOB = ob; - } - } - } - } - } - - // - canContinue = - (bullOB == NULL && mBullOB == NULL) || - (bearOB == NULL && mBearOB == NULL); - if (canContinue) - { - barIndex++; - } - } - - // - if (mBullOB != NULL) - { - bullOB = mBullOB; - } - - // - if (mBearOB != NULL) - { - bearOB = mBearOB; - } - - - -//////////////////////////////////////////////////////////// - - - // - // Detect an Order Block in Vision ... - if (conditions.visionBullOB == NULL || - conditions.visionBearOB == NULL) - { - // - result = DetectOrderBlocks( - NULL, - NULL, - conditions.visionBullOB, - conditions.visionBearOB, - cBar, - mVisionState // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - XCBullishOrderBlockObject *iBullOBObj; - conditions.visionBullOB.To(cTime); - result = mPOIDrawer.CreateBullishOrderBlock( - conditions.visionBullOB, - iBullOBObj // - ); - if (result) - { - AddObjectIfNotExists(iBullOBObj); - } - - // - XCBearishOrderBlockObject *iBearOBObj; - conditions.visionBearOB.To(cTime); - result = mPOIDrawer.CreateBearishOrderBlock( - conditions.visionBearOB, - iBearOBObj // - ); - if (result) - { - AddObjectIfNotExists(iBearOBObj); - } - } - - // - // Consolidation Order Blocks ... - if (conditions.consolidationBullOB == NULL || - conditions.consolidationBearOB == NULL) - { - // - result = DetectOrderBlocks( - conditions.visionBullOB, - conditions.visionBearOB, - conditions.consolidationBullOB, - conditions.consolidationBearOB, - cBar, - mConsolidationState // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - XCBullishOrderBlockObject *iBullOBObj; - conditions.consolidationBullOB.To(cTime); - result = mPOIDrawer.CreateBullishOrderBlock( - conditions.consolidationBullOB, - iBullOBObj // - ); - if (result) - { - AddObjectIfNotExists(iBullOBObj); - } - - // - XCBearishOrderBlockObject *iBearOBObj; - conditions.consolidationBearOB.To(cTime); - result = mPOIDrawer.CreateBearishOrderBlock( - conditions.consolidationBearOB, - iBearOBObj // - ); - if (result) - { - AddObjectIfNotExists(iBearOBObj); - } - } - - // - msg = "OrderBlocks Detected ..."; - Alert(msg); - - // - // Detect Trigger Order Flow ... - if (!HasValidOrderFlow()) - { - // - int samePivots = 40; - int requiredPivots = 10; - - // - bool useVisionState = false; - bool useConsolidationState = false; - bool useVerificationState = false; - bool useAnalyseState = false; - bool useDecisionState = true; - bool useTriggerState = false; - - // - DetectOrderFlow( - cIndex, - samePivots, - requiredPivots, - mTriggerCycleHelper, - mOrderFlow, - mOrderFlowDir, - // - // Filling Pivot State ... - useVisionState, // Use Vision State ... - useConsolidationState, // Use Consolidation State ... - useVerificationState, // Use Verification State ... - useAnalyseState, // Use Analyse State ... - useDecisionState, // Use Decision State ... - useTriggerState // Use Trigger State ... - ); - - // - result = HasValidOrderFlow(); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - bool ignoreSwingHighs = true; - bool ignoreSwingLows = true; - bool ignoreSupportZones = true; - bool ignoreResistanceZones = true; - bool ignoreSupplyZones = true; - bool ignoreDemandZones = true; - bool ignoreBullishOrderBlocks = true; - bool ignoreBearishOrderBlocks = true; - bool ignoreBullishFairValueGaps = true; - bool ignoreBearishFairValueGaps = true; - bool ignoreBullishRejectionBars = true; - bool ignoreBearishRejectionBars = true; - bool ignoreBullishMomentumBars = true; - bool ignoreBearishMomentumBars = true; - - // - RedrawOrderFlow( - false, // Force Clean ... - false, // Same Period ... - true, // Order Flow ... - true, // Order Flow State ... - false, // Only Last Order Flow ... - true, // Only Last Order Flow State ... - // - mOrderFlowDir, // Direction Force ... - ignoreSwingHighs, - ignoreSwingLows, - ignoreSupportZones, - ignoreResistanceZones, - ignoreSupplyZones, - ignoreDemandZones, - ignoreBullishOrderBlocks, - ignoreBearishOrderBlocks, - ignoreBullishFairValueGaps, - ignoreBearishFairValueGaps, - ignoreBullishRejectionBars, - ignoreBearishRejectionBars, - ignoreBullishMomentumBars, - ignoreBearishMomentumBars // - ); - } - - // - msg = "Found OrderFlow : " + (IsBullish(mOrderFlowDir) ? "Bullish" : "Berish"); - Alert(msg); - - // - // Check Market Conditions for - // Specified Structure ... - // ENUM_X_DIRECTION marketStructureDir = X_DIRECTION_NONE; - // result = conditions.HasDirection( - // marketStructureDir, - // cBar // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - // msg = "Found Market Strucutre : " + (IsBullish(marketStructureDir) ? "Bullish" : "Berish"); - // Alert(msg); - - // - // conditions.marketStructureDir = marketStructureDir; - - // // - // XPVPivot lastPivot; - // result = GetLastItem( - // lastPivot, - // mOrderFlow // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - - // - // Detect Last FVG ... - // XOHCL breakerBar; - // result = DetectLastBreakerBar( - // cBar, - // breakerBar, - // lastPivot, - // marketStructureDir // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - // msg = "Found Breaker Bar: " + breakerBar.GetTag(); - // Alert(msg); - - // // - // // Detect Nearest Momentum or Rejection Bar ... - // XOHCL decisionBar; - // result = mDecisionCycleHelper.DetectNearestDecisionBar( - // decisionBar, - // marketStructureDir, - // cBar // - // ); - // if (!result) - // { - // return result; - // } - // msg = "Found Decision Bar: " + decisionBar.GetTag(); - // Alert(msg); - - // // - // // Detect Nearest Sar Change ... - // XOHCL sarChangeBar; - // result = mTriggerCycleHelper.DetectNearestCSARChange( - // sarChangeBar, - // cBar // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - // msg = "Found Sar Change Bar: " + sarChangeBar.GetTag(); - // Alert(msg); - - // // - // // Now we Hvae to Check Other Conditions ... - // result = - // // breakerBar.time > sarChangeBar.time && - // // decisionBar.time > breakerBar.time; - // decisionBar.time > sarChangeBar.time; - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - - // // - // // Now we Have Check Direction Related Conditions ... - // if (IsBullish(marketStructureDir)) - // { - // // - // result = - // // bid > decisionBar.high && - // // bid > breakerBar.high && - // bid > sarChangeBar.high && - // bid > conditions.triggerConditions.xchsarConditions.cSars[0]; - // } - // else - // { - // // - // result = - // // bid < decisionBar.low && - // // bid < breakerBar.low && - // bid < sarChangeBar.high && - // bid < conditions.triggerConditions.xchsarConditions.cSars[0]; - // } - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - - // // - // conditions.provider = "X121SMC"; - // if (IsBullish(marketStructureDir)) - // { - // // - // // conditions.sl = decisionBar.low; - // // conditions.sl = breakerBar.low; - // conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; - // } - // else - // { - // // - // // conditions.sl = decisionBar.high; - // // conditions.sl = breakerBar.high; - // conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; - // } - - -////////////////////////////////////////////////////////////////// - - - // - bool isSamePeaks = - // - conditions.triggerConditions.x121Conditions.peaksBuffer[0] == conditions.decisionConditions.x121Conditions.peaksBuffer[0] && - conditions.decisionConditions.x121Conditions.peaksBuffer[0] == conditions.analyseConditions.x121Conditions.peaksBuffer[0] - // && - // conditions.analyseConditions.x121Conditions.peaksBuffer[0] == conditions.verificationConditions.x121Conditions.peaksBuffer[0] && - // conditions.verificationConditions.x121Conditions.peaksBuffer[0] == conditions.consolidationConditions.x121Conditions.peaksBuffer[0] && - // conditions.consolidationConditions.x121Conditions.peaksBuffer[0] == conditions.visionConditions.x121Conditions.peaksBuffer[0] - // - ; - if (isSamePeaks) { - Print("isSamePeaks"); - } - - // - bool isSameVales = - // - conditions.triggerConditions.x121Conditions.valesBuffer[0] == conditions.decisionConditions.x121Conditions.valesBuffer[0] && - conditions.decisionConditions.x121Conditions.valesBuffer[0] == conditions.analyseConditions.x121Conditions.valesBuffer[0] - // && - // conditions.analyseConditions.x121Conditions.valesBuffer[0] == conditions.verificationConditions.x121Conditions.valesBuffer[0] && - // conditions.verificationConditions.x121Conditions.valesBuffer[0] == conditions.consolidationConditions.x121Conditions.valesBuffer[0] && - // conditions.consolidationConditions.x121Conditions.valesBuffer[0] == conditions.visionConditions.x121Conditions.valesBuffer[0] - // - ; - if (isSameVales) { - Print("isSameVales"); - } - - -////////////////////////////////////////////////////////////////////// - - - // - // Detect Valid Supply and Demand Zones ... - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - result = mTriggerCycleHelper - .DetectValisSupplyZone( - cBar, - supplyZone, - demandZone // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - supplyZone.To(cTime); - XCSupplyZoneObject *iSupplyZoneObj; - result = mPOIDrawer.CreateSupplyZone( - supplyZone, - iSupplyZoneObj // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - demandZone.To(cTime); - XCDemandZoneObject *iDemandZoneObj; - result = mPOIDrawer.CreateDemandZone( - demandZone, - iDemandZoneObj // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - Print("Supply and Demand Zone Created ..."); - - -////////////////////////////////////////////////////////////////////// - - - // - int consolidationsCount = mTriggerCycleHelper.CountConsolidationZones(); - result = IsValidSize(consolidationsCount); - if (!result) - { - // - conditions.Clean(); - return result; - } - XConsolidationZone consolidations[]; - mTriggerCycleHelper.FillConsolidationZones(consolidations); - - // - // Detect Bid inside Of Zones ... - bool hasSupply = false; - bool hasDemand = false; - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - bool isBidInsideZone = false; - XConsolidationZone bidContainsConsolidationZone; - for (int i = consolidationsCount - 1; i >= 0; i--) - { - // - XConsolidationZone iZone = consolidations[i]; - - // - // Check Supply or Demand Zone ... - hasSupply = iZone.HasSupplyZone(supplyZone); - hasDemand = iZone.HasDemandZone(demandZone); - - // - result = hasSupply || - hasDemand; - if (!result) + bool isFilled = item.FillBar(iBar); + if (!isFilled) { continue; } // - // Check Bid inside Zone ... - if (hasSupply) + bool canSelect = (iBar.high <= upper && + iBar.low >= lower) || + (iBar.high >= upper && + iBar.low <= lower); + if (canSelect) { // - result = bid < supplyZone.Upper() && - bid > supplyZone.Lower(); + Add( + item, + h1SwingLows // + ); + + // + // Draw ... + XCSwingLowObject *iObj; + bool isCreated = mPOIDrawer.CreateSwingLow( + item, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + } + } + + // + // Draw ... + XCSupportZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupportZone( + h1SupportZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } +} + +// +count = ArraySize(conditions.h1ResistanceZones); +if (IsValidSize(count)) +{ + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = conditions.h1ResistanceZones[i]; + + // + bool canSelect = + h1ResistanceZone == NULL || + h1ResistanceZone.Upper() > item.Upper(); + if (canSelect) + { + h1ResistanceZone = item; + } + } +} +if (h1ResistanceZone != NULL) +{ + // + // Detect Swings ... + count = ArraySize(conditions.h1State.swingHighs); + if (IsValidSize(count)) + { + // + double upper = h1ResistanceZone.Upper(); + double lower = h1ResistanceZone.Lower(); + + // + for (int i = 0; i < count; i++) + { + // + XCSwing *item = conditions.h1State.swingHighs[i]; + + // + XOHCL iBar; + bool isFilled = item.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool canSelect = (iBar.high <= upper && + iBar.low >= lower) || + (iBar.high >= upper && + iBar.low <= lower); + if (canSelect) + { + // + Add( + item, + h1SwingHighs // + ); + + // + // Draw ... + XCSwingHighObject *iObj; + bool isCreated = mPOIDrawer.CreateSwingHigh( + item, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + } + } + + // + // Draw ... + XCResistanceZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateResistanceZone( + h1ResistanceZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } +} + +// +// 15M ... + +// +XCSupportZone *m15SupportZone = NULL; +count = ArraySize(conditions.m15SupportZones); +if (IsValidSize(count)) +{ + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *item = conditions.m15SupportZones[i]; + + // + bool canSelect = + m15SupportZone == NULL || + m15SupportZone.Lower() < item.Lower(); + if (canSelect) + { + m15SupportZone = item; + } + } +} +if (m15SupportZone != NULL) +{ + // + XCSupportZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupportZone( + m15SupportZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } +} + +// +XCResistanceZone *m15ResistanceZone = NULL; +count = ArraySize(conditions.m15ResistanceZones); +if (IsValidSize(count)) +{ + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = conditions.m15ResistanceZones[i]; + + // + bool canSelect = + m15ResistanceZone == NULL || + m15ResistanceZone.Upper() > item.Upper(); + if (canSelect) + { + m15ResistanceZone = item; + } + } +} +if (m15ResistanceZone != NULL) +{ + // + XCResistanceZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateResistanceZone( + m15ResistanceZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } +} + +// +// 5M ... + +// +XCSupportZone *m5SupportZone = NULL; +count = ArraySize(conditions.m5SupportZones); +if (IsValidSize(count)) +{ + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *item = conditions.m5SupportZones[i]; + + // + bool canSelect = + m5SupportZone == NULL || + m5SupportZone.Lower() < item.Lower(); + if (canSelect) + { + m5SupportZone = item; + } + } +} +if (m5SupportZone != NULL) +{ + // + XCSupportZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupportZone( + m5SupportZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } +} + +// +XCResistanceZone *m5ResistanceZone = NULL; +count = ArraySize(conditions.m5ResistanceZones); +if (IsValidSize(count)) +{ + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = conditions.m5ResistanceZones[i]; + + // + bool canSelect = + m5ResistanceZone == NULL || + m5ResistanceZone.Upper() > item.Upper(); + if (canSelect) + { + m5ResistanceZone = item; + } + } +} +if (m5ResistanceZone != NULL) +{ + // + XCResistanceZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateResistanceZone( + m5ResistanceZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } +} + +// +// DrawState(_5MState); + +// +// +// Strategy Class Tools Functions ... + +/** + * Detect Specified States Market Structure ... + * + * @param dir: ENUM_X_DIRECTION member, Refrence ... + * @param state: XPOIState instance ... + * + * @return ( bool ) + */ +bool DetectMarketStructure( + ENUM_X_DIRECTION &dir, + XCSupportZone *&supportZones[], + XCResistanceZone *&resistanceZones[], + XPOIState &state // +) +{ + // + bool result = false; + + // + int count = 0; + + // + // Filter Untouched Supports ... + Clean(supportZones); + int untouchedSupportsCount = 0; + count = ArraySize(state.supportZones); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *item = state.supportZones[i]; + + // + // Find Breakout Bar + XOHCL iBar; + bool isFilled = item.FillBar(iBar); + if (!isFilled) + { + break; + } + + // + int iBarIndex = iBar.Index(); + int iBarUnTouchedCount = 0; + for (int j = 0; j < iBarIndex; j++) + { + // + XOHCL jBar; + bool isInited = jBar.Init( + iBar.symbol, + iBar.period, + j // + ); + if (!isInited) + { + break; + } + + // + bool isUntouched = + jBar.low > item.Upper(); + if (isUntouched) + { + iBarUnTouchedCount++; + } + else + { + iBarUnTouchedCount--; + } + } + + // + if (iBarUnTouchedCount > 0) + { + // + Add( + item, + supportZones // + ); + } + } + + // + untouchedSupportsCount = ArraySize(supportZones); + if (IsValidSize(untouchedSupportsCount)) + { + // + // Draw ... + // for (int i = 0; i < untouchedSupportsCount; i++) + // { + // // + // XCSupportZone *item = supportZones[i]; + + // // + // XCSupportZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateSupportZone( + // item, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + } + } + + // + // Filter Untouched Resistances ... + Clean(resistanceZones); + int untouchedResistancesCount = 0; + count = ArraySize(state.resistanceZones); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = state.resistanceZones[i]; + + // + // Find Breakout Bar + XOHCL iBar; + bool isFilled = item.FillBar(iBar); + if (!isFilled) + { + break; + } + + // + int iBarIndex = iBar.Index(); + int iBarUnTouchedCount = 0; + for (int j = 0; j < iBarIndex; j++) + { + // + XOHCL jBar; + bool isInited = jBar.Init( + iBar.symbol, + iBar.period, + j // + ); + if (!isInited) + { + break; + } + + // + bool isUntouched = + jBar.high < item.Lower(); + if (isUntouched) + { + iBarUnTouchedCount++; + } + else + { + iBarUnTouchedCount--; + } + } + + // + if (iBarUnTouchedCount > 0) + { + // + Add( + item, + resistanceZones // + ); + } + } + + // + untouchedResistancesCount = ArraySize(resistanceZones); + if (IsValidSize(untouchedResistancesCount)) + { + // + // Draw ... + // for (int i = 0; i < untouchedResistancesCount; i++) + // { + // // + // XCResistanceZone *item = resistanceZones[i]; + + // // + // XCResistanceZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateResistanceZone( + // item, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + } + } + + // + bool hasBullishStructure = + IsValidSize(untouchedSupportsCount) && + untouchedSupportsCount > untouchedResistancesCount; + bool hasBearishStructure = + IsValidSize(untouchedResistancesCount) && + untouchedResistancesCount > untouchedSupportsCount; + + // + result = (hasBullishStructure && + !hasBearishStructure) || + (hasBearishStructure && + !hasBullishStructure); + + // + if (result) + { + // + dir = + hasBullishStructure + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + + // + return result; +} + +//////////////////////////////////////////////////////////////////////////// + +// +// Detect Order Blocks ... +// int obsCount = 0; + +// +// Find Bullish Order Block ... +// XCOrderBlock *bullishOB = NULL; +// XCRejectionBar *bullishOBRejectionBar = NULL; +// obsCount = lastPivot.state.CountBullishOrderBlocks(); +// if (IsValidSize(obsCount)) +// { +// // +// for (int i = 0; i < obsCount; i++) +// { +// // +// XCOrderBlock *iOB = lastPivot.state.bullishOrderBlocks[i]; + +// // +// XOHCL iBar; +// bool hasBar = iOB.FillBar(iBar); +// bool isPeriodSame = hasBar && +// iBar.period == _period; + +// // +// if (iOB.Upper() <= pivotMid && +// iOB.Lower() >= lastPivot.lower) +// { +// // +// bullishOB = iOB; +// break; +// } +// } +// } +// bool hasBullishOB = bullishOB != NULL; +// bool isBullishOBRejected = false; +// if (hasBullishOB) +// { +// // +// int bullishRejectedBarsCount = lastPivot.state.CountBullishRejectionBars(); +// if (IsValidSize(bullishRejectedBarsCount)) +// { +// // +// for (int i = 0; i < bullishRejectedBarsCount; i++) +// { +// // +// XCRejectionBar *item = lastPivot.state.bullishRejectionBars[i]; + +// // +// XOHCL iBar; +// bool isFilled = item.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// bool isRejected = iBar.low <= bullishOB.Lower() && +// (iBar.GetDown() <= bullishOB.Upper() || +// iBar.GetDown() > bullishOB.Upper()); + +// // +// isBullishOBRejected = +// bullishOBRejectionBar == NULL +// ? isRejected +// : isRejected && +// item.From() > bullishOBRejectionBar.From(); +// if (isBullishOBRejected) +// { +// bullishOBRejectionBar = item; +// } +// } +// } +// if (isBullishOBRejected) +// { +// // +// bullishOBRejectionBar.To(cTime); +// XCBullishRejectionBarObject *iObj; +// bool isCreated = mPOIDrawer.CreateBullishRejectionBar( +// bullishOBRejectionBar, +// iObj // +// ); +// if (isCreated) +// { +// AddObjectIfNotExists(iObj); +// } +// } + +// // +// bullishOB.To(cTime); +// XCBullishOrderBlockObject *iObj; +// bool isCreated = mPOIDrawer.CreateBullishOrderBlock( +// bullishOB, +// iObj // +// ); +// if (isCreated) +// { +// AddObjectIfNotExists(iObj); +// } +// } + +// +// Find Bearish Order Block ... +// XCOrderBlock *bearishOB = NULL; +// XCRejectionBar *bearishOBRejectionBar = NULL; +// obsCount = lastPivot.state.CountBearishOrderBlocks(); +// if (IsValidSize(obsCount)) +// { +// // +// for (int i = 0; i < obsCount; i++) +// { +// // +// XCOrderBlock *iOB = lastPivot.state.bearishOrderBlocks[i]; + +// // +// XOHCL iBar; +// bool hasBar = iOB.FillBar(iBar); +// bool isPeriodSame = hasBar && +// iBar.period == _period; + +// // +// if (iOB.Lower() >= pivotMid && +// iOB.Upper() <= lastPivot.upper) +// { +// // +// bearishOB = iOB; +// break; +// } +// } +// } +// bool hasBearishOB = bearishOB != NULL; +// bool isBearishOBRejected = false; +// if (hasBearishOB) +// { +// // +// int bearishRejectedBarsCount = lastPivot.state.CountBearishRejectionBars(); +// if (IsValidSize(bearishRejectedBarsCount)) +// { +// // +// for (int i = 0; i < bearishRejectedBarsCount; i++) +// { +// // +// XCRejectionBar *item = lastPivot.state.bearishRejectionBars[i]; + +// // +// XOHCL iBar; +// bool isFilled = item.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// bool isRejected = iBar.high >= bearishOB.Upper() && +// (iBar.GetUp() <= bearishOB.Lower() || +// iBar.GetUp() > bearishOB.Lower()); + +// // +// isBearishOBRejected = +// bearishOBRejectionBar == NULL +// ? isRejected +// : isRejected && +// item.From() > bearishOBRejectionBar.From(); +// if (isBearishOBRejected) +// { +// bearishOBRejectionBar = item; +// } +// } +// } +// if (isBearishOBRejected) +// { +// // +// bearishOBRejectionBar.To(cTime); +// XCBearishRejectionBarObject *iObj; +// bool isCreated = mPOIDrawer.CreateBearishRejectionBar( +// bearishOBRejectionBar, +// iObj // +// ); +// if (isCreated) +// { +// AddObjectIfNotExists(iObj); +// } +// } + +// // +// bearishOB.To(cTime); +// XCBearishOrderBlockObject *iObj; +// bool isCreated = mPOIDrawer.CreateBearishOrderBlock( +// bearishOB, +// iObj // +// ); +// if (isCreated) +// { +// AddObjectIfNotExists(iObj); +// } +// } + +// // +// // Find an Order Block ... +// bool isBearishOrderBlockRejected = false; + +///////////////////////////////////////////////////////////////////////////// + +// +RedrawOrderFlow(); + +// +// Check Candlestick PullBacks ... +ENUM_X_DIRECTION pullBackDir; +bool hasPullBack = mBarAnalyser.HasPullBack( + pullBackDir, + cBar, + 3, // Loopback ... + true // Force Body ... +); +bool hasBullishPullback = + hasPullBack && + pullBackDir == X_DIRECTION_BULLISH; +bool hasBearishPullback = + hasPullBack && + pullBackDir == X_DIRECTION_BEARISH; + +// +bool isInDiscount = + bid < pivotMid && + bid > lastPivot.lower; + +// +bool isInPremium = + bid > pivotMid && + bid < lastPivot.upper; + +// +// Check Order Flow Validation ... + +// +// For Bullish Order Flow ... +// if Price Breakes Lower to Down, means Change of Charcter Happens ... +bool isCHOCHHappens = + isBullishOrderFlow ? bid < lastPivot.lower - pip + : bid > lastPivot.upper + pip; + +// +// For Bullish Order Flow ... +// if Price Breakes Upper to Up, means Breake of Structure Happens ... +bool isBOSHappens = + isBullishOrderFlow ? bid > lastPivot.upper + pip + : bid < lastPivot.lower - pip; + +// +if (isBOSHappens) +{ + // + // RedrawOrderFlow(); + Print(""); +} + +// +if (isCHOCHHappens) +{ + // + result = false; + ResetOrderFlow(); + return result; +} + +// +// Check 3MA and 3VWAP State ... + +// +bool isVWAPBullishOrdered = + // + ( + // + (conditions.x3vwapConditions.isBullishOrdered || + conditions.x3vwapConditions.isSwitchedToBullishOrdered) + // + || + // + conditions.x3vwapConditions.fasts[cIndex] > conditions.x3vwapConditions.mids[cIndex] + // + || + // + conditions.x3vwapConditions.mids[cIndex] > conditions.x3vwapConditions.slows[cIndex] + // + ) + // + ; + +// +bool isVWAPBearishOrdered = + // + ( + // + (conditions.x3vwapConditions.isBearishOrdered || + conditions.x3vwapConditions.isSwitchedToBearishOrdered) + // + || + // + conditions.x3vwapConditions.fasts[cIndex] < conditions.x3vwapConditions.mids[cIndex] + // + || + // + conditions.x3vwapConditions.mids[cIndex] < conditions.x3vwapConditions.slows[cIndex] + // + ) + // + ; + +// +bool isVWapBullishState = + // + ( + // + (conditions.x3vwapConditions.isBullishState || + conditions.x3vwapConditions.isSwitchedToBullishState) + // + || + // + (x3vwapHelper.IsBullish(conditions.x3vwapConditions.fastStates[cIndex]) && + x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex])) + // + || + // + (x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex]) && + x3vwapHelper.IsBullish(conditions.x3vwapConditions.slowStates[cIndex])) + // + ) + // + ; + +// +bool isVWapBearishState = + // + ( + // + (conditions.x3vwapConditions.isBearishState || + conditions.x3vwapConditions.isSwitchedToBearishState) + // + || + // + (x3vwapHelper.IsBearish(conditions.x3vwapConditions.fastStates[cIndex]) && + x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex])) + // + || + // + (x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex]) && + x3vwapHelper.IsBearish(conditions.x3vwapConditions.slowStates[cIndex])) + // + ) + // + ; + +// +bool isVWapOverFastMA = + // + ( + // + (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex]) + // + || + // + (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.slows[cIndex] > conditions.x3maConditions.fasts[cIndex]) + // + ) + // + ; + +// +bool isVWapUnderFastMA = + // + ( + // + (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex]) + // + || + // + (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.slows[cIndex] < conditions.x3maConditions.fasts[cIndex]) + // + ) + // + ; + +// +bool is3Bullish = + // + ( + // + (isVWAPBullishOrdered && + isVWapBullishState) + // + || + // + (isVWAPBullishOrdered && + isVWapOverFastMA) + // + || + // + (isVWapBullishState && + isVWapOverFastMA) + // + ) + // + ; + +// +bool is3Bearish = + // + ( + // + (isVWAPBearishOrdered && + isVWapBearishState) + // + || + // + (isVWAPBearishOrdered && + isVWapUnderFastMA) + // + || + // + (isVWapBearishState && + isVWapUnderFastMA) + // + ) + // + ; + +// +// Check Parabolic Sars State ... + +// +bool isSarBullish = + // + (conditions.xchsarConditions.isCBullish && + conditions.xchsarConditions.isSSwitchedBullish) + // + || + // + (conditions.xchsarConditions.isSBullish && + conditions.xchsarConditions.isCSwitchedBullish) + // + ; +bool isSarBearish = + // + (conditions.xchsarConditions.isCBearish && + conditions.xchsarConditions.isSSwitchedBearish) + // + || + // + (conditions.xchsarConditions.isSBearish && + conditions.xchsarConditions.isCSwitchedBearish) + // + ; + +// // +// hasLong = +// // +// is3Bullish && +// // isInDiscount && +// isSarBullish // && +// // hasBullishPullback && +// // bullishLiquidityPercent > 30 +// // +// ; + +// // +// hasShort = +// // +// is3Bearish && +// // isInPremium && +// isSarBearish // && +// // hasBearishPullback && +// // bearishLiquidityPercent > 30 +// // +// ; + +////////////////////// + +// +XPVPivot lastPivot; +result = GetLastItem( + lastPivot, + mOrderFlow // +); +if (!result) +{ + return result; +} +bool isBullishOrderFlow = IsBullish(mOrderFlowDir); +bool isBearishOrderFlow = IsBearish(mOrderFlowDir); +double pivotMid = lastPivot.CalculateMid(); + +// +// Calculate Liquidity Percent ... +double bullishLiquidityPercent = lastPivot + .CalculateLiquidityPercent(X_DIRECTION_BULLISH); +double bearishLiquidityPercent = lastPivot + .CalculateLiquidityPercent(X_DIRECTION_BEARISH); +double minLiquidityPercent = 35; +bool hasBullishLiquidity = bullishLiquidityPercent >= minLiquidityPercent; +bool hasBearishLiquidity = bearishLiquidityPercent >= minLiquidityPercent; +result = hasBullishLiquidity || + hasBearishLiquidity; +if (!result) +{ + return result; +} + +///////////////////////////////////////////////////////////////// + +// // +// // 1D Period ... +// // POI Detector ... +// m1DPOI = new XCPOIDetector( +// symbol, +// PERIOD_D1 // +// ); + +// // +// m1DPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m1DPOI.Init(); + +// // +// // 4H Period ... +// // POI Detector ... +// m4HPOI = new XCPOIDetector( +// symbol, +// PERIOD_H4 // +// ); + +// // +// m4HPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m4HPOI.Init(); + +// // +// // 2H Period ... +// // POI Detector ... +// m2HPOI = new XCPOIDetector( +// symbol, +// PERIOD_H2 // +// ); + +// // +// m2HPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m2HPOI.Init(); + +// +// 1H Period ... +// POI Detector ... +// m1HPOI = new XCPOIDetector( +// symbol, +// PERIOD_H1 // +// ); + +// // +// m1HPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m1HPOI.Init(); + +// +// 15M Period ... +// POI Detector ... +// m15MPOI = new XCPOIDetector( +// symbol, +// PERIOD_M15 // +// ); + +// // +// m15MPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m15MPOI.Init(); + +// // +// // 5M Period ... +// // POI Detector ... +// m5MPOI = new XCPOIDetector( +// symbol, +// PERIOD_M5 // +// ); + +// // +// m5MPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m5MPOI.Init(); + +// // +// // 1M Period ... +// // POI Detector ... +// m1MPOI = new XCPOIDetector( +// symbol, +// PERIOD_M1 // +// ); + +// // +// m1MPOI.MaxNumberOfRequiredPOIs(poiRequired); + +// // +// m1MPOI.Init(); + +//////////////////////////////// + +// delete m1DPOI; +// delete m4HPOI; +// delete m2HPOI; +delete m1HPOI; +delete m15MPOI; +// delete m5MPOI; +// delete m1MPOI; + +/////////////////////////////////// + +// +// Point Of Interests ... +XCPOIDetector *mTriggerPOIDetector; +XCPOIDetector *mAnalysePOIDetector; +XCPOIDetector *mVisionPOIDetector; + +// +// XCPOIDetector *m1DPOI; +// XCPOIDetector *m4HPOI; +// XCPOIDetector *m2HPOI; +// XCPOIDetector *m1HPOI; +// XCPOIDetector *m15MPOI; +// XCPOIDetector *m5MPOI; +// XCPOIDetector *m1MPOI; + +// +XPOIState mTriggerPOIState; +XPOIState mAnalysePOIState; +XPOIState mVisionPOIState; + +// XPOIState _1DState; +// XPOIState _4HState; +// XPOIState _2HState; +// XPOIState _1HState; +// XPOIState _15MState; +// XPOIState _5MState; +// XPOIState _1MState; +// XPOIState _CombineState; + +/////////////////////////////////////////// + +// +// Update POIs ... + +// +ENUM_XPOI_EVENTS _events[]; +mPOIDetector.Update(_events); + +// // +// ENUM_XPOI_EVENTS _1DStates[]; +// m1DPOI.Update(_1DStates); + +// // +// ENUM_XPOI_EVENTS _4HStates[]; +// m4HPOI.Update(_4HStates); + +// // +// ENUM_XPOI_EVENTS _2HStates[]; +// m2HPOI.Update(_2HStates); + +// +ENUM_XPOI_EVENTS _1HStates[]; +m1HPOI.Update(_1HStates); + +// // +// ENUM_XPOI_EVENTS _15MStates[]; +// m15MPOI.Update(_15MStates); + +// // +// ENUM_XPOI_EVENTS _5MStates[]; +// m5MPOI.Update(_5MStates); + +// // +// ENUM_XPOI_EVENTS _1MStates[]; +// m1MPOI.Update(_1MStates); + +// // +// // Read all POI States ... +mPOIDetector.GetState(_state); +// m1DPOI.GetState(_1DState); +// m4HPOI.GetState(_4HState); +// m2HPOI.GetState(_2HState); +m1HPOI.GetState(_1HState); +// m15MPOI.GetState(_15MState); +// m5MPOI.GetState(_5MState); +// m1MPOI.GetState(_1MState); + +// +// Combine States ... +// XPOIState _States[]; +// AddRef( +// _1DState, +// _States // +// ); +// AddRef( +// _4HState, +// _States // +// ); +// AddRef( +// _2HState, +// _States // +// ); +// AddRef( +// _1HState, +// _States // +// ); +// AddRef( +// _15MState, +// _States // +// ); +// AddRef( +// _5MState, +// _States // +// ); +// AddRef( +// _1MState, +// _States // +// ); +// CombineStates( +// _CombineState, +// _States // +// ); + +//////////////////////////////////////////////////////////////// + +// +// Works by WVAP and PSar ... +bool long1 = + // + conditions.x3vwapConditions.isBullishState && + conditions.x3vwapConditions.isBullishOrdered && + // conditions.xpvConditions.vales[cIndex] == conditions.xchsarConditions.cSars[cIndex] && + conditions.xchsarConditions.cSars[cIndex] < conditions.x3vwapConditions.slows[cIndex] + // + ; +if (long1) +{ + // + CustomStateDrawing(_1HState); + selectedSL = conditions.xpvConditions.vales[cIndex]; +} + +// +// Works by WVAP and PSar ... +bool short1 = + // + conditions.x3vwapConditions.isBearishState && + conditions.x3vwapConditions.isBearishOrdered && + // conditions.xpvConditions.peaks[cIndex] == conditions.xchsarConditions.cSars[cIndex] && + conditions.xchsarConditions.cSars[cIndex] > conditions.x3vwapConditions.slows[cIndex] + // + ; +if (short1) +{ + // + CustomStateDrawing(_1HState); + selectedSL = conditions.xpvConditions.peaks[cIndex]; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////// + +// mOrderFlow[pivotIDX].state.ticksZone = +//_15MState.ticksZone; + +// // +// // D1 ... +// XPOIState d1; +// if (_1DState.HasChild()) +// { +// // +// DetectPivotPOIs( +// mOrderFlow[pivotIDX], +// _1DState, +// d1, +// lookupSwingHighs, +// lookupSwingLows, +// lookupSupportZones, +// lookupResistanceZones, +// lookupSupplyZones, +// lookupDemandZones, +// lookupBullishOrderBlocks, +// lookupBearishOrderBlocks, +// lookupBullishFairValueGaps, +// lookupBearishFairValueGaps, +// lookupBullishRejectionBars, +// lookupBearishRejectionBars, +// lookupBullishMomentumBars, +// lookupBearishMomentumBars // +// ); + +// // +// if (d1.HasChild()) +// { +// d1.Fill(mOrderFlow[pivotIDX].state); +// } +// } + +// // +// // H4 ... +// XPOIState h4; +// if (_4HState.HasChild()) +// { +// // +// DetectPivotPOIs( +// mOrderFlow[pivotIDX], +// _4HState, +// h4, +// lookupSwingHighs, +// lookupSwingLows, +// lookupSupportZones, +// lookupResistanceZones, +// lookupSupplyZones, +// lookupDemandZones, +// lookupBullishOrderBlocks, +// lookupBearishOrderBlocks, +// lookupBullishFairValueGaps, +// lookupBearishFairValueGaps, +// lookupBullishRejectionBars, +// lookupBearishRejectionBars, +// lookupBullishMomentumBars, +// lookupBearishMomentumBars // +// ); + +// // +// if (h4.HasChild()) +// { +// h4.Fill(mOrderFlow[pivotIDX].state); +// } +// } + +// +// H2 ... +// XPOIState h2; +// if (_2HState.HasChild()) +// { +// // +// DetectPivotPOIs( +// mOrderFlow[pivotIDX], +// _2HState, +// h2, +// lookupSwingHighs, +// lookupSwingLows, +// lookupSupportZones, +// lookupResistanceZones, +// lookupSupplyZones, +// lookupDemandZones, +// lookupBullishOrderBlocks, +// lookupBearishOrderBlocks, +// lookupBullishFairValueGaps, +// lookupBearishFairValueGaps, +// lookupBullishRejectionBars, +// lookupBearishRejectionBars, +// lookupBullishMomentumBars, +// lookupBearishMomentumBars // +// ); + +// // +// if (h2.HasChild()) +// { +// h2.Fill(mOrderFlow[pivotIDX].state); +// } +// } + +// +// H1 ... +XPOIState h1; +if (_1HState.HasChild()) +{ + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + _1HState, + h1, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (h1.HasChild()) + { + h1.Fill(mOrderFlow[pivotIDX].state); + } +} + +// +// M15 ... +// XPOIState m15; +// if (_15MState.HasChild()) +// { +// // +// DetectPivotPOIs( +// mOrderFlow[pivotIDX], +// _15MState, +// m15, +// lookupSwingHighs, +// lookupSwingLows, +// lookupSupportZones, +// lookupResistanceZones, +// lookupSupplyZones, +// lookupDemandZones, +// lookupBullishOrderBlocks, +// lookupBearishOrderBlocks, +// lookupBullishFairValueGaps, +// lookupBearishFairValueGaps, +// lookupBullishRejectionBars, +// lookupBearishRejectionBars, +// lookupBullishMomentumBars, +// lookupBearishMomentumBars // +// ); + +// // +// if (m15.HasChild()) +// { +// m15.Fill(mOrderFlow[pivotIDX].state); +// } +// } + +// +// M5 ... +// XPOIState m5; +// if (_5MState.HasChild()) +// { +// // +// DetectPivotPOIs( +// mOrderFlow[pivotIDX], +// _5MState, +// m5, +// lookupSwingHighs, +// lookupSwingLows, +// lookupSupportZones, +// lookupResistanceZones, +// lookupSupplyZones, +// lookupDemandZones, +// lookupBullishOrderBlocks, +// lookupBearishOrderBlocks, +// lookupBullishFairValueGaps, +// lookupBearishFairValueGaps, +// lookupBullishRejectionBars, +// lookupBearishRejectionBars, +// lookupBullishMomentumBars, +// lookupBearishMomentumBars // +// ); + +// // +// if (m5.HasChild()) +// { +// m5.Fill(mOrderFlow[pivotIDX].state); +// } +// } + +// +// M1 ... +// XPOIState m1; +// if (_1MState.HasChild()) +// { +// // +// DetectPivotPOIs( +// mOrderFlow[pivotIDX], +// _1MState, +// m1, +// lookupSwingHighs, +// lookupSwingLows, +// lookupSupportZones, +// lookupResistanceZones, +// lookupSupplyZones, +// lookupDemandZones, +// lookupBullishOrderBlocks, +// lookupBearishOrderBlocks, +// lookupBullishFairValueGaps, +// lookupBearishFairValueGaps, +// lookupBullishRejectionBars, +// lookupBearishRejectionBars, +// lookupBullishMomentumBars, +// lookupBearishMomentumBars // +// ); + +// // +// if (m1.HasChild()) +// { +// 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 // + ); + + // +} + +//////////////////////////////////////// + +bool canContinue = true; +while (canContinue) +{ + // + XOHCL iBar; + bool isBarInited = iBar.Init( + mBar.symbol, + mBar.period, + barIndex // + ); + if (!isBarInited) + { + break; + } + + // + if (bullOB == NULL) + { + // + XCOrderBlock *ob; + bool isBullOB = cycleHelper + .mPOIDetector + .DetectBullishOrderBlock( + mBar, + ob // + ); + if (isBullOB) + { + // + bool isPricePassed = bar.low > ob.Upper(); + if (isPricePassed) + { + // + if (mBullOB == NULL) + { + // + mBullOB = ob; + } + else + { + // + bool isRefined = mBullOB.Upper() < ob.Upper(); + if (isRefined) + { + mBullOB = ob; + } + } + } + } + } + + // + if (bearOB == NULL) + { + // + XCOrderBlock *ob; + bool isBearOB = cycleHelper + .mPOIDetector + .DetectBearishOrderBlock( + mBar, + ob // + ); + if (isBearOB) + { + // + bool isPricePassed = bar.high < ob.Lower(); + if (isPricePassed) + { + // + if (mBearOB == NULL) + { + // + mBearOB = ob; + } + else + { + // + bool isRefined = mBearOB.Lower() > ob.Lower(); + if (isRefined) + { + mBearOB = ob; + } + } + } + } + } + + // + canContinue = + (bullOB == NULL && mBullOB == NULL) || + (bearOB == NULL && mBearOB == NULL); + if (canContinue) + { + barIndex++; + } +} + +// +if (mBullOB != NULL) +{ + bullOB = mBullOB; +} + +// +if (mBearOB != NULL) +{ + bearOB = mBearOB; +} + +//////////////////////////////////////////////////////////// + +// +// Detect an Order Block in Vision ... +if (conditions.visionBullOB == NULL || + conditions.visionBearOB == NULL) +{ + // + result = DetectOrderBlocks( + NULL, + NULL, + conditions.visionBullOB, + conditions.visionBearOB, + cBar, + mVisionState // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + XCBullishOrderBlockObject *iBullOBObj; + conditions.visionBullOB.To(cTime); + result = mPOIDrawer.CreateBullishOrderBlock( + conditions.visionBullOB, + iBullOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBullOBObj); + } + + // + XCBearishOrderBlockObject *iBearOBObj; + conditions.visionBearOB.To(cTime); + result = mPOIDrawer.CreateBearishOrderBlock( + conditions.visionBearOB, + iBearOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBearOBObj); + } +} + +// +// Consolidation Order Blocks ... +if (conditions.consolidationBullOB == NULL || + conditions.consolidationBearOB == NULL) +{ + // + result = DetectOrderBlocks( + conditions.visionBullOB, + conditions.visionBearOB, + conditions.consolidationBullOB, + conditions.consolidationBearOB, + cBar, + mConsolidationState // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + XCBullishOrderBlockObject *iBullOBObj; + conditions.consolidationBullOB.To(cTime); + result = mPOIDrawer.CreateBullishOrderBlock( + conditions.consolidationBullOB, + iBullOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBullOBObj); + } + + // + XCBearishOrderBlockObject *iBearOBObj; + conditions.consolidationBearOB.To(cTime); + result = mPOIDrawer.CreateBearishOrderBlock( + conditions.consolidationBearOB, + iBearOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBearOBObj); + } +} + +// +msg = "OrderBlocks Detected ..."; +Alert(msg); + +// +// Detect Trigger Order Flow ... +if (!HasValidOrderFlow()) +{ + // + int samePivots = 40; + int requiredPivots = 10; + + // + bool useVisionState = false; + bool useConsolidationState = false; + bool useVerificationState = false; + bool useAnalyseState = false; + bool useDecisionState = true; + bool useTriggerState = false; + + // + DetectOrderFlow( + cIndex, + samePivots, + requiredPivots, + mTriggerCycleHelper, + mOrderFlow, + mOrderFlowDir, + // + // Filling Pivot State ... + useVisionState, // Use Vision State ... + useConsolidationState, // Use Consolidation State ... + useVerificationState, // Use Verification State ... + useAnalyseState, // Use Analyse State ... + useDecisionState, // Use Decision State ... + useTriggerState // Use Trigger State ... + ); + + // + result = HasValidOrderFlow(); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + bool ignoreSwingHighs = true; + bool ignoreSwingLows = true; + bool ignoreSupportZones = true; + bool ignoreResistanceZones = true; + bool ignoreSupplyZones = true; + bool ignoreDemandZones = true; + bool ignoreBullishOrderBlocks = true; + bool ignoreBearishOrderBlocks = true; + bool ignoreBullishFairValueGaps = true; + bool ignoreBearishFairValueGaps = true; + bool ignoreBullishRejectionBars = true; + bool ignoreBearishRejectionBars = true; + bool ignoreBullishMomentumBars = true; + bool ignoreBearishMomentumBars = true; + + // + RedrawOrderFlow( + false, // Force Clean ... + false, // Same Period ... + true, // Order Flow ... + true, // Order Flow State ... + false, // Only Last Order Flow ... + true, // Only Last Order Flow State ... + // + mOrderFlowDir, // Direction Force ... + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); +} + +// +msg = "Found OrderFlow : " + (IsBullish(mOrderFlowDir) ? "Bullish" : "Berish"); +Alert(msg); + +// +// Check Market Conditions for +// Specified Structure ... +// ENUM_X_DIRECTION marketStructureDir = X_DIRECTION_NONE; +// result = conditions.HasDirection( +// marketStructureDir, +// cBar // +// ); +// if (!result) +// { +// // +// conditions.Clean(); +// return result; +// } +// msg = "Found Market Strucutre : " + (IsBullish(marketStructureDir) ? "Bullish" : "Berish"); +// Alert(msg); + +// +// conditions.marketStructureDir = marketStructureDir; + +// // +// XPVPivot lastPivot; +// result = GetLastItem( +// lastPivot, +// mOrderFlow // +// ); +// if (!result) +// { +// // +// conditions.Clean(); +// return result; +// } + +// +// Detect Last FVG ... +// XOHCL breakerBar; +// result = DetectLastBreakerBar( +// cBar, +// breakerBar, +// lastPivot, +// marketStructureDir // +// ); +// if (!result) +// { +// // +// conditions.Clean(); +// return result; +// } +// msg = "Found Breaker Bar: " + breakerBar.GetTag(); +// Alert(msg); + +// // +// // Detect Nearest Momentum or Rejection Bar ... +// XOHCL decisionBar; +// result = mDecisionCycleHelper.DetectNearestDecisionBar( +// decisionBar, +// marketStructureDir, +// cBar // +// ); +// if (!result) +// { +// return result; +// } +// msg = "Found Decision Bar: " + decisionBar.GetTag(); +// Alert(msg); + +// // +// // Detect Nearest Sar Change ... +// XOHCL sarChangeBar; +// result = mTriggerCycleHelper.DetectNearestCSARChange( +// sarChangeBar, +// cBar // +// ); +// if (!result) +// { +// // +// conditions.Clean(); +// return result; +// } +// msg = "Found Sar Change Bar: " + sarChangeBar.GetTag(); +// Alert(msg); + +// // +// // Now we Hvae to Check Other Conditions ... +// result = +// // breakerBar.time > sarChangeBar.time && +// // decisionBar.time > breakerBar.time; +// decisionBar.time > sarChangeBar.time; +// if (!result) +// { +// // +// conditions.Clean(); +// return result; +// } + +// // +// // Now we Have Check Direction Related Conditions ... +// if (IsBullish(marketStructureDir)) +// { +// // +// result = +// // bid > decisionBar.high && +// // bid > breakerBar.high && +// bid > sarChangeBar.high && +// bid > conditions.triggerConditions.xchsarConditions.cSars[0]; +// } +// else +// { +// // +// result = +// // bid < decisionBar.low && +// // bid < breakerBar.low && +// bid < sarChangeBar.high && +// bid < conditions.triggerConditions.xchsarConditions.cSars[0]; +// } +// if (!result) +// { +// // +// conditions.Clean(); +// return result; +// } + +// // +// conditions.provider = "X121SMC"; +// if (IsBullish(marketStructureDir)) +// { +// // +// // conditions.sl = decisionBar.low; +// // conditions.sl = breakerBar.low; +// conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; +// } +// else +// { +// // +// // conditions.sl = decisionBar.high; +// // conditions.sl = breakerBar.high; +// conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; +// } + +////////////////////////////////////////////////////////////////// + +// +bool isSamePeaks = + // + conditions.triggerConditions.x121Conditions.peaksBuffer[0] == conditions.decisionConditions.x121Conditions.peaksBuffer[0] && + conditions.decisionConditions.x121Conditions.peaksBuffer[0] == conditions.analyseConditions.x121Conditions.peaksBuffer[0] + // && + // conditions.analyseConditions.x121Conditions.peaksBuffer[0] == conditions.verificationConditions.x121Conditions.peaksBuffer[0] && + // conditions.verificationConditions.x121Conditions.peaksBuffer[0] == conditions.consolidationConditions.x121Conditions.peaksBuffer[0] && + // conditions.consolidationConditions.x121Conditions.peaksBuffer[0] == conditions.visionConditions.x121Conditions.peaksBuffer[0] + // + ; +if (isSamePeaks) +{ + Print("isSamePeaks"); +} + +// +bool isSameVales = + // + conditions.triggerConditions.x121Conditions.valesBuffer[0] == conditions.decisionConditions.x121Conditions.valesBuffer[0] && + conditions.decisionConditions.x121Conditions.valesBuffer[0] == conditions.analyseConditions.x121Conditions.valesBuffer[0] + // && + // conditions.analyseConditions.x121Conditions.valesBuffer[0] == conditions.verificationConditions.x121Conditions.valesBuffer[0] && + // conditions.verificationConditions.x121Conditions.valesBuffer[0] == conditions.consolidationConditions.x121Conditions.valesBuffer[0] && + // conditions.consolidationConditions.x121Conditions.valesBuffer[0] == conditions.visionConditions.x121Conditions.valesBuffer[0] + // + ; +if (isSameVales) +{ + Print("isSameVales"); +} + +////////////////////////////////////////////////////////////////////// + +// +// Detect Valid Supply and Demand Zones ... +XCSupplyZone *supplyZone; +XCDemandZone *demandZone; +result = mTriggerCycleHelper + .DetectValisSupplyZone( + cBar, + supplyZone, + demandZone // + ); +if (!result) +{ + // + conditions.Clean(); + return result; +} + +// +supplyZone.To(cTime); +XCSupplyZoneObject *iSupplyZoneObj; +result = mPOIDrawer.CreateSupplyZone( + supplyZone, + iSupplyZoneObj // +); +if (!result) +{ + // + conditions.Clean(); + return result; +} + +// +demandZone.To(cTime); +XCDemandZoneObject *iDemandZoneObj; +result = mPOIDrawer.CreateDemandZone( + demandZone, + iDemandZoneObj // +); +if (!result) +{ + // + conditions.Clean(); + return result; +} + +// +Print("Supply and Demand Zone Created ..."); + +////////////////////////////////////////////////////////////////////// + +// +int consolidationsCount = mTriggerCycleHelper.CountConsolidationZones(); +result = IsValidSize(consolidationsCount); +if (!result) +{ + // + conditions.Clean(); + return result; +} +XConsolidationZone consolidations[]; +mTriggerCycleHelper.FillConsolidationZones(consolidations); + +// +// Detect Bid inside Of Zones ... +bool hasSupply = false; +bool hasDemand = false; +XCSupplyZone *supplyZone; +XCDemandZone *demandZone; +bool isBidInsideZone = false; +XConsolidationZone bidContainsConsolidationZone; +for (int i = consolidationsCount - 1; i >= 0; i--) +{ + // + XConsolidationZone iZone = consolidations[i]; + + // + // Check Supply or Demand Zone ... + hasSupply = iZone.HasSupplyZone(supplyZone); + hasDemand = iZone.HasDemandZone(demandZone); + + // + result = hasSupply || + hasDemand; + if (!result) + { + continue; + } + + // + // Check Bid inside Zone ... + if (hasSupply) + { + // + result = bid < supplyZone.Upper() && + bid > supplyZone.Lower(); + } + else + { + // + result = bid < demandZone.Upper() && + bid > demandZone.Lower(); + } + + // + if (result) + { + break; + } +} +if (!result) +{ + // + conditions.Clean(); + return result; +} + +// +if (hasSupply) +{ + // + supplyZone.To(cTime); + XCSupplyZoneObject *iSupplyZoneObj; + result = mPOIDrawer.CreateSupplyZone( + supplyZone, + iSupplyZoneObj // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } +} + +// +if (hasDemand) +{ + // + demandZone.To(cTime); + XCDemandZoneObject *iDemandZoneObj; + result = mPOIDrawer.CreateDemandZone( + demandZone, + iDemandZoneObj // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } +} + +// +Print("BID Inside Zone ..."); + +////////////////////////////////////////////////////////////////////////// + +bool DetectCandlestic( + ENUM_X_DIRECTION &dir, + X121SMCStrategyConditions &conditions // +) +{ + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + int cIndex = 1; + int pIndex = cIndex + 1; + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Momentum Bars ... + XCMomentumBar *cBullishMomentum = NULL; + XCMomentumBar *cBearishMomentum = NULL; + XCMomentumBar *pBullishMomentum = NULL; + XCMomentumBar *pBearishMomentum = NULL; + int bullishMomentumBarsCount = conditions.triggerConditions.state + .CountBullishMomentumBars(); + int bearishMomentumBarsCount = conditions.triggerConditions.state + .CountBearishMomentumBars(); + if (IsValidSize(bullishMomentumBarsCount)) + { + // + cBullishMomentum = conditions.triggerConditions.state.bullishMomentumBars[bullishMomentumBarsCount - 1]; + pBullishMomentum = conditions.triggerConditions.state.bullishMomentumBars[bullishMomentumBarsCount - 2]; + } + if (IsValidSize(bearishMomentumBarsCount)) + { + // + cBearishMomentum = conditions.triggerConditions.state.bearishMomentumBars[bearishMomentumBarsCount - 1]; + pBearishMomentum = conditions.triggerConditions.state.bearishMomentumBars[bearishMomentumBarsCount - 2]; + } + + // + // Rejection Bars ... + XCRejectionBar *cBullishRejection = NULL; + XCRejectionBar *cBearishRejection = NULL; + XCRejectionBar *pBullishRejection = NULL; + XCRejectionBar *pBearishRejection = NULL; + int bullishRejectionBarsCount = conditions.triggerConditions.state + .CountBullishRejectionBars(); + int bearishRejectionBarsCount = conditions.triggerConditions.state + .CountBearishRejectionBars(); + if (IsValidSize(bullishRejectionBarsCount)) + { + // + cBullishRejection = conditions.triggerConditions.state.bullishRejectionBars[bullishRejectionBarsCount - 1]; + pBullishRejection = conditions.triggerConditions.state.bullishRejectionBars[bullishRejectionBarsCount - 2]; + } + if (IsValidSize(bearishRejectionBarsCount)) + { + // + cBearishRejection = conditions.triggerConditions.state.bearishRejectionBars[bearishRejectionBarsCount - 1]; + pBearishRejection = conditions.triggerConditions.state.bearishRejectionBars[bearishRejectionBarsCount - 2]; + } + + // + bool isBullish = + // + // pBar is Rejection and cBar is Momentum ... + // pBar is Momentum and cBar is Rejection ... + // cBar is Momentum and Rejection ... + // + pBullishMomentum != NULL && + pBullishMomentum.IsValid() && + // + cBullishMomentum != NULL && + cBullishMomentum.IsValid() && + // + // + pBullishRejection != NULL && + pBullishRejection.IsValid() && + // + cBullishRejection != NULL && + cBullishRejection.IsValid() && + // + ( + // + (pBar.time == pBullishRejection.BarTime() && + cBar.time == cBullishMomentum.BarTime()) + // + || + // + (pBar.time == pBullishMomentum.BarTime() && + cBar.time == cBullishRejection.BarTime()) + // + || + // + (cBar.time == cBullishMomentum.BarTime() && + cBar.time == cBullishRejection.BarTime()) + // + ) + // + ; + + // + bool isBearish = + // + // pBar is Rejection and cBar is Momentum ... + // pBar is Momentum and cBar is Rejection ... + // cBar is Momentum and Rejection ... + // + pBearishMomentum != NULL && + pBearishMomentum.IsValid() && + // + cBearishMomentum != NULL && + cBearishMomentum.IsValid() && + // + // + pBearishRejection != NULL && + pBearishRejection.IsValid() && + // + cBearishRejection != NULL && + cBearishRejection.IsValid() && + // + ( + // + (pBar.time == pBearishRejection.BarTime() && + cBar.time == cBearishMomentum.BarTime()) + // + || + // + (pBar.time == pBearishMomentum.BarTime() && + cBar.time == cBearishRejection.BarTime()) + // + || + // + (cBar.time == cBearishMomentum.BarTime() && + cBar.time == cBearishRejection.BarTime()) + // + ) + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; +} + +///////////////////////////////////////////////////////////////////////////////////// + +/** + * Detect Nearest Supply/Demand Zones ... + * + * @param bar: XOHCL instance, Start Bar ... + * + * @return ( bool ) + */ +bool DetectValisSupplyZone( + XOHCL &bar, + XCSupplyZone *&supplyZone, + XCDemandZone *&demandZone // +) +{ + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int index = bar.Index(); + + // + double bid = GetBid(bar.symbol); + double ask = GetAsk(bar.symbol); + + // + // Retrieve X121 Cnditions ... + int conditionsLoopback = 10; + X121Conditions x121Conditions; + result = mX121Helper.GetConditions( + x121Conditions, + index, + conditionsLoopback // + ); + if (!result) + { + return result; + } + int validPeaksCount = ArraySize(x121Conditions.validPeaksBuffer); + int validValesCount = ArraySize(x121Conditions.validValesBuffer); + + // + XPOIState state; + ENUM_XPOI_EVENTS events[]; + mPOIDetector.Update(events); + mPOIDetector.GetState(state); + result = state.IsValid() && + state.HasChild(); + if (!result) + { + return result; + } + + // + // Supply Zones ... + XCSupplyZone *supplies[]; + int suppliesCount = state.CountSupplyZones(); + + // + // Select Bar Validated Supply Zones ... + if (IsValidSize(suppliesCount)) + { + // + for (int i = 0; i < suppliesCount; i++) + { + // + XCSupplyZone *iZone = state.supplyZones[i]; + + // + // Check Zone is Valid For Bar ... + bool isValid = bar.high < iZone.Lower() && + ask < iZone.Lower() && + bid < iZone.Lower(); + if (isValid) + { + // + Add( + iZone, + supplies // + ); + } + } + } + suppliesCount = ArraySize(supplies); + + // + // Select Valid Peaks Filtered Supplies ... + if (IsValidSize(suppliesCount)) + { + // + // Check Valid Peaks ... + XCSupplyZone *tmp[]; + if (IsValidSize(validPeaksCount)) + { + // + for (int i = 0; i < suppliesCount; i++) + { + // + XCSupplyZone *iZone = supplies[i]; + + // + for (int j = 0; j < validPeaksCount; j++) + { + // + double value = x121Conditions.validPeaksBuffer[j]; + + // + // Check Valid Peaks in Zone ... + bool isZoneContainsValidValue = + value >= iZone.Lower() && + value <= iZone.Upper(); + if (isZoneContainsValidValue) + { + // + Add( + iZone, + tmp // + ); + } + } + } + } + + // + Clean(supplies); + Copy( + tmp, + supplies // + ); + } + suppliesCount = ArraySize(supplies); + + // + // Select Nearest Supply Zone ... + if (IsValidSize(suppliesCount)) + { + // + // Check Nearest Supplies ... + for (int i = 0; i < suppliesCount; i++) + { + // + XCSupplyZone *iZone = supplies[i]; + if (supplyZone == NULL) + { + supplyZone = iZone; } else { // - result = bid < demandZone.Upper() && - bid > demandZone.Lower(); + bool canChange = + iZone.Lower() < supplyZone.Lower(); + if (canChange) + { + supplyZone = iZone; + } + } + } + } + + // + // Demand Zones ... + XCDemandZone *demands[]; + int demandsCount = state.CountDemandZones(); + + // + // Select Bar Validated Demand Zones ... + if (IsValidSize(demandsCount)) + { + // + for (int i = 0; i < demandsCount; i++) + { + // + XCDemandZone *iZone = state.demandZones[i]; + + // + // Check Zone is Valid For Bar ... + bool isValid = bar.low > iZone.Upper() && + ask > iZone.Upper() && + bid > iZone.Upper(); + if (isValid) + { + // + Add( + iZone, + demands // + ); + } + } + } + demandsCount = ArraySize(demands); + + // + // Select Valid Vales Filtered Demands ... + if (IsValidSize(demandsCount)) + { + // + // Check Valid Vales ... + XCDemandZone *tmp[]; + if (IsValidSize(validValesCount)) + { + // + for (int i = 0; i < demandsCount; i++) + { + // + XCDemandZone *iZone = demands[i]; + + // + for (int j = 0; j < validValesCount; j++) + { + // + double value = x121Conditions.validValesBuffer[j]; + + // + // Check Valid Peaks in Zone ... + bool isZoneContainsValidValue = + value >= iZone.Lower() && + value <= iZone.Upper(); + if (isZoneContainsValidValue) + { + // + Add( + iZone, + tmp // + ); + } + } + } + } + + // + Clean(demands); + Copy( + tmp, + demands // + ); + } + demandsCount = ArraySize(demands); + + // + // Select Nearest Demand Zone ... + if (IsValidSize(demandsCount)) + { + // + // Check Nearest Demands ... + for (int i = 0; i < demandsCount; i++) + { + // + XCDemandZone *iZone = demands[i]; + if (demandZone == NULL) + { + demandZone = iZone; + } + else + { + // + bool canChange = + iZone.Upper() > demandZone.Upper(); + if (canChange) + { + demandZone = iZone; + } + } + } + } + + // + // Validate Founded Zones ... + result = (supplyZone != NULL && + supplyZone.IsValid()) && + (demandZone != NULL && + demandZone.IsValid()); + + // + return result; +} + +//////////////////////////////////////////////////////////////////// + + // + CustomStateDrawing( + conditions.consolidationConditions.state, + false, // + X_DIRECTION_NONE, + false, // ignoreSwingHighs + false, // ignoreSwingLows + false, // ignoreSupportZones + false, // ignoreResistanceZones + false, // ignoreSupplyZones + false, // ignoreDemandZones + true, // ignoreBullishOrderBlocks + true, // ignoreBearishOrderBlocks + true, // ignoreBullishFairValueGaps + true, // ignoreBearishFairValueGaps + true, // ignoreBullishRejectionBars + true, // ignoreBearishRejectionBars + true, // ignoreBullishMomentumBars + true // ignoreBearishMomentumBars + ); + + // + // TODO: Remove ... + // Draw ... + if (hasVisionSupplyZone && visionSupplyZone != NULL) + { + // + visionSupplyZone.To(TimeCurrent()); + XCSupplyZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupplyZone( + visionSupplyZone, + iObj // + ); + if (isCreated) + { + // + iObj.ZoneWidth(4); + iObj.ZoneColor(clrMagenta); + AddObjectIfNotExists(iObj); + } + } + + // + // TODO: Remove ... + // Draw ... + if (hasVisionDemandZone && visionDemandZone != NULL) + { + // + visionDemandZone.To(TimeCurrent()); + XCDemandZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateDemandZone( + visionDemandZone, + iObj // + ); + if (isCreated) + { + // + iObj.ZoneWidth(4); + iObj.ZoneColor(clrAqua); + AddObjectIfNotExists(iObj); + } } // if (result) { - break; + ClearDraws(); } - } - if (!result) - { - // - conditions.Clean(); - return result; - } - // - if (hasSupply) - { + // - supplyZone.To(cTime); - XCSupplyZoneObject *iSupplyZoneObj; - result = mPOIDrawer.CreateSupplyZone( - supplyZone, - iSupplyZoneObj // - ); - if (!result) + // TODO: Remove this ... + // Draw ... + if (hasConsolidationSupportZone && + consolidationSupportZone != NULL) { // - conditions.Clean(); - return result; + consolidationSupportZone.To(TimeCurrent()); + XCSupportZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupportZone( + consolidationSupportZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } } - } - // - if (hasDemand) - { // - demandZone.To(cTime); - XCDemandZoneObject *iDemandZoneObj; - result = mPOIDrawer.CreateDemandZone( - demandZone, - iDemandZoneObj // - ); - if (!result) + // TODO: Remove this ... + // Draw ... + if (hasConsolidationResistanceZone && + consolidationResistanceZone != NULL) { // - conditions.Clean(); - return result; + consolidationResistanceZone.To(TimeCurrent()); + XCResistanceZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateResistanceZone( + consolidationResistanceZone, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } } - } - // - Print("BID Inside Zone ..."); +//////////////////////////////////////////////////////////////////////////////////// + + // + XCSwing *swingLow = NULL; + XCSwing *swingHigh = NULL; + bool isSwingLowRejected = false; + bool isSwingHighRejected = false; + int swingLowsCount = decisionConditions.state.CountSwingLows(); + int swingHighsCount = decisionConditions.state.CountSwingHighs(); + if (IsValidSize(swingLowsCount)) + { + swingLow = decisionConditions.state.swingLows[swingLowsCount - 1]; + } + if (IsValidSize(swingHighsCount)) + { + swingHigh = decisionConditions.state.swingHighs[swingHighsCount - 1]; + } + + // + isSwingLowRejected = swingLow != NULL && + swingLow.IsValid() && + decisionCBar.low > swingLow.GetValue(); + + // + isSwingHighRejected = swingHigh != NULL && + swingHigh.IsValid() && + decisionCBar.high < swingHigh.GetValue(); -////////////////////////////////////////////////////////////////////////// - - - bool DetectCandlestic( - ENUM_X_DIRECTION &dir, - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - int cIndex = 1; - int pIndex = cIndex + 1; - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - // Momentum Bars ... - XCMomentumBar *cBullishMomentum = NULL; - XCMomentumBar *cBearishMomentum = NULL; - XCMomentumBar *pBullishMomentum = NULL; - XCMomentumBar *pBearishMomentum = NULL; - int bullishMomentumBarsCount = conditions.triggerConditions.state - .CountBullishMomentumBars(); - int bearishMomentumBarsCount = conditions.triggerConditions.state - .CountBearishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - cBullishMomentum = conditions.triggerConditions.state.bullishMomentumBars[bullishMomentumBarsCount - 1]; - pBullishMomentum = conditions.triggerConditions.state.bullishMomentumBars[bullishMomentumBarsCount - 2]; - } - if (IsValidSize(bearishMomentumBarsCount)) - { - // - cBearishMomentum = conditions.triggerConditions.state.bearishMomentumBars[bearishMomentumBarsCount - 1]; - pBearishMomentum = conditions.triggerConditions.state.bearishMomentumBars[bearishMomentumBarsCount - 2]; - } - - // - // Rejection Bars ... - XCRejectionBar *cBullishRejection = NULL; - XCRejectionBar *cBearishRejection = NULL; - XCRejectionBar *pBullishRejection = NULL; - XCRejectionBar *pBearishRejection = NULL; - int bullishRejectionBarsCount = conditions.triggerConditions.state - .CountBullishRejectionBars(); - int bearishRejectionBarsCount = conditions.triggerConditions.state - .CountBearishRejectionBars(); - if (IsValidSize(bullishRejectionBarsCount)) - { - // - cBullishRejection = conditions.triggerConditions.state.bullishRejectionBars[bullishRejectionBarsCount - 1]; - pBullishRejection = conditions.triggerConditions.state.bullishRejectionBars[bullishRejectionBarsCount - 2]; - } - if (IsValidSize(bearishRejectionBarsCount)) - { - // - cBearishRejection = conditions.triggerConditions.state.bearishRejectionBars[bearishRejectionBarsCount - 1]; - pBearishRejection = conditions.triggerConditions.state.bearishRejectionBars[bearishRejectionBarsCount - 2]; - } - - // - bool isBullish = - // - // pBar is Rejection and cBar is Momentum ... - // pBar is Momentum and cBar is Rejection ... - // cBar is Momentum and Rejection ... - // - pBullishMomentum != NULL && - pBullishMomentum.IsValid() && - // - cBullishMomentum != NULL && - cBullishMomentum.IsValid() && - // - // - pBullishRejection != NULL && - pBullishRejection.IsValid() && - // - cBullishRejection != NULL && - cBullishRejection.IsValid() && - // - ( - // - (pBar.time == pBullishRejection.BarTime() && - cBar.time == cBullishMomentum.BarTime()) - // - || - // - (pBar.time == pBullishMomentum.BarTime() && - cBar.time == cBullishRejection.BarTime()) - // - || - // - (cBar.time == cBullishMomentum.BarTime() && - cBar.time == cBullishRejection.BarTime()) - // - ) - // - ; - - // - bool isBearish = - // - // pBar is Rejection and cBar is Momentum ... - // pBar is Momentum and cBar is Rejection ... - // cBar is Momentum and Rejection ... - // - pBearishMomentum != NULL && - pBearishMomentum.IsValid() && - // - cBearishMomentum != NULL && - cBearishMomentum.IsValid() && - // - // - pBearishRejection != NULL && - pBearishRejection.IsValid() && - // - cBearishRejection != NULL && - cBearishRejection.IsValid() && - // - ( - // - (pBar.time == pBearishRejection.BarTime() && - cBar.time == cBearishMomentum.BarTime()) - // - || - // - (pBar.time == pBearishMomentum.BarTime() && - cBar.time == cBearishRejection.BarTime()) - // - || - // - (cBar.time == cBearishMomentum.BarTime() && - cBar.time == cBearishRejection.BarTime()) - // - ) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - -///////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index a5238534..107e43a4 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -463,287 +463,6 @@ class XC121SMCCycleHelper : public XCBase // // Tools ... - /** - * Detect Nearest Supply/Demand Zones ... - * - * @param bar: XOHCL instance, Start Bar ... - * - * @return ( bool ) - */ - bool DetectValisSupplyZone( - XOHCL &bar, - XCSupplyZone *&supplyZone, - XCDemandZone *&demandZone // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - - // - double bid = GetBid(bar.symbol); - double ask = GetAsk(bar.symbol); - - // - // Retrieve X121 Cnditions ... - int conditionsLoopback = 10; - X121Conditions x121Conditions; - result = mX121Helper.GetConditions( - x121Conditions, - index, - conditionsLoopback // - ); - if (!result) - { - return result; - } - int validPeaksCount = ArraySize(x121Conditions.validPeaksBuffer); - int validValesCount = ArraySize(x121Conditions.validValesBuffer); - - // - XPOIState state; - ENUM_XPOI_EVENTS events[]; - mPOIDetector.Update(events); - mPOIDetector.GetState(state); - result = state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - // Supply Zones ... - XCSupplyZone *supplies[]; - int suppliesCount = state.CountSupplyZones(); - - // - // Select Bar Validated Supply Zones ... - if (IsValidSize(suppliesCount)) - { - // - for (int i = 0; i < suppliesCount; i++) - { - // - XCSupplyZone *iZone = state.supplyZones[i]; - - // - // Check Zone is Valid For Bar ... - bool isValid = bar.high < iZone.Lower() && - ask < iZone.Lower() && - bid < iZone.Lower(); - if (isValid) - { - // - Add( - iZone, - supplies // - ); - } - } - } - suppliesCount = ArraySize(supplies); - - // - // Select Valid Peaks Filtered Supplies ... - if (IsValidSize(suppliesCount)) - { - // - // Check Valid Peaks ... - XCSupplyZone *tmp[]; - if (IsValidSize(validPeaksCount)) - { - // - for (int i = 0; i < suppliesCount; i++) - { - // - XCSupplyZone *iZone = supplies[i]; - - // - for (int j = 0; j < validPeaksCount; j++) - { - // - double value = x121Conditions.validPeaksBuffer[j]; - - // - // Check Valid Peaks in Zone ... - bool isZoneContainsValidValue = - value >= iZone.Lower() && - value <= iZone.Upper(); - if (isZoneContainsValidValue) - { - // - Add( - iZone, - tmp // - ); - } - } - } - } - - // - Clean(supplies); - Copy( - tmp, - supplies // - ); - } - suppliesCount = ArraySize(supplies); - - // - // Select Nearest Supply Zone ... - if (IsValidSize(suppliesCount)) - { - // - // Check Nearest Supplies ... - for (int i = 0; i < suppliesCount; i++) - { - // - XCSupplyZone *iZone = supplies[i]; - if (supplyZone == NULL) - { - supplyZone = iZone; - } - else - { - // - bool canChange = - iZone.Lower() < supplyZone.Lower(); - if (canChange) - { - supplyZone = iZone; - } - } - } - } - - // - // Demand Zones ... - XCDemandZone *demands[]; - int demandsCount = state.CountDemandZones(); - - // - // Select Bar Validated Demand Zones ... - if (IsValidSize(demandsCount)) - { - // - for (int i = 0; i < demandsCount; i++) - { - // - XCDemandZone *iZone = state.demandZones[i]; - - // - // Check Zone is Valid For Bar ... - bool isValid = bar.low > iZone.Upper() && - ask > iZone.Upper() && - bid > iZone.Upper(); - if (isValid) - { - // - Add( - iZone, - demands // - ); - } - } - } - demandsCount = ArraySize(demands); - - // - // Select Valid Vales Filtered Demands ... - if (IsValidSize(demandsCount)) - { - // - // Check Valid Vales ... - XCDemandZone *tmp[]; - if (IsValidSize(validValesCount)) - { - // - for (int i = 0; i < demandsCount; i++) - { - // - XCDemandZone *iZone = demands[i]; - - // - for (int j = 0; j < validValesCount; j++) - { - // - double value = x121Conditions.validValesBuffer[j]; - - // - // Check Valid Peaks in Zone ... - bool isZoneContainsValidValue = - value >= iZone.Lower() && - value <= iZone.Upper(); - if (isZoneContainsValidValue) - { - // - Add( - iZone, - tmp // - ); - } - } - } - } - - // - Clean(demands); - Copy( - tmp, - demands // - ); - } - demandsCount = ArraySize(demands); - - // - // Select Nearest Demand Zone ... - if (IsValidSize(demandsCount)) - { - // - // Check Nearest Demands ... - for (int i = 0; i < demandsCount; i++) - { - // - XCDemandZone *iZone = demands[i]; - if (demandZone == NULL) - { - demandZone = iZone; - } - else - { - // - bool canChange = - iZone.Upper() > demandZone.Upper(); - if (canChange) - { - demandZone = iZone; - } - } - } - } - - // - // Validate Founded Zones ... - result = (supplyZone != NULL && - supplyZone.IsValid()) && - (demandZone != NULL && - demandZone.IsValid()); - - // - return result; - } - /** * Detect XPV Based POI(s) ... * diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index d589e1d5..b1a101e5 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -470,7 +470,8 @@ struct XPVPivotPoint /** * Cleanup ... */ - void Clean() { + void Clean() + { // value = 0; repetition = 0; @@ -479,19 +480,20 @@ struct XPVPivotPoint /** * Validate ... - * + * * @return ( bool ) */ - bool IsValid() { + bool IsValid() + { // bool result = false; // - result = + result = // value > 0 && repetition > 0 && - type != XPV_NONE + type != XPV_NONE // ; @@ -1965,5 +1967,195 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) // // Custom Providers Conditions ... +struct XTestProiderConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + bool isNewPeak; + bool isNewVale; + + // + bool hasVisionSupplyZone; + XCSupplyZone *visionSupplyZone; + + // + bool hasVisionDemandZone; + XCDemandZone *visionDemandZone; + + // + bool hasConsolidationSupportZone; + XCSupportZone *consolidationSupportZone; + + // + bool hasConsolidationResistanceZone; + XCResistanceZone *consolidationResistanceZone; + + // + double peak; + double vale; + + // + bool hasSamePeaks; + bool hasSameVales; + + // + datetime setupTime; + datetime triggerTime; + + // + // Trigger Props ... + + // + // Constructor ... + XTestProiderConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + peak = 0; + vale = 0; + + // + isNewPeak = false; + isNewVale = false; + hasSamePeaks = false; + hasSameVales = false; + hasVisionSupplyZone = false; + hasVisionDemandZone = false; + hasConsolidationSupportZone = false; + hasConsolidationResistanceZone = false; + + // + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + triggerTime = NULL; + setupTime = NULL; + visionSupplyZone = NULL; + visionDemandZone = NULL; + consolidationSupportZone = NULL; + consolidationResistanceZone = NULL; + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped( + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + result = IsValid(setupTime); + if (!result) + { + return result; + } + + // + bool isBullish = + // + isNewVale && + hasSamePeaks && + hasSameVales && + hasVisionDemandZone && + visionDemandZone != NULL && + visionDemandZone.IsValid() + // + ; + + // + bool isBearish = + // + isNewPeak && + hasSamePeaks && + hasSameVales && + hasVisionSupplyZone && + visionSupplyZone != NULL && + visionSupplyZone.IsValid() + // + ; + + // + result = + isBullish || + isBearish; + if (!result) + { + return result; + } + + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + 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; + } + + // +}; // \ No newline at end of file diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 914e9f5e..7e3ee030 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -148,19 +148,51 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Detect Signal Conditions ... - // X_121_SMC_PROVIDER_SMPV ... - // result = DetectSamePeaksAndValesSignal(conditions); - // if (!result) - // { - // // - // // Detect VWAPC ... - // // X_121_SMC_PROVIDER_VWAPC ... - // result = DetectVWAPCSignal(conditions); - // } - result = DetectRJBPVSignal(conditions); - // result = DetectVWAPCSignal(conditions); + bool hasSignal = false; // + bool hasSMPVSignal = false; + bool hasRJBPVSignal = false; + bool hasVWAPCSignal = false; + bool hasTestSignal = false; + + // + // X_121_SMC_PROVIDER_SMPV ... + if (!hasSignal) + { + // + // hasSMPVSignal = DetectSamePeaksAndValesSignal(conditions); + // hasSignal = hasSMPVSignal; + } + + // + // X_121_SMC_PROVIDER_RJBPV ... + if (!hasSignal) + { + // // + // hasRJBPVSignal = DetectRJBPVSignal(conditions); + // hasSignal = hasRJBPVSignal; + } + + // + // X_121_SMC_PROVIDER_VWAPC ... + if (!hasSignal) + { + // // + // hasVWAPCSignal = DetectVWAPCSignal(conditions); + // hasSignal = hasVWAPCSignal; + } + + // + if (!hasSignal) + { + // + hasTestSignal = DetectTestSignal(conditions); + hasSignal = hasTestSignal; + } + + // + result = hasSignal; if (!result) { // @@ -246,12 +278,10 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // result = PrepareSignal(signal); - // if (result) - // { - // // - // // Print("PRV: ", provider); - // // DrawSignal(signal); - // } + if (result) + { + DrawSignal(signal); + } // hasLong = false; @@ -643,6 +673,14 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + // + // Detect a Valid Peaks Break ... + + // + // Find Supply and Demand Zones ... + // XPOIState state = conditions.visionConditions.state; + // int supplyZonesCount = + // bool isBullish = // @@ -672,6 +710,27 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + // + CustomStateDrawing( + conditions.visionConditions.state, + false, // + X_DIRECTION_NONE, + false, // ignoreSwingHighs + false, // ignoreSwingLows + true, // ignoreSupportZones + true, // ignoreResistanceZones + false, // ignoreSupplyZones + false, // ignoreDemandZones + true, // ignoreBullishOrderBlocks + true, // ignoreBearishOrderBlocks + true, // ignoreBullishFairValueGaps + true, // ignoreBearishFairValueGaps + true, // ignoreBullishRejectionBars + true, // ignoreBearishRejectionBars + true, // ignoreBullishMomentumBars + true // ignoreBearishMomentumBars + ); + // // Set SL, Provider and Direction ... conditions.signalDir = @@ -749,137 +808,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy * * @return ( bool ) */ - // TODO: Required Calibrate ... - bool DetectVWAPCSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - string msg = NULL; - - // - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_VWAPC; - string providerStr = ToString(provider); - - // - // Check Candlestic State ... - ENUM_X_DIRECTION candlesticDir; - result = DetectCandlestic( - provider, - candlesticDir, - conditions // - ); - if (!result) - { - return result; - } - - // - // Check Sar State ... - ENUM_X_DIRECTION sarDir; - result = DetectSarState( - provider, - sarDir, - conditions // - ); - if (!result) - { - return result; - } - - // - // Check VWAP State ... - ENUM_X_DIRECTION vwapDir; - result = DetectVWapState( - provider, - vwapDir, - conditions // - ); - if (!result) - { - return result; - } - - // - bool isBullish = - // - IsBullish(sarDir) && - IsBullish(vwapDir) && - IsBullish(candlesticDir) - // - ; - - // - bool isBearish = - // - IsBearish(sarDir) && - IsBearish(vwapDir) && - IsBearish(candlesticDir) - // - ; - - // - result = - // - isBullish || - isBearish - // - ; - - // - Print("VWap Signal ..."); - - // - if (!result) - { - return result; - } - - // - return result; - } - bool DetectRJBPVSignal( X121SMCStrategyConditions &conditions // ) @@ -982,7 +910,7 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy bool isValeInsideDemandZone = false; // - XPOIState state = conditions.consolidationConditions.state; + XPOIState state = conditions.verificationConditions.state; // // // // Detect Order Block ... @@ -1214,6 +1142,974 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + /** + * Detect and Parse Market Conditions for Signalling ... + * + * @param conditions: X121SMCStrategyConditions instance Reference ... + * + * @return ( bool ) + */ + // TODO: Required Calibrate ... + bool DetectVWAPCSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + return false; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + string msg = NULL; + + // + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_VWAPC; + string providerStr = ToString(provider); + + // + // Check Candlestic State ... + ENUM_X_DIRECTION candlesticDir; + result = DetectCandlestic( + provider, + candlesticDir, + conditions // + ); + if (!result) + { + return result; + } + + // + // Check Sar State ... + ENUM_X_DIRECTION sarDir; + result = DetectSarState( + provider, + sarDir, + conditions // + ); + if (!result) + { + return result; + } + + // + // Check VWAP State ... + ENUM_X_DIRECTION vwapDir; + result = DetectVWapState( + provider, + vwapDir, + conditions // + ); + if (!result) + { + return result; + } + + // + bool isBullish = + // + IsBullish(sarDir) && + IsBullish(vwapDir) && + IsBullish(candlesticDir) + // + ; + + // + bool isBearish = + // + IsBearish(sarDir) && + IsBearish(vwapDir) && + IsBearish(candlesticDir) + // + ; + + // + result = + // + isBullish || + isBearish + // + ; + + // + Print("VWap Signal ..."); + + // + if (!result) + { + return result; + } + + // + return result; + } + + // + // TODO: Remove this ... + XTestProiderConditions mTestConditions; + bool DetectTestSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_SMPV; + string providerStr = ToString(provider); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + bool isBullish = false; + bool isBearish = false; + + // + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + double selectedSL = 0; + + // + // Retrieve Peak and Vale ... + double peak = conditions.triggerConditions.x121Conditions.peaksBuffer[0]; + double vale = conditions.triggerConditions.x121Conditions.valesBuffer[0]; + + // + X121SMCCycleConditions triggerConditions = conditions.triggerConditions; + X121SMCCycleConditions decisionConditions = conditions.decisionConditions; + X121SMCCycleConditions analyseConditions = conditions.analyseConditions; + X121SMCCycleConditions verificationConditions = conditions.verificationConditions; + X121SMCCycleConditions consolidationConditions = conditions.consolidationConditions; + X121SMCCycleConditions visionConditions = conditions.visionConditions; + + // + XPOIState triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + int zoneValidationDivider = 10; + + // + // Try to Detect Setup Conditions ... + ENUM_X_DIRECTION setupDir; + result = mTestConditions.IsSetuped(setupDir); + if (!result) + { + // + // First we must check a new Peak or Vale Happens ... + bool isNewPeak = conditions.triggerConditions.x121Conditions.isNewPeak; + bool isNewVale = conditions.triggerConditions.x121Conditions.isNewVale; + + // + result = isNewPeak || + isNewVale; + if (!result) + { + return result; + } + + // + mTestConditions.isNewPeak = isNewPeak; + mTestConditions.isNewVale = isNewVale; + + // + // We have to Check the Peaks and Vales Happens inside a Demand or Supply Zone ... + // in Vision State ... + + // + bool hasVisionSupplyZone = false; + XCSupplyZone *visionSupplyZone = NULL; + int visionSupplyZonesCount = visionState.CountSupplyZones(); + if (isNewPeak && + IsValidSize(visionSupplyZonesCount)) + { + // + // Try to Find Inside Zone ... + for (int i = 0; i < visionSupplyZonesCount; i++) + { + // + XCSupplyZone *iZone = visionState.supplyZones[i]; + double zoneValidRange = (iZone.Upper() - iZone.Lower()) / zoneValidationDivider; + + // + hasVisionSupplyZone = + // + peak >= iZone.Lower() && + peak <= iZone.Upper() && + peak > iZone.Upper() - zoneValidRange + // + ; + if (hasVisionSupplyZone) + { + // + visionSupplyZone = iZone; + break; + } + } + } + + // + bool hasVisionDemandZone = false; + XCDemandZone *visionDemandZone = NULL; + int visionDemandZonesCount = visionState.CountDemandZones(); + if (isNewVale && + IsValidSize(visionDemandZonesCount)) + { + // + // Try to Find Inside Zone ... + for (int i = 0; i < visionDemandZonesCount; i++) + { + // + XCDemandZone *iZone = visionState.demandZones[i]; + double zoneValidRange = (iZone.Upper() - iZone.Lower()) / zoneValidationDivider; + + // + hasVisionDemandZone = + // + vale >= iZone.Lower() && + vale <= iZone.Upper() && + vale < iZone.Lower() + zoneValidRange + // + ; + if (hasVisionDemandZone) + { + // + visionDemandZone = iZone; + break; + } + } + } + + // + result = hasVisionSupplyZone || + hasVisionDemandZone; + if (!result) + { + return result; + } + + // + mTestConditions.visionSupplyZone = visionSupplyZone; + mTestConditions.visionDemandZone = visionDemandZone; + + // + mTestConditions.hasVisionSupplyZone = hasVisionSupplyZone; + mTestConditions.hasVisionDemandZone = hasVisionDemandZone; + + // + double triggerPeak = conditions.triggerConditions.x121Conditions.peaksBuffer[0]; + double decisionPeak = conditions.decisionConditions.x121Conditions.peaksBuffer[0]; + double analysePeak = conditions.analyseConditions.x121Conditions.peaksBuffer[0]; + double verificationPeak = conditions.verificationConditions.x121Conditions.peaksBuffer[0]; + double consolidationPeak = conditions.consolidationConditions.x121Conditions.peaksBuffer[0]; + double visionPeak = conditions.visionConditions.x121Conditions.peaksBuffer[0]; + + // + bool isPeaksSame = + // + triggerPeak && + decisionPeak && + analysePeak && + verificationPeak && + consolidationPeak && + visionPeak + // + ; + + // + double triggerVale = conditions.triggerConditions.x121Conditions.valesBuffer[0]; + double decisionVale = conditions.decisionConditions.x121Conditions.valesBuffer[0]; + double analyseVale = conditions.analyseConditions.x121Conditions.valesBuffer[0]; + double verificationVale = conditions.verificationConditions.x121Conditions.valesBuffer[0]; + double consolidationVale = conditions.consolidationConditions.x121Conditions.valesBuffer[0]; + double visionVale = conditions.visionConditions.x121Conditions.valesBuffer[0]; + + // + bool isValesSame = + // + triggerVale && + decisionVale && + analyseVale && + verificationVale && + consolidationVale && + visionVale + // + ; + + // + mTestConditions.hasSamePeaks = isPeaksSame; + mTestConditions.hasSameVales = isValesSame; + + // + isBullish = + // + isNewVale && + isPeaksSame && + isValesSame && + hasVisionDemandZone + // + ; + + // + isBearish = + // + isNewPeak && + isPeaksSame && + isValesSame && + hasVisionSupplyZone + // + ; + + // + result = + isBullish || + isBearish; + if (!result) + { + return result; + } + + // + mTestConditions.setupTime = TimeCurrent(); + + // + result = mTestConditions.IsSetuped(setupDir); + if (!result) + { + return result; + } + + // + // Alert ... + string message = providerStr + " Conditions Set Upped: " + ToString(setupDir); + Alert(message); + } + else + { + // + // Try to Detect Trigger Conditions ... + mTestConditions.symbol = symbol; + mTestConditions.period = period; + + // + // Try to Find Support Zone which Vales Inside it ... + bool hasConsolidationSupportZone = false; + XCSupportZone *consolidationSupportZone = NULL; + int consolidationSupportZonesCount = consolidationState.CountSupportZones(); + if (IsValidSize(consolidationSupportZonesCount)) + { + // + for (int i = 0; i < consolidationSupportZonesCount; i++) + { + // + XCSupportZone *iZone = consolidationState.supportZones[i]; + // double zoneValidRange = (iZone.Upper() - iZone.Lower()) / zoneValidationDivider; + + // + hasConsolidationSupportZone = + // + peak >= iZone.Lower() && + peak <= iZone.Upper() + // && + // vale < iZone.Upper() - zoneValidRange + // + ; + if (hasConsolidationSupportZone) + { + // + consolidationSupportZone = iZone; + break; + } + } + } + + // + // Try to Find Resistance Zone which Peaks Inside it ... + bool hasConsolidationResistanceZone = false; + XCResistanceZone *consolidationResistanceZone = NULL; + int consolidationResistanceZonesCount = consolidationState.CountResistanceZones(); + if (IsValidSize(consolidationResistanceZonesCount)) + { + // + for (int i = 0; i < consolidationResistanceZonesCount; i++) + { + // + XCResistanceZone *iZone = consolidationState.resistanceZones[i]; + // double zoneValidRange = (iZone.Upper() - iZone.Lower()) / zoneValidationDivider; + + // + hasConsolidationResistanceZone = + // + vale >= iZone.Lower() && + vale <= iZone.Upper() + // && + // peak > iZone.Lower() + zoneValidRange + // + ; + if (hasConsolidationResistanceZone) + { + // + consolidationResistanceZone = iZone; + break; + } + } + } + + // + result = hasConsolidationSupportZone || + hasConsolidationResistanceZone; + if (!result) + { + return result; + } + + // + result = + // + (IsBullish(setupDir) && + hasConsolidationResistanceZone) + // + || + // + (IsBearish(setupDir) && + hasConsolidationSupportZone) + // + ; + if (!result) + { + return result; + } + + // + // Detect State Conditions ... + + // + // Vision ... + + // + bool isVisionBullishPassed = + // + // Sar ... + visionConditions.x121Conditions.isSarBullish + // + && + // + // VWap ... + visionConditions.x121Conditions.isVWapFastBullish + // + ; + + // + bool isVisionBearishPassed = + // + // Sar ... + visionConditions.x121Conditions.isSarBearish + // + && + // + // VWap ... + visionConditions.x121Conditions.isVWapFastBearish + // + ; + + // + bool isVisionPassed = isVisionBullishPassed || + isVisionBearishPassed; + result = isVisionPassed; + if (!result) + { + return result; + } + + // + // Consolidation ... + + // + bool isConsolidationBullishPassed = + // + // Sar ... + consolidationConditions.x121Conditions.isSarBullish + // + && + // + // VWap State ... + consolidationConditions.x121Conditions.isVWapBullishState + // + && + // + // VWap Order ... + consolidationConditions.x121Conditions.isVWapBullishOrdered + // + ; + + // + bool isConsolidationBearishPassed = + // + // + // Sar ... + consolidationConditions.x121Conditions.isSarBearish + // + && + // + // VWap State ... + consolidationConditions.x121Conditions.isVWapBearishState + // + && + // + // VWap Order ... + consolidationConditions.x121Conditions.isVWapBearishOrdered + // + ; + + // + bool isConsolidationPassed = isConsolidationBullishPassed || + isConsolidationBearishPassed; + result = isConsolidationPassed; + if (!result) + { + return result; + } + + // + // Verification ... + + // + bool isVerificationBullishPassed = + // + // Sar ... + verificationConditions.x121Conditions.isSarBullish + // + && + // + // VWap State ... + verificationConditions.x121Conditions.isVWapBullishState + // + && + // + // VWap Order ... + verificationConditions.x121Conditions.isVWapBullishOrdered + // + ; + + // + bool isVerificationBearishPassed = + // + // Sar ... + verificationConditions.x121Conditions.isSarBearish + // + && + // + // VWap State ... + verificationConditions.x121Conditions.isVWapBearishState + // + && + // + // VWap Order ... + verificationConditions.x121Conditions.isVWapBearishOrdered + // + ; + + // + bool isVerificationPassed = isVerificationBullishPassed || + isVerificationBearishPassed; + result = isVerificationPassed; + if (!result) + { + return result; + } + + // + // Analyse ... + + // + bool isAnalyseBullishPassed = + // + // Sar ... + analyseConditions.x121Conditions.isSarBullish + // + && + // + // VWap Order ... + analyseConditions.x121Conditions.isVWapBullishOrdered + // + && + // + // VWap State ... + (analyseConditions.x121Conditions.isVWapBullishState || + (analyseConditions.x121Conditions.isVWapMidBullish && + analyseConditions.x121Conditions.isVWapSlowBullish)) + // + ; + + // + bool isAnalyseBearishPassed = + // + // Sar ... + analyseConditions.x121Conditions.isSarBearish + // + && + // + // VWap Order ... + analyseConditions.x121Conditions.isVWapBearishOrdered + // + && + // + // VWap State ... + (analyseConditions.x121Conditions.isVWapBearishState || + (analyseConditions.x121Conditions.isVWapMidBearish && + analyseConditions.x121Conditions.isVWapSlowBearish)) + // + ; + + // + bool isAnalysePassed = isAnalyseBullishPassed || + isAnalyseBearishPassed; + result = isAnalysePassed; + if (!result) + { + return result; + } + + // + // Decision ... + + // + double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; + double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; + + // + XOHCL decisionCBar; + result = mDecisionCycleHelper.GetBar( + decisionCBar, + cIndex // + ); + + // + // Check Fibo Pressure ... + ENUM_X_DIRECTION pressureDir; + bool hasPressurePin = mBarAnalyser.HasFiboPressure( + decisionCBar, + pressureDir // + ); + + // + bool isBarBullish = + // + (hasPressurePin && + IsBullish(pressureDir)) + // + && + // + decisionCBar.low == decisionVale + // + ; + + // + bool isBarBearish = + // + (hasPressurePin && + IsBearish(pressureDir)) + // + && + // + decisionCBar.high == decisionPeak + // + ; + + // + bool isBarPassed = isBarBullish || + isBarBearish; + result = isBarPassed; + if (!result) + { + return result; + } + + // + bool isDecisionBullishPassed = + // + // Bar ... + isBarBullish + // + && + // + // VWap Order ... + decisionConditions.x121Conditions.isVWapBullishOrdered + // + ; + + // + bool isDecisionBearishPassed = + // + // Bar ... + isBarBearish + // + && + // + // VWap Order ... + decisionConditions.x121Conditions.isVWapBearishOrdered + // + ; + + // + bool isDecisionPassed = isDecisionBullishPassed || + isDecisionBearishPassed; + result = isDecisionPassed; + if (!result) + { + return result; + } + + // + // Trigger ... + + // + double donOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; + double donOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; + + // + double donCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; + double donCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; + + // + bool isDonBullish = + // + donCloseLower > donOpenUpper + // + && + // + cBar.low > donCloseLower && + cBar.high > donCloseLower + // + ; + + // + bool isDonBearish = + // + donOpenUpper > donCloseUpper + // + && + // + cBar.low < donCloseUpper && + cBar.high < donCloseUpper + // + ; + + // + bool isTriggerBullishPassed = + // + // Don ... + isDonBullish + // + && + // + // Sar ... + triggerConditions.x121Conditions.isSarBullish + // + ; + + // + bool isTriggerBearishPassed = + // + // Don ... + isDonBearish + // + && + // + // Sar ... + triggerConditions.x121Conditions.isSarBearish + // + ; + + // + bool isTriggerPassed = isTriggerBullishPassed || + isTriggerBearishPassed; + result = isTriggerPassed; + if (!result) + { + return result; + } + + // + // + // + + // + bool isBullishTriggerConditionsPassed = + // + isConsolidationBullishPassed && + isVerificationBullishPassed && + isAnalyseBullishPassed && + isDecisionBullishPassed && + isTriggerBullishPassed + // + ; + + // + bool isBearishTriggerConditionsPassed = + // + isConsolidationBearishPassed && + isVerificationBearishPassed && + isAnalyseBearishPassed && + isDecisionBearishPassed && + isTriggerBearishPassed + // + ; + + // + // + // + + // + bool isBullish = + // + IsBullish(setupDir) && + hasConsolidationSupportZone && + isBullishTriggerConditionsPassed + // + ; + + // + bool isBearish = + // + IsBearish(setupDir) && + hasConsolidationResistanceZone && + isBearishTriggerConditionsPassed + // + ; + + // + result = + isBullish || + isBearish; + if (!result) + { + return result; + } + + // + double entry = GetEntry( + symbol, + setupDir // + ); + double spread = GetSpread( + symbol // + ); + + // + zoneValidationDivider = 8; + double selectedSL = isBullish + ? consolidationResistanceZone.Upper() - spread - + ((consolidationResistanceZone.Upper() - consolidationResistanceZone.Lower()) / + zoneValidationDivider) + : consolidationSupportZone.Lower() + spread + + ((consolidationSupportZone.Upper() - consolidationSupportZone.Lower()) / + zoneValidationDivider); + + // + mTestConditions.sl = selectedSL; + mTestConditions.type = + isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + mTestConditions.triggerTime = TimeCurrent(); + } + + // + // Check Conditions is Prepared for Trigger ... + result = mTestConditions.CanTrigger(); + if (!result) + { + return result; + } + + // + conditions.signalDir = setupDir; + conditions.provider = providerStr; + conditions.sl = mTestConditions.sl; + + // + mTestConditions.Clean(); + + // + return result; + } + // // Helper Functions ...