From a5cb716d0be735c25cb790b0b776c5fdbed34d20 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 21 Jun 2024 06:45:33 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x121.setup.class.mq5 | 1056 +++++++---------------- Classes/x-saherelm.x121.setup.xea.mq5 | 9 +- Classes/x-saherelm.xea.class.mq5 | 23 +- Classes/x-saherelm.xsctrend.class.mq5 | 138 ++- Documents/BKP/usefull.mq5 | 731 ++++++++++++++++ Documents/Supporting.Doc.md | 39 + Libraries/x-saherelm.draw.lib.mq5 | 33 + 7 files changed, 1268 insertions(+), 761 deletions(-) create mode 100644 Documents/Supporting.Doc.md diff --git a/Classes/x-saherelm.x121.setup.class.mq5 b/Classes/x-saherelm.x121.setup.class.mq5 index 524fc362..fae874de 100644 --- a/Classes/x-saherelm.x121.setup.class.mq5 +++ b/Classes/x-saherelm.x121.setup.class.mq5 @@ -2754,7 +2754,7 @@ struct X121SignalGenerator // XSCZonesInput zonesInput; - zonesInput.length = 71; + zonesInput.length = 26; zonesInput.numberOfZones = 10; // @@ -2847,28 +2847,35 @@ struct X121SignalGenerator signal.trend.IsValid(); // - XSignal rSignal; // Recovery Signal ... + datetime prevTime = iTime( + signal.symbol, + signal.period, + 1 // + ); // - double rSL = 0; // Recovery Stop Loss ... - double rTP = 0; // Recovery Take Profit ... - double rEntry = 0; // Recovery Entry Point ... - double rVolume = signal.volume * 2; // Recovery Volume ... - ENUM_POSITION_TYPE rType; // Recovery Signal Type ... - ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ... - bool isSignalPrepared = false; // Check Signal Preparation Succeed ... + datetime cTime = TimeCurrent(); // - bool condition = false; - double exitPrice = GetExit(signal.symbol, signal.type); - double entryPrice = GetEntry(signal.symbol, signal.type); + string entryLineName = "sEntry" + signal.symbol; + DrawTrendLine( + 0, + entryLineName, + 0, + prevTime, + signal.entry, + cTime, + signal.entry, + clrYellow, + STYLE_SOLID, + 2, + false, + false, + true // + ); // - double onePointValue = PointToPrice(1, signal.symbol); - - // - double directionalVolumeMultiplier = 1; - double inDirectionalVolumeMultiplier = 2; + double tmpPivots[]; // if (canUseCF) @@ -2879,730 +2886,63 @@ struct X121SignalGenerator XOHCL cfBEARBar = signal.cf.GetBearishBar(); // - if (isLong) - { - // - // Supports For Longs ... - - // - // CF Bullish ... - - // - // HIGH ... - - // - condition = entryPrice < cfBULLBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.high; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice > cfBULLBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.high; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - // LOW ... - - // - condition = entryPrice > cfBULLBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.low; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice < cfBULLBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.low; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - // CF Bearish ... - - // - // HIGH ... - - // - condition = entryPrice < cfBEARBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.high; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice > cfBEARBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.high; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - // LOW ... - - // - condition = entryPrice > cfBEARBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.low; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice < cfBEARBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.low; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - } - else - { - // - // Supports For Shorts ... - - // - // CF Bullish ... - - // - // HIGH ... - - // - condition = entryPrice < cfBULLBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.high; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice > cfBULLBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.high; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - // LOW ... - - // - condition = entryPrice > cfBULLBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.low; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice < cfBULLBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBULLBar.low; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - // CF Bearish ... - - // - // HIGH ... - - // - condition = entryPrice < cfBEARBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.high; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice > cfBEARBar.high; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.high; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - // LOW ... - - // - condition = entryPrice > cfBEARBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.low; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - condition = entryPrice < cfBEARBar.low; - if (condition) - { - // - // InDirectional ... - rEntry = cfBEARBar.low; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * inDirectionalVolumeMultiplier; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - XEQMSupportToken + XINDirectionalToken, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - } + Add( + cfBULLBar.high, + tmpPivots // + ); + Add( + cfBULLBar.low, + tmpPivots // + ); + Add( + cfBEARBar.high, + tmpPivots // + ); + Add( + cfBEARBar.low, + tmpPivots // + ); + + // + signal.cf.Remove(); } // if (canUseTrend) { + // signal.trend.Draw(); + + // + // Lows ... + Add( + signal.trend.GetLows(), + tmpPivots // + ); + + // + // Highs ... + Add( + signal.trend.GetHighs(), + tmpPivots // + ); + + // + // Support ... + Add( + signal.trend.GetSupport(), + tmpPivots // + ); + + // + // Resistance ... + Add( + signal.trend.GetResistance(), + tmpPivots // + ); + + // + signal.trend.Remove(); } // @@ -3613,17 +2953,77 @@ struct X121SignalGenerator // // Find Hot Zones ... - + for (int i = 0; i < signal.zones.CountZones(); i++) + { + // + // Retrieve Indexed Zone ... + XSCZone *iZone = signal.zones.GetZone(i); + + // + // Check Zone is Hot Zone or not ... + bool isHotZone = false; + for (int j = 0; j < ArraySize(hotLevels); j++) + { + // + isHotZone = (iZone.percent / 100) >= hotLevels[j]; + if (isHotZone) + { + break; + } + } + + // + // Prevent Moving Forward if there isn't Hot Zone ... + if (!isHotZone) + { + continue; + } + + // + // Zone High ... + Add( + iZone.high, + tmpPivots // + ); + + // + // Zone Low ... + Add( + iZone.low, + tmpPivots // + ); + } + + // + signal.zones.Remove(); } // - signal.cf.Remove(); - signal.trend.Remove(); - signal.zones.Remove(); + XSignal supports[]; + int indirectionalsCount = + PrepareInDirectionalSupportSignals( + supports, + signal, + tmpPivots // + ); + if (IsValidSize(indirectionalsCount)) + { + // + Copy( + supports, + signal.supports // + ); + + // + Clean(supports); + } + + // + RemoveDraws(entryLineName); } // - bool UpdateSupportSignals( + bool PrepareDirectionalSupportSignals( XPosition &support, XPosition &parent, XSignal &result // @@ -3720,6 +3120,182 @@ struct X121SignalGenerator return mResult; } + // + int PrepareInDirectionalSupportSignals( + XSignal &supports[], + XSignal &source, + double &pivots[] // + ) + { + // + int result = 0; + + // + Clean(supports); + + // + int pivotsCount = ArraySize(pivots); + if (!IsValidSize(pivotsCount)) + { + return result; + } + + // + bool isLong = IsLong(source.type); + + // + XSignal rSignal; // Recovery Signal ... + + // + double rSL = 0; // Recovery Stop Loss ... + double rTP = 0; // Recovery Take Profit ... + double rEntry = 0; // Recovery Entry Point ... + double rVolume = 0; // Recovery Volume ... + ENUM_POSITION_TYPE rType; // Recovery Signal Type ... + ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ... + bool isSignalPrepared = false; // Check Signal Preparation Succeed ... + + // + bool condition = false; + + // + double onePointValue = PointToPrice(1, source.symbol); + + // + double directionalVolumeMultiplier = 1; + double inDirectionalVolumeMultiplier = 2; + + // + // if Long we are Looking for lower prices than + // entry price and vise verse ... + + // + for (int i = 0; i < pivotsCount; i++) + { + // + double iPivot = pivots[i]; + + // + bool isValidPrice = + isLong + ? source.entry > iPivot + : source.entry < iPivot; + if (!isValidPrice) + { + continue; + } + + // + // InDirectional ... + if (isLong) + { + // + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_STOP; + } + else + { + // + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_STOP; + } + + // + rEntry = iPivot; + rVolume = source.volume; + + // + isSignalPrepared = rSignal.Prepare( + source.symbol, + XEQMSupportToken + XINDirectionalToken, + source.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + + // + // Here we Create Related Directional Order ... + + // + // Directional ... + if (isLong) + { + // + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_LIMIT; + } + else + { + // + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_LIMIT; + } + + // + rEntry = source.entry; + rVolume = source.volume; + + // + isSignalPrepared = rSignal.Prepare( + source.symbol, + XEQMSupportToken + XDirectionalToken, + source.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + + // + if (isSignalPrepared) + { + // + AddRef( + rSignal, + supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + } + + // + result = ArraySize(supports); + + // + return result; + } + // string GetTag() { diff --git a/Classes/x-saherelm.x121.setup.xea.mq5 b/Classes/x-saherelm.x121.setup.xea.mq5 index d456503d..b52ac745 100644 --- a/Classes/x-saherelm.x121.setup.xea.mq5 +++ b/Classes/x-saherelm.x121.setup.xea.mq5 @@ -4032,7 +4032,7 @@ public: // Handle Support of Supports here ... void OnPositionsChangedHandler(int count) override { - EQMHandleSupportProtection(count); + // EQMHandleSupportProtection(count); } // @@ -4784,9 +4784,8 @@ private: } // - bool isDIRInDIRSupport = position.provider == XEQMSupportToken + XDirectionalToken || - position.provider == XEQMSupportToken + XINDirectionalToken; - if (!isDIRInDIRSupport) + bool isINDIRSupport = position.provider == XEQMSupportToken + XINDirectionalToken; + if (!isINDIRSupport) { return; } @@ -4828,7 +4827,7 @@ private: // XSignal signal; X121SignalGenerator signalGenerator; - bool hasSupport = signalGenerator.UpdateSupportSignals( + bool hasSupport = signalGenerator.PrepareDirectionalSupportSignals( position, parent, signal // diff --git a/Classes/x-saherelm.xea.class.mq5 b/Classes/x-saherelm.xea.class.mq5 index f3c469de..8c6fb145 100644 --- a/Classes/x-saherelm.xea.class.mq5 +++ b/Classes/x-saherelm.xea.class.mq5 @@ -1099,16 +1099,16 @@ protected: // // Check At Least One Support Positions Open For Hedging ... - XPosition supports[]; - int supportsCount = ExtractSupports( - positions, - supports // - ); - result = IsValidSize(supportsCount); - if (!result) - { - return result; - } + // XPosition supports[]; + // int supportsCount = ExtractSupports( + // positions, + // supports // + // ); + // result = IsValidSize(supportsCount); + // if (!result) + // { + // return result; + // } // double profits = SpecifiedCalculatePositionsProfit(positions); @@ -1139,6 +1139,9 @@ protected: return result; } + // + SyncSupports(); + // string message = XEQMSupportToken + " Hedge: " + ToString(profits) + " ..."; diff --git a/Classes/x-saherelm.xsctrend.class.mq5 b/Classes/x-saherelm.xsctrend.class.mq5 index 8fce72e9..9b2e096e 100644 --- a/Classes/x-saherelm.xsctrend.class.mq5 +++ b/Classes/x-saherelm.xsctrend.class.mq5 @@ -120,7 +120,8 @@ public: // // Deconstructor ... - void ~XSCTrend() { + void ~XSCTrend() + { Remove(); } @@ -340,6 +341,77 @@ public: return result; } + // + // Retrieve Chart Line Values ... + + // + // Get Lows Line Price at Specific Time ... + double GetLows(datetime time = NULL) + { + // + double result = 0; + + // + result = GetObjectPrice( + lowsName, + time // + ); + + // + return result; + } + + // + // Get Highs Line Price at Specific Time ... + double GetHighs(datetime time = NULL) + { + // + double result = 0; + + // + result = GetObjectPrice( + highsName, + time // + ); + + // + return result; + } + + // + // Get Support Line Price at Specific Time ... + double GetSupport(datetime time = NULL) + { + // + double result = 0; + + // + result = GetObjectPrice( + supportName, + time // + ); + + // + return result; + } + + // + // Get Resistance Line Price at Specific Time ... + double GetResistance(datetime time = NULL) + { + // + double result = 0; + + // + result = GetObjectPrice( + resistanceName, + time // + ); + + // + return result; + } + // // Remove Draws ... bool Remove( @@ -377,6 +449,7 @@ public: } // + // Draw Trend Object on Chart ... bool Draw( long chartId = 0, string prefix = NULL, @@ -438,7 +511,7 @@ public: secondSwingLowBar.time > secondSwingHighBar.time ? secondSwingHighBar.time : secondSwingLowBar.time; - string supportName = + supportName = // identifier + (IsSpecifiedValid(prefix) @@ -455,8 +528,7 @@ public: secondSwingLowBar.time > secondSwingHighBar.time ? secondSwingHighBar.time : secondSwingLowBar.time; - - string resistanceName = + resistanceName = // identifier + (IsSpecifiedValid(prefix) @@ -474,7 +546,7 @@ public: // double oldLow = secondSwingLowBar.low; datetime oldLowTime = secondSwingLowBar.time; - string lowsName = + lowsName = // identifier + (IsSpecifiedValid(prefix) @@ -492,7 +564,7 @@ public: // double oldHigh = secondSwingHighBar.high; datetime oldHighTime = secondSwingHighBar.time; - string highsName = + highsName = // identifier + (IsSpecifiedValid(prefix) @@ -598,6 +670,53 @@ public: // // Protected ... protected: + // + // Tools ... + + // + double GetObjectPrice( + string objName, + datetime objTime, + long chartId = 0, + int subWindow = 0 // + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + if (!IsSpecifiedValid(objName)) + { + return result; + } + + // + objTime = NormalizeTime(objTime); + + // + string objectName = FindObjectName( + objName, + chartId, + subWindow // + ); + + // + result = ObjectGetValueByTime( + chartId, + objectName, + objTime // + ); + + // + return result; + } + // // Private ... private: @@ -615,6 +734,13 @@ private: XOHCL secondSwingLowBar; XOHCL firstSwingHighBar; XOHCL secondSwingHighBar; + + // + // Object Names ... + string lowsName; + string highsName; + string supportName; + string resistanceName; }; // \ No newline at end of file diff --git a/Documents/BKP/usefull.mq5 b/Documents/BKP/usefull.mq5 index 1caa21f5..7de7e904 100644 --- a/Documents/BKP/usefull.mq5 +++ b/Documents/BKP/usefull.mq5 @@ -2339,3 +2339,734 @@ rEntry = 0; isSignalPrepared = false; } + +/////////////////////////////////////////////////////////////////////// + + // + if (canUseCF) + { + // + signal.cf.Draw(); + XOHCL cfBULLBar = signal.cf.GetBullishBar(); + XOHCL cfBEARBar = signal.cf.GetBearishBar(); + + // + if (isLong) + { + // + // Supports For Longs ... + + // + // CF Bullish ... + + // + // HIGH ... + + // + condition = entryPrice < cfBULLBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.high; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice > cfBULLBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.high; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + // LOW ... + + // + condition = entryPrice > cfBULLBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.low; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice < cfBULLBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.low; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + // CF Bearish ... + + // + // HIGH ... + + // + condition = entryPrice < cfBEARBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.high; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice > cfBEARBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.high; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + // LOW ... + + // + condition = entryPrice > cfBEARBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.low; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice < cfBEARBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.low; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + } + else + { + // + // Supports For Shorts ... + + // + // CF Bullish ... + + // + // HIGH ... + + // + condition = entryPrice < cfBULLBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.high; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice > cfBULLBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.high; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + // LOW ... + + // + condition = entryPrice > cfBULLBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.low; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice < cfBULLBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBULLBar.low; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + // CF Bearish ... + + // + // HIGH ... + + // + condition = entryPrice < cfBEARBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.high; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice > cfBEARBar.high; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.high; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + // LOW ... + + // + condition = entryPrice > cfBEARBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.low; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + + // + condition = entryPrice < cfBEARBar.low; + if (condition) + { + // + // InDirectional ... + rEntry = cfBEARBar.low; + rType = POSITION_TYPE_BUY; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * inDirectionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken + XINDirectionalToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + } + } + } diff --git a/Documents/Supporting.Doc.md b/Documents/Supporting.Doc.md new file mode 100644 index 00000000..84abf394 --- /dev/null +++ b/Documents/Supporting.Doc.md @@ -0,0 +1,39 @@ +# Supporting Senarios + +first check current Position Direction's + +## Short + +InDirectional +for short positions we only have Long Supports; +entry price must below the Lines; +and Lines Must below the SL of Positions, if it's Exists; + +### Long Orders + +after putting orders of InDirectionals; +set EQM Provider; + +### Long Orders Supporting + +now we have to find out when orders Executed; +after each InDirectional EQM Order Execution, we Have to Prepare a Directional Order +by it's volume on Signal Entry. + +## Long + +InDirectional +for long positions we only have short Supports; +entry price must above the Lines; +and Lines Must Above the SL of Positions, if it's Exists; + +### Short Orders + +after putting orders of InDirectionals; +set EQM Provider; + +### Short Orders Supporting + +now we have to find out when orders Executed; +after each InDirectional EQM Order Execution, we Have to Prepare a Directional Order +by it's volume on Signal Entry. diff --git a/Libraries/x-saherelm.draw.lib.mq5 b/Libraries/x-saherelm.draw.lib.mq5 index 2bdaf10d..cf58a7ac 100644 --- a/Libraries/x-saherelm.draw.lib.mq5 +++ b/Libraries/x-saherelm.draw.lib.mq5 @@ -485,6 +485,39 @@ bool IsDrawExists( return result; } +// +// Find Specific Object Name ... +string FindObjectName( + string suggest, + long chartId = 0, + int subWindow = 0 // +) +{ + // + string result = NULL; + + // + int objectsCount = ObjectsTotal(chartId, subWindow); + if (objectsCount <= 0) { + return result; + } + + // + for (int i = objectsCount - 1; i >= 0; i--) { + // + string iObjectName = ObjectName(chartId, i, subWindow); + bool isExists = StringFind(iObjectName, suggest) >= 0; + if (isExists) { + // + result = iObjectName; + break; + } + } + + // + return result; +} + // // Regular Draws ...