diff --git a/Experts/x-saherelm.xfima.backtester.ea.mq5 b/Experts/x-saherelm.xfima.backtester.ea.mq5 index eb4234cd..69a02530 100644 --- a/Experts/x-saherelm.xfima.backtester.ea.mq5 +++ b/Experts/x-saherelm.xfima.backtester.ea.mq5 @@ -457,7 +457,7 @@ void OnTick() fima2Signaller.OnTick(); // - // AnalyseMarket(1); + AnalyseMarket(1); } // @@ -611,14 +611,24 @@ void OnSignalTriggered(XSignal &signal) return; } + // + // TODO: Fix this ... + return; + // // Draw Signal on Chart ... - // XCSignalObject *iSignalObj; - // bool has = fima2Signaller.poiDrawer.DrawSignal( - // signal, - // iSignalObj, - // 7 // - // ); + XCSignalObject *iSignalObj; + bool has = fima2Signaller.poiDrawer.DrawSignal( + signal, + iSignalObj, + 7 // + ); + + // + if (has) + { + Print("Signal Issued: ", signal.GetObjectID()); + } // // Try to Execute Signal ... @@ -626,29 +636,29 @@ void OnSignalTriggered(XSignal &signal) // // Draw Signal Vertical Line ... - // - CChartObjectVLine *iObj = new CChartObjectVLine(); + // // + // CChartObjectVLine *iObj = new CChartObjectVLine(); - // - string iName = signal.GetTag(); - color iColor = IsLong(signal.type) ? clrLime : clrRed; + // // + // string iName = signal.GetObjectID(); + // color iColor = IsLong(signal.type) ? clrLime : clrRed; - // - bool has = iObj.Create( - fima2Signaller.poiDrawer.ChartIdentification(), - iName, - fima2Signaller.poiDrawer.SubWindowIdentification(), - signal.time // - ); - if (has) - { - // - iObj.Width(2); - iObj.Color(iColor); + // // + // bool has = iObj.Create( + // fima2Signaller.poiDrawer.ChartIdentification(), + // iName, + // fima2Signaller.poiDrawer.SubWindowIdentification(), + // signal.time // + // ); + // if (has) + // { + // // + // iObj.Width(2); + // iObj.Color(iColor); - // - // eaDraws.Add(iObj); - } + // // + // // eaDraws.Add(iObj); + // } // // // // Alert Issued Signal ... @@ -913,7 +923,8 @@ void AnalyseMarket(int barIndex = 0) ); // - // HandleSignalLookup(bar); + // XFIMASIgballer2First(bar); + HandleLookupSignal(bar); // bar.Clean(); @@ -922,7 +933,7 @@ void AnalyseMarket(int barIndex = 0) // // Handle Signal Looking Up ... // Register it as XFIMA Signaller 2 ... -void HandleSignalLookup(XOHCL &bar) +void XFIMASIgballer2First(XOHCL &bar) { // bool has = @@ -1805,4 +1816,98 @@ void HandleSignalLookup(XOHCL &bar) SpecifiedClean(resistances); } +// +void HandleLookupSignal(XOHCL &bar) +{ + // + bool has = + bar.IsValid(); + if (!has) + { + return; + } + + // + XBoxZone iZone; + XSignal iSignal; + string iName = NULL; + bool isBullish = false; + bool isBearish = false; + int barIndex = bar.Index(); + double iPrice = EMPTY_VALUE; + XFIMAConditions fimaConditions; + ENUM_X_PRICE iPriceType = X_PRICE_NONE; + ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + + // + int cIDX = 0; + int pIDX = cIDX + 1; + + // + // Check for a Cross ... + + // + // fima2Signaller.fimaHelper.Update(barIndex); + has = fima2Signaller.fimaHelper.GetConditions( + fimaConditions, + barIndex, + 5 // + ); + + // + double cSlowMA = fimaConditions.maSlowBuffer[cIDX]; + double pSlowMA = fimaConditions.maSlowBuffer[pIDX]; + + // + double cMAUpper = fimaConditions.maBandUpperBuffer[cIDX]; + double cMALower = fimaConditions.maBandLowerBuffer[cIDX]; + + // + double pMAUpper = fimaConditions.maBandUpperBuffer[pIDX]; + double pMALower = fimaConditions.maBandLowerBuffer[pIDX]; + + // + bool isCrossedOver = cSlowMA > cMALower && + pSlowMA < pMALower; + + // + bool isCrossedUnder = cSlowMA < cMAUpper && + cSlowMA > pMAUpper; + + // + has = isCrossedOver || + isCrossedUnder; + if (!has) + { + // + isBullish = false; + isBearish = false; + iDir = X_DIRECTION_NONE; + } + + // + if (has) + { + // + isBullish = isCrossedOver; + isBearish = isCrossedUnder; + } + + // + iDir = (isBullish && !isBearish) + ? X_DIRECTION_BULLISH + : (isBearish && !isBullish) + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + has = HasDirection(iDir); + if (has) + { + Print("Conditions Detected ..."); + } + + // + // Cleanup Resources ... + fimaConditions.Clean(); +} + // \ No newline at end of file diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index 2fd18e10..7fef5402 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -1821,6 +1821,29 @@ struct XSignal return result; } + // + string GetObjectID() + { + // + string result = ""; + + // + if (!IsValid()) + { + return result; + } + + // + result = "XSignal_" + + symbol + "_" + + ToXString(period) + "_" + + ToXString(type) + "_" + + ToXString(TimeToSeconds(time)); + + // + return result; + } + // // Retrieve String Representation of Signal ... string ToString() diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index 66b249d6..70860638 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -631,11 +631,13 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; // + XPivot pvPivots[]; string pvTrendName = "XXIFMA2PVTrend"; CChartObjectTrend *pvTrendLine = NULL; ENUM_X_DIRECTION pvTrend = X_DIRECTION_NONE; // + XPivot zgPivots[]; string zgTrendName = "XFIMA2ZGTrend"; CChartObjectTrend *zgTrendLine = NULL; ENUM_X_DIRECTION zgTrend = X_DIRECTION_NONE; @@ -870,12 +872,12 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Pivots ... XPivot pivots[]; - int pivotsCount = poiDetector.ExtractPVPivots( + count = poiDetector.ExtractPVPivots( pivots, barIndex, 50 // ); - has = IsValidSize(pivotsCount); + has = IsValidSize(count); // // Sort ... @@ -1048,10 +1050,9 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller if (has) { // - CArrayObj *drawnPivots = new CArrayObj(); - pivotsCount = poiDrawer.DrawPivots( + Copy( pivots, - drawnPivots // + pvPivots // ); } @@ -1068,7 +1069,6 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Support ... XBoxZone supportBox; - // XCBoxObject *iSupportObj; has = structure.zigzagAnalysis.HasSupportBox(supportBox); if (has) { @@ -1078,32 +1078,11 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller supportBox, supports // ); - // has = poiDrawer.DrawBox( - // supportBox, - // iSupportObj, - // true, // Ignore At ... - // supportBox.type // Name ... - // ); - // if (has) - // { - // // - // XPOIStyle iStyle; - // poiDrawer.GetBoxStyle( - // iStyle, - // supportBox.dir // - // ); - // poiDrawer.ApplyBoxStyle( - // iSupportObj, - // iStyle // - // ); - // iStyle.Clean(); - // } } // // Resistance ... XBoxZone resistanceBox; - // XCBoxObject *iResistanceObj; has = structure.zigzagAnalysis.HasResistanceBox(resistanceBox); if (has) { @@ -1113,37 +1092,17 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller resistanceBox, supports // ); - // has = poiDrawer.DrawBox( - // resistanceBox, - // iResistanceObj, - // true, // Ignore At ... - // resistanceBox.type // Name ... - // ); - // if (has) - // { - // // - // XPOIStyle iStyle; - // poiDrawer.GetBoxStyle( - // iStyle, - // resistanceBox.dir // - // ); - // poiDrawer.ApplyBoxStyle( - // iResistanceObj, - // iStyle // - // ); - // iStyle.Clean(); - // } } // // Pivots ... XPivot pivots[]; - int pivotsCount = poiDetector.ExtractZigZagPivots( + count = poiDetector.ExtractZigZagPivots( pivots, barIndex, 10 // ); - has = IsValidSize(pivotsCount); + has = IsValidSize(count); // // Sort ... @@ -1316,10 +1275,9 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller if (has) { // - CArrayObj *drawnPivots = new CArrayObj(); - pivotsCount = fima2Signaller.poiDrawer.DrawPivots( + Copy( pivots, - drawnPivots // + zgPivots // ); } @@ -1427,7 +1385,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Do all Draws Here ... - bool canDraw = true; + bool canDraw = false; if (canDraw) { // @@ -1547,6 +1505,33 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // TrendLines ... + // + // Pivots ... + + // + has = HasChild(pvPivots); + if (has) + { + // + CArrayObj *drawnPivots = new CArrayObj(); + count = poiDrawer.DrawPivots( + pvPivots, + drawnPivots // + ); + } + + // + has = HasChild(zgPivots); + if (has) + { + // + CArrayObj *drawnPivots = new CArrayObj(); + count = poiDrawer.DrawPivots( + zgPivots, + drawnPivots // + ); + } + // // Patterns Bar ... has = HasDirection(iDir); @@ -1582,6 +1567,12 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller { // // TODO: Provided SL ... + double _point = GetPoints(bar.symbol); + double slAddition = 5 * _point; + double slPrice = + isBullish + ? iZone.lower - slAddition + : iZone.upper + slAddition; // // Prepare Founded Signal ... @@ -1589,7 +1580,10 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller has = PrepareSignal( signal, iDir, - targets // + targets, + 0, // Use Default R2R ... + slPrice, // Provided Price for SL ... + 0 // Specified Risk in Point .... ); if (has) { @@ -1606,6 +1600,8 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller signal.Clean(); structure.Clean(); fimaConditions.Clean(); + SpecifiedClean(pvPivots); + SpecifiedClean(zgPivots); SpecifiedClean(supports); SpecifiedClean(resistances); }