diff --git a/Experts/x-saherelm.xom1.ea.mq5 b/Experts/x-saherelm.xom1.ea.mq5 index ccd43920..86d4d859 100644 --- a/Experts/x-saherelm.xom1.ea.mq5 +++ b/Experts/x-saherelm.xom1.ea.mq5 @@ -195,6 +195,18 @@ int OnInit() eaExpert.eaSaveLosts = eaSaveLosts; eaExpert.eaSaveRestrictions = eaSaveRestrictions; + // + // Attach Event Handlers ... + eaExpert.AddOnDealsChangedEventHandler(OnDealsChanged); + eaExpert.AddOnStopLossEventHandler(OnStopLossTriggered); + eaExpert.AddOnOrdersChangedEventHandler(OnOrdersChanged); + eaExpert.AddOnTakeProfitEventHandler(OnTakeProfitTriggered); + eaExpert.AddOnModifyPositionEventHandler(OnPositionModified); + eaExpert.AddOnPositionsChangedEventHandler(OnPositionsChanged); + eaExpert.AddOnTradeStateChangedEventHandler(OnTradeStateChanged); + eaExpert.AddOnForceClosePositionEventHandler(OnPositionForceClosed); + eaExpert.AddOnPartialClosePositionEventHandler(OnPositionPartialClosed); + // // Try to Initialize eaExpert ... bool isInited = eaExpert.HandleOnInit(); @@ -278,7 +290,7 @@ void OnChartEvent( */ void OnStopLossTriggered(const XDeal &deal) { - // eaExpert.HandleOnStopLossTriggered(deal); + eaExpert.HandleOnStopLossTriggered(deal); } /** @@ -288,7 +300,7 @@ void OnStopLossTriggered(const XDeal &deal) */ void OnTakeProfitTriggered(const XDeal &deal) { - // eaExpert.HandleOnTakeProfitTriggered(deal); + eaExpert.HandleOnTakeProfitTriggered(deal); } /** @@ -305,11 +317,11 @@ void OnPositionForceClosed( ) { // - // eaExpert.HandleOnPositionForceClosed( - // ticket, - // position, - // comment // - // ); + eaExpert.HandleOnPositionForceClosed( + ticket, + position, + comment // + ); } /** @@ -319,7 +331,7 @@ void OnPositionForceClosed( */ void OnDealsChanged(int count) { - // eaExpert.HandleOnDealsChanged(count); + eaExpert.HandleOnDealsChanged(count); } /** @@ -329,7 +341,7 @@ void OnDealsChanged(int count) */ void OnOrdersChanged(int count) { - // eaExpert.HandleOnOrdersChanged(count); + eaExpert.HandleOnOrdersChanged(count); } /** @@ -339,7 +351,7 @@ void OnOrdersChanged(int count) */ void OnPositionsChanged(int count) { - // eaExpert.HandleOnPositionsChanged(count); + eaExpert.HandleOnPositionsChanged(count); } /** @@ -356,11 +368,11 @@ void OnPositionModified( ) { // - // eaExpert.HandleOnPositionModified( - // ticket, - // profit, - // comment // - // ); + eaExpert.HandleOnPositionModified( + ticket, + profit, + comment // + ); } /** @@ -377,11 +389,11 @@ void OnPositionPartialClosed( ) { // - // eaExpert.HandleOnPositionPartialClosed( - // ticket, - // profit, - // comment // - // ); + eaExpert.HandleOnPositionPartialClosed( + ticket, + profit, + comment // + ); } /** @@ -391,7 +403,7 @@ void OnPositionPartialClosed( */ void OnTradeStateChanged(const XOnTradeHandlerState &state) { - // eaExpert.HandleOnTradeStateChanged(state); + eaExpert.HandleOnTradeStateChanged(state); } // diff --git a/XOM1EA/Classes/xom1ea.expert.class.mq5 b/XOM1EA/Classes/xom1ea.expert.class.mq5 index ec530a73..86cedd1a 100644 --- a/XOM1EA/Classes/xom1ea.expert.class.mq5 +++ b/XOM1EA/Classes/xom1ea.expert.class.mq5 @@ -543,7 +543,7 @@ class XCXOM1EAExpert : public XCBase // Configure Indicator ... XOM1Inputs iDZoneOMInputs; iDZoneOMInputs.Default(); - iDZoneOMInputs.showFiboZone = false; + iDZoneOMInputs.showFiboZone = true; // // Configure Signaller ... diff --git a/XOM1EA/Classes/xom1ea.signaller.class.mq5 b/XOM1EA/Classes/xom1ea.signaller.class.mq5 index 56dd7e67..65fb9279 100644 --- a/XOM1EA/Classes/xom1ea.signaller.class.mq5 +++ b/XOM1EA/Classes/xom1ea.signaller.class.mq5 @@ -257,85 +257,209 @@ class XCXOM1SignallerBase int p2Idx = pIdx + 1; // - // Check New Peak or Vale Happens ... - // New Peak Under Last ... - // New Vale Over Last ... - bool isValeReason = iConditions.valeBuffer[cIdx] > iConditions.valeBuffer[pIdx]; - bool isPeakReason = iConditions.peakBuffer[cIdx] < iConditions.peakBuffer[pIdx]; - has = isValeReason || isPeakReason; - if (!has) + // Check Zones Flags ... + bool checkPVZones = false; + bool checkMAZones = true; + + // + // Check PV Zones ... + if (checkPVZones) { // - iBar.Clean(); - iConditions.Clean(); - return; + // Check New Peak or Vale Happens ... + + // + // New Vale Over Last ... + bool isValeReason = iConditions.valeBuffer[cIdx] > iConditions.valeBuffer[pIdx]; + + // + // New Peak Under Last ... + bool isPeakReason = iConditions.peakBuffer[cIdx] < iConditions.peakBuffer[pIdx]; + + // + has = isValeReason || isPeakReason; + if (has) + { + // + // Prepare Reason ... + ENUM_XOM1_ZONE_REASON iReason = isValeReason + ? X_OM1_ZONE_REASON_VALE + : X_OM1_ZONE_REASON_PEAK; + + // + // Extract Upper / Lower Values ... + double iUpper = iConditions.peakBuffer[pIdx]; + double iLower = iConditions.valeBuffer[pIdx]; + + // + // Calculate Mid Range ... + double iMiddle = iLower + ((iUpper - iLower) / 2); + if (iMiddle > 0) + { + iMiddle = NormalizePrice(iMiddle, symbol); + } + + // + // Detect Reason Price ... + double iPrice = + isValeReason + ? iConditions.valeBuffer[cIdx] + : iConditions.peakBuffer[cIdx]; + if (iPrice > 0) + { + iPrice = NormalizePrice(iPrice, symbol); + } + + // + // Detect Reason Direction ... + ENUM_X_DIRECTION iDir = iPrice > iMiddle + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Try to Initialize Zone ... + XOM1Zone iZone; + has = iZone.Init( + symbol, + period, + name, // Signaller Name ... + iUpper, + iLower, + iPrice, + iDir, + iReason, + iConditions.bars[pIdx].time, // From ... + iConditions.bars[cIdx].time // To + ); + if (has) + { + // + // Add New Detected Zone to Zones ... + AddRef( + iZone, + zones // + ); + } + + // + iZone.Clean(); + } } // - // Prepare Reason ... - ENUM_XOM1_ZONE_REASON iReason = isValeReason - ? X_OM1_ZONE_REASON_VALE - : X_OM1_ZONE_REASON_PEAK; - - // - // Extract Upper / Lower Values ... - double iUpper = iConditions.peakBuffer[pIdx]; - double iLower = iConditions.valeBuffer[pIdx]; - - // - // Calculate Mid Range ... - double iMiddle = iLower + ((iUpper - iLower) / 2); - if (iMiddle > 0) - { - iMiddle = NormalizePrice(iMiddle, symbol); - } - - // - // Detect Reason Price ... - double iPrice = - isValeReason - ? iConditions.valeBuffer[cIdx] - : iConditions.peakBuffer[cIdx]; - if (iPrice > 0) - { - iPrice = NormalizePrice(iPrice, symbol); - } - - // - // Detect Reason Direction ... - ENUM_X_DIRECTION iDir = iPrice > iMiddle - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Try to Initialize Zone ... - XOM1Zone iZone; - has = iZone.Init( - symbol, - period, - name, // Signaller Name ... - iUpper, - iLower, - iPrice, - iDir, - iReason, - iConditions.bars[pIdx].time, // From ... - iConditions.bars[cIdx].time // To - ); - if (has) + // Check MA Zones ... + if (checkMAZones) { // - // Add New Detected Zone to Zones ... - AddRef( - iZone, - zones // - ); + // Crossed Over ... + bool isFastCrossedOverSlow = iConditions.maFastBuffer[cIdx] > iConditions.maSlowBuffer[cIdx] && + !(iConditions.maFastBuffer[pIdx] >= iConditions.maSlowBuffer[pIdx]); + + // + // Crossed Under ... + bool isFastCrossedUnderSlow = iConditions.maFastBuffer[cIdx] < iConditions.maSlowBuffer[cIdx] && + !(iConditions.maFastBuffer[pIdx] <= iConditions.maSlowBuffer[pIdx]); + + // + double iFast = iConditions.maFastBuffer[cIdx]; + double iSlow = iConditions.maSlowBuffer[cIdx]; + double iFibUpper = iConditions.fiboUpperBuffer[cIdx]; + double iFibLower = iConditions.fiboLowerBuffer[cIdx]; + + // + double iValues[] = { + iFast, + iSlow, + iFibUpper, + iFibLower // + }; + + // + // Extract Upper / Lower Values ... + double iUpper = GetMax(iValues); + double iLower = GetMin(iValues); + + // + has = isFastCrossedOverSlow || isFastCrossedUnderSlow; + + // + // Validate Cross Between Zone ... + if (has) + { + // + has = iFast >= iLower && + iFast <= iUpper && + iSlow >= iLower && + iSlow <= iUpper; + } + + // + if (has) + { + // + // Prepare Reason ... + ENUM_XOM1_ZONE_REASON iReason = isFastCrossedOverSlow + ? X_OM1_ZONE_REASON_FCOS + : X_OM1_ZONE_REASON_FCUS; + + // + // Calculate Mid Range ... + double iMiddle = iLower + ((iUpper - iLower) / 2); + if (iMiddle > 0) + { + iMiddle = NormalizePrice(iMiddle, symbol); + } + + // + // Detect Reason Price ... + double iPrice = iConditions.maFastBuffer[cIdx]; + if (iPrice > 0) + { + iPrice = NormalizePrice(iPrice, symbol); + } + + // + // Detect Reason Direction ... + ENUM_X_DIRECTION iDir = isFastCrossedOverSlow + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Try to Initialize Zone ... + XOM1Zone iZone; + has = iZone.Init( + symbol, + period, + name, // Signaller Name ... + iUpper, + iLower, + iPrice, + iDir, + iReason, + iConditions.bars[pIdx].time, // From ... + iConditions.bars[cIdx].time // To + ); + if (has) + { + // + // Add New Detected Zone to Zones ... + AddRef( + iZone, + zones // + ); + } + + // + iZone.Clean(); + } + + // + Clean(iValues); } // // Clean Resources ... iBar.Clean(); - iZone.Clean(); iConditions.Clean(); } @@ -419,7 +543,6 @@ class XCXOM1SignallerBase // } } - }; // \ No newline at end of file diff --git a/XOM1EA/Libraries/xom1ea.lib.mq5 b/XOM1EA/Libraries/xom1ea.lib.mq5 index e1a29a16..9652bb05 100644 --- a/XOM1EA/Libraries/xom1ea.lib.mq5 +++ b/XOM1EA/Libraries/xom1ea.lib.mq5 @@ -32,9 +32,11 @@ // Zone Creation Reason ... enum ENUM_XOM1_ZONE_REASON { - X_OM1_ZONE_REASON_NONE, - X_OM1_ZONE_REASON_PEAK, - X_OM1_ZONE_REASON_VALE + X_OM1_ZONE_REASON_NONE, // NONE + X_OM1_ZONE_REASON_PEAK, // PEAK + X_OM1_ZONE_REASON_VALE, // VALE + X_OM1_ZONE_REASON_FCOS, // FCOS + X_OM1_ZONE_REASON_FCUS, // FCUS }; /** @@ -65,31 +67,7 @@ bool IsXValid(ENUM_XOM1_ZONE_REASON value) */ string ToXString(ENUM_XOM1_ZONE_REASON value) { - // - string result = NULL; - - // - if (!IsXValid(value)) - { - return result; - } - - // - switch (value) - { - // - case X_OM1_ZONE_REASON_PEAK: - result = "PEAK"; - break; - - // - case X_OM1_ZONE_REASON_VALE: - result = "VALE"; - break; - } - - // - return result; + return EnumToString(value); } /** @@ -123,6 +101,14 @@ ENUM_XOM1_ZONE_REASON FromXString(string value) { result = X_OM1_ZONE_REASON_VALE; } + else if (value == ToXString(X_OM1_ZONE_REASON_FCOS)) + { + result = X_OM1_ZONE_REASON_FCOS; + } + else if (value == ToXString(X_OM1_ZONE_REASON_FCUS)) + { + result = X_OM1_ZONE_REASON_FCUS; + } // return result;