diff --git a/Experts/x-saherelm.xfima.backtester.ea.mq5 b/Experts/x-saherelm.xfima.backtester.ea.mq5 index ed3537dd..618f7717 100644 --- a/Experts/x-saherelm.xfima.backtester.ea.mq5 +++ b/Experts/x-saherelm.xfima.backtester.ea.mq5 @@ -920,6 +920,8 @@ void HandleSignalLookup(XOHCL &bar) } // + XBoxZone iZone; + XSignal iSignal; string iName = NULL; XBoxZone supports[]; XBoxZone resistances[]; @@ -933,6 +935,10 @@ void HandleSignalLookup(XOHCL &bar) // Check Required Pattern Exists ... bool hasPinnedBar = HasDirection(marketStructure.pinnedDir); bool hasEngulfedBar = HasDirection(marketStructure.engulfedDir); + bool hasFlagPattern = HasDirection(marketStructure.flagPatternDir); + bool hasStarPattern = HasDirection(marketStructure.starPatternDir); + bool hasRisingPattern = HasDirection(marketStructure.risingPatternDir); + bool hasPiercingPattern = HasDirection(marketStructure.piercingPatternDir); bool hasSignalKeyBar = HasDirection(marketStructure.signalKeyBarPatternDir); // @@ -1222,73 +1228,73 @@ void HandleSignalLookup(XOHCL &bar) { // // Support ... - // XBoxZone supportBox; - // XCBoxObject *iSupportObj; - // has = marketStructure.zigzagAnalysis.HasSupportBox(supportBox); - // if (has) - // { - // // - // supportBox.to = bar.time; - // AddIfNotExists( - // supportBox, - // supports // - // ); - // has = fima2Signaller.poiDrawer.DrawBox( - // supportBox, - // iSupportObj, - // true, // Ignore At ... - // supportBox.type // Name ... - // ); - // if (has) - // { - // // - // XPOIStyle iStyle; - // fima2Signaller.poiDrawer.GetBoxStyle( - // iStyle, - // supportBox.dir // - // ); - // fima2Signaller.poiDrawer.ApplyBoxStyle( - // iSupportObj, - // iStyle // - // ); - // iStyle.Clean(); - // } - // } + XBoxZone supportBox; + XCBoxObject *iSupportObj; + has = marketStructure.zigzagAnalysis.HasSupportBox(supportBox); + if (has) + { + // + supportBox.to = bar.time; + AddIfNotExists( + supportBox, + supports // + ); + has = fima2Signaller.poiDrawer.DrawBox( + supportBox, + iSupportObj, + true, // Ignore At ... + supportBox.type // Name ... + ); + if (has) + { + // + XPOIStyle iStyle; + fima2Signaller.poiDrawer.GetBoxStyle( + iStyle, + supportBox.dir // + ); + fima2Signaller.poiDrawer.ApplyBoxStyle( + iSupportObj, + iStyle // + ); + iStyle.Clean(); + } + } // // Resistance ... - // XBoxZone resistanceBox; - // XCBoxObject *iResistanceObj; - // has = marketStructure.zigzagAnalysis.HasResistanceBox(resistanceBox); - // if (has) - // { - // // - // resistanceBox.to = bar.time; - // AddIfNotExists( - // resistanceBox, - // supports // - // ); - // has = fima2Signaller.poiDrawer.DrawBox( - // resistanceBox, - // iResistanceObj, - // true, // Ignore At ... - // resistanceBox.type // Name ... - // ); - // if (has) - // { - // // - // XPOIStyle iStyle; - // fima2Signaller.poiDrawer.GetBoxStyle( - // iStyle, - // resistanceBox.dir // - // ); - // fima2Signaller.poiDrawer.ApplyBoxStyle( - // iResistanceObj, - // iStyle // - // ); - // iStyle.Clean(); - // } - // } + XBoxZone resistanceBox; + XCBoxObject *iResistanceObj; + has = marketStructure.zigzagAnalysis.HasResistanceBox(resistanceBox); + if (has) + { + // + resistanceBox.to = bar.time; + AddIfNotExists( + resistanceBox, + supports // + ); + has = fima2Signaller.poiDrawer.DrawBox( + resistanceBox, + iResistanceObj, + true, // Ignore At ... + resistanceBox.type // Name ... + ); + if (has) + { + // + XPOIStyle iStyle; + fima2Signaller.poiDrawer.GetBoxStyle( + iStyle, + resistanceBox.dir // + ); + fima2Signaller.poiDrawer.ApplyBoxStyle( + iResistanceObj, + iStyle // + ); + iStyle.Clean(); + } + } // // Pivots ... @@ -1484,31 +1490,103 @@ void HandleSignalLookup(XOHCL &bar) } // - // Selecting Price Type of Bar based on Dir ... + // Support ... + bool hasSupport = marketStructure.support.IsValid(); + if (hasSupport) + { + // + AddIfNotExists( + marketStructure.support, + supports // + ); + + // + XCBoxObject *iObj; + has = fima2Signaller.poiDrawer.DrawBox( + marketStructure.support, + iObj); + if (has) + { + } + } + + // + // Resistance ... + bool hasResistance = marketStructure.resistance.IsValid(); + if (hasResistance) + { + // + AddIfNotExists( + marketStructure.resistance, + resistances // + ); + + // + XCBoxObject *iObj; + has = fima2Signaller.poiDrawer.DrawBox( + marketStructure.resistance, + iObj); + if (has) + { + } + } + + // + // Check Bar Pattern Exists ... has = hasPinnedBar || hasEngulfedBar || - hasSignalKeyBar; + hasFlagPattern || + hasStarPattern || + hasSignalKeyBar || + hasRisingPattern || + hasPiercingPattern; + + // + // Select Pattern Direction and Price and Price Type ... if (has) { // - // Retrieve Direction ... if (hasPinnedBar) { // iDir = marketStructure.pinnedDir; - iName = "XPin_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + iName = "pinned" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); } else if (hasEngulfedBar) { // iDir = marketStructure.engulfedDir; - iName = "XEngulf_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + iName = "engulfed" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasFlagPattern) + { + // + iDir = marketStructure.flagPatternDir; + iName = "flagPattern" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasStarPattern) + { + // + iDir = marketStructure.starPatternDir; + iName = "starPattern" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); } else if (hasSignalKeyBar) + { + // + iDir = marketStructure.risingPatternDir; + iName = "risingPattern" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasRisingPattern) + { + // + iDir = marketStructure.piercingPatternDir; + iName = "piercingPattern" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasPiercingPattern) { // iDir = marketStructure.signalKeyBarPatternDir; - iName = "SignalKey_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + iName = "signalKeyBarPattern" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); } // @@ -1521,6 +1599,14 @@ void HandleSignalLookup(XOHCL &bar) : X_PRICE_HIGH; iPrice = bar.GetPrice(iPriceType); + // + has = HasDirection(iDir); + } + + // + // Validate Patterns based on MA Band ... + if (has) + { // // Retrieve MA Band for Validation ... double iMABandUpper = fima2Signaller.fimaHelper.GetMABandUpper(barIndex); @@ -1531,111 +1617,177 @@ void HandleSignalLookup(XOHCL &bar) has = isBullish ? iPrice < iMABandLower : iPrice > iMABandUpper; + } - // - // Check Support and Resistance ... + // + // Select a Zone which Price inside it ... + // + // Validate Happens in Zone ... + int insideZoneIDX = -1; + has = has && + (isBullish + ? HasInside( + insideZoneIDX, + bar, + supports // + ) + : HasInside( + insideZoneIDX, + bar, + resistances // + )); + + // + // Validate Selected Inside Zone ... + // whith Bars Edge ... + has = IsValidIndex(insideZoneIDX); + if (has) + { // - // Support ... - bool hasSupport = marketStructure.support.IsValid(); - if (hasSupport) + if (isBullish) { - // - AddIfNotExists( - marketStructure.support, - supports // - ); - - // - XCBoxObject *iObj; - has = fima2Signaller.poiDrawer.DrawBox( - marketStructure.support, - iObj); - if (has) - { - } + iZone = supports[insideZoneIDX]; + } + else + { + iZone = resistances[insideZoneIDX]; } // - // Resistance ... - bool hasResistance = marketStructure.resistance.IsValid(); - if (hasResistance) - { - // - AddIfNotExists( - marketStructure.resistance, - resistances // - ); - - // - XCBoxObject *iObj; - has = fima2Signaller.poiDrawer.DrawBox( - marketStructure.resistance, - iObj); - if (has) - { - } - } - - // - // Validate Happens in Zone ... - int insideZoneIDX = -1; - has = has && - (isBullish - ? HasInside( - insideZoneIDX, - bar, - supports // - ) - : HasInside( - insideZoneIDX, - bar, - resistances // - )) && - IsValidIndex(insideZoneIDX); - - // - if (has) - { - // - int iWidth = 1; - int iCode = 159; - color iClr = isBullish - ? clrYellow - : clrDarkOrange; - ENUM_ARROW_ANCHOR iAnchor = isBullish - ? ANCHOR_TOP - : ANCHOR_BOTTOM; - XCBarArrowObject *iObj; - has = fima2Signaller.poiDrawer.DrawBarArrow( - bar, - iObj, - iPriceType, - iCode, - iClr, - iWidth, - iAnchor, - iName, - true, // Ignore Bar Tag ... - 10 // Threshold ... - ); - if (has) - { - } - } + has = isBullish + ? bar.high > supports[insideZoneIDX].upper + : bar.low < resistances[insideZoneIDX].lower; } // // Checking Liquidities ... // + // Draw Selected and Validated Bar and Selected Zone ... if (has) { + // + int iWidth = 1; + int iCode = 159; + color iClr = isBullish + ? clrYellow + : clrDarkOrange; + ENUM_ARROW_ANCHOR iAnchor = isBullish + ? ANCHOR_TOP + : ANCHOR_BOTTOM; + + // + XCBoxObject *iZoneObj; + XCBarArrowObject *iPatternObj; + + // + has = fima2Signaller.poiDrawer.DrawBarArrow( + bar, + iPatternObj, + iPriceType, + iCode, + iClr, + iWidth, + iAnchor, + iName, + true, // Ignore Bar Tag ... + 10 // Threshold ... + ); + if (has) + { + } + + // + has = fima2Signaller.poiDrawer.DrawBox( + iZone, + iZoneObj, + true, // Ignore At ... + iZone.type // Name ... + ); + if (has) + { + // + XPOIStyle iStyle; + fima2Signaller.poiDrawer.GetBoxStyle( + iStyle, + iZone.dir // + ); + iStyle.width = 2; + iStyle.clr = iClr; + fima2Signaller.poiDrawer.ApplyBoxStyle( + iZoneObj, + iStyle // + ); + } + } + + // + // Preparing Signal ... + if (has) + { + // + iSignal.time = bar.time; + iSignal.provider = "XFima"; + iSignal.symbol = bar.symbol; + iSignal.period = bar.period; + iSignal.mode = X_ORDER_MODE_MARKET; + iSignal.entry = GetEntry(bar.symbol, iDir); + iSignal.type = isBullish + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + + // + iSignal.volume = 0.01; + + // + double _r2r = 2.0; + double _slDistanceInPoint = 5; + double _point = GetPoints(iSignal.symbol); + double _riskDistance = _slDistanceInPoint * _point; + double _risk = _riskDistance + MathAbs((isBullish ? iZone.lower : iZone.upper) - iSignal.entry); + double _reward = GetSpread(iSignal.symbol) + (_risk * _r2r); + + // + double sl = isBullish + ? iSignal.entry - _risk + : iSignal.entry + _risk; + double tp = isBullish + ? iSignal.entry + _reward + : iSignal.entry - _reward; + + // + iSignal.sl = sl; + iSignal.tp = tp; + + // + has = iSignal.IsValid(); + if (has) + { + // + XCSignalObject *iSignalObj; + has = fima2Signaller.poiDrawer.DrawSignal( + iSignal, + iSignalObj, + 7 // + ); + } + } + + // + // For Logging ... + if (has) + { + // + ENUM_X_SIGNAL_EXECUTION_RESULT eResult; + has = eaExpert.eaTrader.ExecuteSignal(iSignal, eResult); Print("Detect a Potential Place for Price Movement: ", ToXString(iDir), ", Time: ", bar.time); } // // Cleanup Resources ... + iZone.Clean(); + iSignal.Clean(); SpecifiedClean(supports); SpecifiedClean(resistances); }