diff --git a/Classes/x-saherelm.x121.setup.class.mq5 b/Classes/x-saherelm.x121.setup.class.mq5 index ff6809e5..9914cca4 100644 --- a/Classes/x-saherelm.x121.setup.class.mq5 +++ b/Classes/x-saherelm.x121.setup.class.mq5 @@ -26,8 +26,6 @@ // #include "../Libraries/x-saherelm.xtrade.lib.mq5" #include "../Classes/x-saherelm.xalert.class.mq5" -#include "../Classes/x-saherelm.xsczone.class.mq5" -#include "../Classes/x-saherelm.xsctrend.class.mq5" // #include "../Helpers/x-saherelm.xpv.helper.mq5" @@ -2793,9 +2791,23 @@ struct X121SignalGenerator bool canUseTrend = trend.Init(tInputs); if (canUseTrend) { + // signal.trend = trend; } + // + XSCCFInput cfInputs; + cfInputs.Default(); + XSCCF *cf = new XSCCF( + signal.symbol, + signal.period // + ); + bool canUseCF = cf.Init(cfInputs); + if (canUseCF) + { + signal.cf = cf; + } + // // Generate Support Signals ... if (_useSupport) @@ -2827,7 +2839,10 @@ struct X121SignalGenerator bool isLong = IsLong(signal.type); // - bool canUseZones = signal.zones != NULL; + bool canUseCF = signal.cf != NULL && + signal.cf.IsValid(); + bool canUseZones = signal.zones != NULL && + signal.zones.IsValid(); bool canUseTrend = signal.trend != NULL && signal.trend.IsValid(); @@ -2844,6 +2859,7 @@ struct X121SignalGenerator bool isSignalPrepared = false; // Check Signal Preparation Succeed ... // + bool condition = false; double exitPrice = GetExit(signal.symbol, signal.type); double entryPrice = GetEntry(signal.symbol, signal.type); @@ -2851,520 +2867,852 @@ struct X121SignalGenerator double onePointValue = PointToPrice(1, signal.symbol); // - // Check Signal Has TP and SL ... - if (signal.tp > 0 && signal.sl > 0) - { - // - // Here we Can Provide Orders based on Signal TP and SL ... - - // - // Calculate TP/Entry Distance ... - double tpDistance = - isLong - ? signal.tp - signal.entry - : signal.entry - signal.tp; - - // - // Calculate Recovery Zone Step ... - double slDistance = - isLong - ? signal.entry - signal.sl - : signal.sl - signal.entry; - } + double directionalVolumeMultiplier = 1; + double inDirectionalVolumeMultiplier = 2; // - // Add Zone Based Signals ... - if (canUseZones) + if (canUseCF) { // - // signal.zones.DrawZones(); + signal.cf.Draw(); + XOHCL cfBULLBar = signal.cf.GetBullishBar(); + XOHCL cfBEARBar = signal.cf.GetBearishBar(); // - // Try to Find a Hot Level based on Signal Direction - // as Resistance ... - - // - for (int i = 0; i < signal.zones.CountZones(); i++) + if (isLong) { // - // Retrieve Indexed Zone ... - XSCZone *iZone = signal.zones.GetZone(i); + // Supports For Longs ... // - // Check Zone is Hot Zone or not ... - bool isHotZone = false; - for (int j = 0; j < ArraySize(hotLevels); j++) + // CF Bullish ... + + // + // HIGH ... + + // + condition = entryPrice < cfBULLBar.high; + if (condition) { // - isHotZone = (iZone.percent / 100 >= hotLevels[j]); - if (isHotZone) + // 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) { - break; + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; } } // - // Prevent Moving Forward if there isn't Hot Zone ... - if (!isHotZone) - { - continue; - } - - // - if (iZone.high > signal.entry && iZone.low > signal.entry) + condition = entryPrice > cfBULLBar.high; + if (condition) { // - // Here we can Use Resistance Zone as SL Recovery for - // Short Positions ... - if (!isLong && - (signal.sl <= 0 - ? true - : iZone.high < signal.sl && iZone.low < signal.sl)) + // 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) { // - // Opposit Support on Resistance Upper ... - - // - // rTP = signal.sl <= 0 - // ? iZone.high - (onePointValue * 15) - // : signal.sl; - // rSL = signal.entry; - rType = POSITION_TYPE_BUY; - rEntry = iZone.high + (onePointValue * 2); - rMode = X_ORDER_MODE_STOP; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // + AddRef( + rSignal, + signal.supports // ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } // - // Support Directional on Resistance Lower ... + rSignal.Clean(); // - // rTP = signal.entry; - // rSL = signal.sl <= 0 - // ? signal.entry - (onePointValue * 15) - // : signal.sl; - rEntry = iZone.low - (onePointValue * 2); - rVolume = signal.volume * 3; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - rVolume = signal.volume * 2; - } + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; } } // - if (iZone.high < signal.entry && iZone.low < signal.entry) + // 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; + } } } } // if (canUseTrend) + { + signal.trend.Draw(); + } + + // + if (canUseZones) + { + signal.zones.Draw(); + } + + // + signal.cf.Remove(); + signal.trend.Remove(); + signal.zones.Remove(); + } + + // + bool UpdateSupportSignals( + XPosition &support, + XPosition &parent, + XSignal &result // + ) + { + // + bool mResult = false; + + // + result.Clean(); + + // + mResult = support.IsValid() && parent.IsValid(); + if (!mResult) + { + return mResult; + } + + // + bool isDirectional = support.provider == XEQMSupportToken + XDirectionalToken; + + // + if (!isDirectional) { // - // Check Ask and Bid Price ... + // Indirectional Supports Updated Using Directional ... // - XOHCL fHighBar = signal.trend.GetFirstSwingHighBar(); - XOHCL sHighBar = signal.trend.GetSecondSwingHighBar(); + double entryPrice = GetEntry( + parent.symbol, + parent.type // + ); // - XOHCL fLowBar = signal.trend.GetFirstSwingLowBar(); - XOHCL sLowBar = signal.trend.GetSecondSwingLowBar(); - - // - double twoPoint = onePointValue * 2; - double fiftyPoint = onePointValue * 15; - - // - // add resistance ... - bool canAdd = - isLong && - entryPrice < (sHighBar.high - fiftyPoint); - if (canAdd) + ENUM_X_ORDER_MODES rMode = X_ORDER_MODE_NOTHING; + bool isParentLong = IsLong(parent.type); + if (isParentLong) { // - rSignal.Clean(); - - // - rEntry = sHighBar.high - fiftyPoint; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * 2; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) + if (entryPrice < parent.entry) { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; + rMode = X_ORDER_MODE_STOP; } - - // - rEntry = sHighBar.high - fiftyPoint; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * 3; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) + else if (entryPrice > parent.entry) { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; + rMode = X_ORDER_MODE_LIMIT; + } + } + else + { + // + if (entryPrice < parent.entry) + { + rMode = X_ORDER_MODE_LIMIT; + } + else if (entryPrice > parent.entry) + { + rMode = X_ORDER_MODE_STOP; } } // - canAdd = - isLong && - entryPrice > (sLowBar.low + fiftyPoint); - if (canAdd) + if (rMode != X_ORDER_MODE_NOTHING) { // - rSignal.Clean(); - - // - rEntry = (sLowBar.low + fiftyPoint); - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * 2; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, + mResult = result.Prepare( + parent.symbol, + XEQMSupportToken + XDirectionalToken, + parent.period, + parent.type, rMode, - rEntry, - rVolume, - rSL, - rTP // + parent.entry, + parent.volume, + 0, + 0 // ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - - // - rEntry = (sLowBar.low - fiftyPoint); - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * 3; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - 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 support ... - canAdd = - !isLong && - entryPrice > (sLowBar.low + fiftyPoint); - if (canAdd) + if (mResult) { // - rSignal.Clean(); - - // - rEntry = sLowBar.low + fiftyPoint; - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * 2; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - - // - rEntry = sLowBar.low + fiftyPoint; - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * 3; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - } - - // - canAdd = - !isLong && - entryPrice < (sHighBar.high - fiftyPoint); - if (canAdd) - { - // - rSignal.Clean(); - - // - rEntry = (sHighBar.high - fiftyPoint); - rType = POSITION_TYPE_BUY; - rMode = X_ORDER_MODE_STOP; - rVolume = signal.volume * 2; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } - - // - rEntry = (sHighBar.high - fiftyPoint); - rType = POSITION_TYPE_SELL; - rMode = X_ORDER_MODE_LIMIT; - rVolume = signal.volume * 3; - - // - isSignalPrepared = rSignal.Prepare( - signal.symbol, - signal.provider, - signal.period, - rType, - rMode, - rEntry, - rVolume, - rSL, - rTP // - ); - if (isSignalPrepared) - { - // - AddRef( - rSignal, - signal.supports // - ); - - // - rSignal.Clean(); - - // - rSL = 0; - rTP = 0; - rEntry = 0; - isSignalPrepared = false; - } + string comment = GenerateSupportTag(parent.ticket); + result.comment = comment; } } + else + { + // + // TODO: Implement ... + } + + // + return mResult; } // diff --git a/Classes/x-saherelm.x121.setup.xea.mq5 b/Classes/x-saherelm.x121.setup.xea.mq5 index 8faf5be4..3a6e87e3 100644 --- a/Classes/x-saherelm.x121.setup.xea.mq5 +++ b/Classes/x-saherelm.x121.setup.xea.mq5 @@ -42,7 +42,7 @@ struct XTradeInfo double volume; // Volume string provider; // Signaller ENUM_TIMEFRAMES period; // Trading Timeframe - ENUM_X_POSITION_TYPE type; // Position Type + ENUM_X_POSITION_TYPES type; // Position Type // ulong ticket; // Position Ticket @@ -3851,7 +3851,7 @@ public: { // // Select Signal Opposit Positions ... - ENUM_X_POSITION_TYPE iOpposit = GetOppositPositionType(iSignal.type); + ENUM_X_POSITION_TYPES iOpposit = GetOppositPositionType(iSignal.type); // XPosition iPositions[]; @@ -3995,9 +3995,8 @@ public: // // Signal Info Manager ... XSignal tSignal = signal; - bool isSupport = ExtractSupportedTicket(signal.comment) > 0; - bool isEQMSupport = ExtractEQMSupportedTicket(signal.comment) > 0; - if (!isSupport && !isEQMSupport) + bool isSupport = IsSupport(signal.comment); + if (!isSupport) { mTradeHandler.Update(tSignal); } @@ -4019,6 +4018,13 @@ public: mTradeHandler.Sync(); } + // + // Handle Support of Supports here ... + void OnPositionsChangedHandler(int count) override + { + EQMHandleSupportProtection(count); + } + // void OnPositionClosed( const XPosition &position, @@ -4739,6 +4745,102 @@ private: } } + // + void EQMHandleSupportProtection(int positionsCount) + { + // + if (!IsValidSize(positionsCount)) + { + return; + } + + // + ulong ticket = mTrader.GetLastOpenPositionTicket(); + XPosition position; + bool hasPosition = mTrader.GetPosition( + ticket, + position // + ); + if (!hasPosition) + { + return; + } + + // + bool isSupport = IsSupport(position.comment); + if (!isSupport) + { + return; + } + + // + bool isDIRInDIRSupport = position.provider == XEQMSupportToken + XDirectionalToken || + position.provider == XEQMSupportToken + XINDirectionalToken; + if (!isDIRInDIRSupport) + { + return; + } + + // + ulong parentTicket = ExtractParentTicket(position.comment); + XPosition parent; + bool hasParent = mTrader.GetPosition( + parentTicket, + parent // + ); + if (!hasParent) + { + return; + } + + // + // Remove Parent TP SL ... + if (parent.tp > 0 || parent.sl > 0) + { + // + string comment = XEQMSupportToken + "Remoove TPSL due Protect ..."; + bool isModeified = mTrader.Modify( + parentTicket, + 0, + 0, + comment // + ); + if (isModeified) + { + // + string message = XEQMSupportToken + " Removes Position (" + ToString(parentTicket) + ")' TP/SL Due Start Supporting ..."; + + // + Alert(message); + } + } + + // + XSignal signal; + X121SignalGenerator signalGenerator; + bool hasSupport = signalGenerator.UpdateSupportSignals( + position, + parent, + signal // + ); + if (!hasSupport) + { + return; + } + + // + XSignal signals[]; + + // + AddRef( + signal, + signals // + ); + + // + EQMExecuteSignals(signals); + } + // }; diff --git a/Classes/x-saherelm.xea.class.mq5 b/Classes/x-saherelm.xea.class.mq5 index a2132505..f3c469de 100644 --- a/Classes/x-saherelm.xea.class.mq5 +++ b/Classes/x-saherelm.xea.class.mq5 @@ -500,7 +500,7 @@ public: XSignal &support, // Holds Support Signal, if Provided string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period // Specified Time Frame ) { @@ -1261,7 +1261,7 @@ protected: void HandleGuardHedgeAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period, // Specified Time Frame double minProfitForHedging = 1, // Specified Profit for Hedge double minProfitForHedgingVolumeFactor = 0.01 // Specified Volume Factor for Hedge @@ -1320,7 +1320,7 @@ protected: void HandleGuardCloseInProfitAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period, // Specified Time Frame ENUM_X_POSITION_SELECT_METHODS method = NULL // Select Method ) @@ -1362,7 +1362,7 @@ protected: void HandleGuardCloseInDrawdownAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period, // Specified Time Frame ENUM_X_POSITION_SELECT_METHODS method = NULL // Select Method ) @@ -1404,7 +1404,7 @@ protected: void HandleGuardForceCloseAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period, // Specified Time Frame ulong ticket = 0 // Specific Ticket ) @@ -1481,7 +1481,7 @@ protected: void HandleGuardTrailingStopAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period, // Specified Time Frame double sl // Desired SL Value ... ) @@ -1559,7 +1559,7 @@ protected: void HandleGuardAddSupportPositionAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period // Specified Time Frame ) { @@ -1613,7 +1613,7 @@ protected: void HandleGuardCancelPendingOrdersAction( string provider, // Positions Provided by Specific Provider string symbol, // Trading Symbol - ENUM_X_POSITION_TYPE type, // Trading Type + ENUM_X_POSITION_TYPES type, // Trading Type ENUM_TIMEFRAMES period // Specified Time Frame ) { diff --git a/Classes/x-saherelm.xrange.class.mq5 b/Classes/x-saherelm.xrange.class.mq5 index c0efb069..0fedb424 100644 --- a/Classes/x-saherelm.xrange.class.mq5 +++ b/Classes/x-saherelm.xrange.class.mq5 @@ -22,8 +22,7 @@ // // Imports ... #include "../Classes/x-saherelm.base.class.mq5" -#include "../Libraries/x-saherelm.xtrade.lib.mq5" -#include "../Classes/x-saherelm.xaccount.class.mq5" +#include "../Libraries/x-saherelm.draw.lib.mq5" // // Definitions ... diff --git a/Classes/x-saherelm.xsccf.class.mq5 b/Classes/x-saherelm.xsccf.class.mq5 new file mode 100644 index 00000000..2e5d55c6 --- /dev/null +++ b/Classes/x-saherelm.xsccf.class.mq5 @@ -0,0 +1,736 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCRange +// Description: provides all Range requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.base.class.mq5" +#include "../Libraries/x-saherelm.draw.lib.mq5" + +// +// Definitions ... + +// +struct XSCCFInput +{ + // + // Props ... + + // + int length; // Minimum of Same Bars + + // + color clrUpper; // Upper Color ... + color clrLower; // Lower Color ... + + // + // Constructor ... + void XSCCFInput() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + length = 0; + + // + clrUpper = CLR_NONE; + clrLower = CLR_NONE; + } + + // + // Defualt Configs ... + void Default() + { + // + length = 4; + + // + clrLower = clrAqua; + clrUpper = clrMagenta; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length >= 2 + // + ; + + // + return result; + } +}; + +// +// Class ... + +class XSCCF : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor ... + void XSCCF( + string symbol, + ENUM_TIMEFRAMES period // + ) : XSCBase() + { + // + mSymbol = symbol; + mPeriod = period; + } + + // + // Deconstructor ... + void ~XSCCF() {} + + // + // Initialize ... + bool Init(XSCCFInput &inputs) + { + // + bool result = false; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + // Find Bullish Bar ... + result = FindBullishBar(0); + if (!result) + { + return result; + } + + // + // Find Bearish Bar ... + result = FindBearishBar(0); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + string GetSymbol() + { + return mSymbol; + } + + // + ENUM_TIMEFRAMES GetPeriod() + { + return mPeriod; + } + + // + XSCCFInput GetInputs() + { + return mInputs; + } + + // + bool SetInputs(XSCCFInput &inputs) + { + return Init(inputs); + } + + // + XOHCL GetBullishBar() + { + return bullishBar; + } + + // + XOHCL GetBearishBar() + { + return bearishBar; + } + + // + // Overrides ... + string GetTag() override + { + return "XCF"; + } + + // + // Tools ... + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + bullishBar.IsValid() && + bearishBar.IsValid() + // + ; + + // + return result; + } + + // + // Retrieve Title Prefix ... + string GetIdentifier() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetTag() + "_" + + mSymbol + "_" + + ToString(mPeriod) + "_" + + ToFormatString(bullishBar.time) + "_"; + + // + return result; + } + + // + // Remove Draws ... + bool Remove( + long chartId = 0, + int subWindow = 0 // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + string prefix = GetIdentifier(); + result = IsSpecifiedValid(prefix); + if (!result) + { + return result; + } + + // + RemoveDraws( + prefix, + chartId, + subWindow // + ); + + // + return result; + } + + // + bool Draw( + long chartId = 0, + string prefix = NULL, + int subWindow = 0, + string upperPrefix = "Upper", + string lowerPrefix = "Lower" // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + result = DrawBullishBar( + chartId, + prefix, + subWindow, + upperPrefix, + lowerPrefix // + ); + if (!result) + { + return result; + } + + // + result = DrawBearishBar( + chartId, + prefix, + subWindow, + upperPrefix, + lowerPrefix // + ); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Protected ... +protected: + // + // Tools ... + + // + bool FindBullishBar( + int barIndex // + ) + { + // + bool result = false; + + // + int next = barIndex + 1; + + // + int totalBars = iBars( + mSymbol, + mPeriod // + ); + result = barIndex >= 0 && barIndex + 1 + mInputs.length < totalBars; + if (!result) + { + return result; + } + + // + bool isNextValid = next >= 0 && next + 1 + mInputs.length < totalBars; + + // + int bullBarIndex = barIndex + 1; + int start = bullBarIndex + 1; + int end = start + mInputs.length; + + // + XOHCL startBar; + result = startBar.Init( + mSymbol, + mPeriod, + bullBarIndex // + ); + if (!result) + { + return result; + } + + // + result = startBar.IsBullish(); + if (!result) + { + if (isNextValid) + { + return FindBullishBar(next); + } + else + { + return result; + } + } + + // + // Loop Back to Find Bearish Bars ... + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + result = iBar.Init( + mSymbol, + mPeriod, + i // + ); + if (!result || !iBar.IsBearish()) + { + // + if (isNextValid) + { + return FindBullishBar(next); + } + else + { + return result; + } + + // + break; + } + } + + // + if (result) + { + bullishBar = startBar; + } + + // + return result; + } + + // + bool FindBearishBar( + int barIndex // + ) + { + // + bool result = false; + + // + int next = barIndex + 1; + + // + int totalBars = iBars( + mSymbol, + mPeriod // + ); + result = barIndex >= 0 && barIndex + 1 + mInputs.length < totalBars; + if (!result) + { + return result; + } + + // + bool isNextValid = next >= 0 && next + 1 + mInputs.length < totalBars; + + // + int bearBarIndex = barIndex + 1; + int start = bearBarIndex + 1; + int end = start + mInputs.length; + + // + XOHCL startBar; + result = startBar.Init( + mSymbol, + mPeriod, + bearBarIndex // + ); + if (!result) + { + return result; + } + + // + result = startBar.IsBearish(); + if (!result) + { + if (isNextValid) + { + return FindBearishBar(next); + } + else + { + return result; + } + } + + // + // Loop Back to Find Bearish Bars ... + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + result = iBar.Init( + mSymbol, + mPeriod, + i // + ); + if (!result || !iBar.IsBullish()) + { + // + if (isNextValid) + { + return FindBearishBar(next); + } + else + { + return result; + } + + // + break; + } + } + + // + if (result) + { + bearishBar = startBar; + } + + // + return result; + } + + // + bool DrawBullishBar( + long chartId = 0, + string prefix = NULL, + int subWindow = 0, + string upperPrefix = "Upper", + string lowerPrefix = "Lower" // + ) + { + // + bool result = false; + + // + result = bullishBar.IsValid(); + if (!result) + { + return result; + } + + // + if (!IsSpecifiedValid(upperPrefix)) + { + upperPrefix = "High"; + } + + // + if (!IsSpecifiedValid(lowerPrefix)) + { + lowerPrefix = "Low"; + } + + // + datetime cTime = TimeCurrent(); + + // + string identifier = GetIdentifier(); + + // + // High Line ... + string bullishHighLineName = + (IsSpecifiedValid(prefix) + ? prefix + "_" + : "") + + identifier + "_" + + "BULL_" + + upperPrefix; + + // + result = DrawTrendLine( + chartId, + bullishHighLineName, + subWindow, + bullishBar.time, + bullishBar.high, + cTime, + bullishBar.high, + mInputs.clrUpper, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + + // + // Low Line ... + string bullishLowLineName = + (IsSpecifiedValid(prefix) + ? prefix + "_" + : "") + + identifier + "_" + + "BULL_" + + lowerPrefix; + + // + result = DrawTrendLine( + chartId, + bullishLowLineName, + subWindow, + bullishBar.time, + bullishBar.low, + cTime, + bullishBar.low, + mInputs.clrLower, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + + // + return result; + } + + // + bool DrawBearishBar( + long chartId = 0, + string prefix = NULL, + int subWindow = 0, + string upperPrefix = "Upper", + string lowerPrefix = "Lower" // + ) + { + // + bool result = false; + + // + result = bearishBar.IsValid(); + if (!result) + { + return result; + } + + // + if (!IsSpecifiedValid(upperPrefix)) + { + upperPrefix = "High"; + } + + // + if (!IsSpecifiedValid(lowerPrefix)) + { + lowerPrefix = "Low"; + } + + // + datetime cTime = TimeCurrent(); + + // + string identifier = GetIdentifier(); + + // + // High Line ... + string bearishHighLineName = + (IsSpecifiedValid(prefix) + ? prefix + "_" + : "") + + identifier + "_" + + "BEAR_" + + upperPrefix; + + // + result = DrawTrendLine( + chartId, + bearishHighLineName, + subWindow, + bearishBar.time, + bearishBar.high, + cTime, + bearishBar.high, + mInputs.clrUpper, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + + // + // Low Line ... + string bearishLowLineName = + (IsSpecifiedValid(prefix) + ? prefix + "_" + : "") + + identifier + "_" + + "BEAR_" + + lowerPrefix; + + // + result = DrawTrendLine( + chartId, + bearishLowLineName, + subWindow, + bearishBar.time, + bearishBar.low, + cTime, + bearishBar.low, + mInputs.clrLower, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + + // + return result; + } + + // + // Private ... +private: + // + // Props ... + string mSymbol; // Trading Symbol ... + ENUM_TIMEFRAMES mPeriod; // Trading Period ... + + // + XOHCL bearishBar; // Bearish Order Block Bar + XOHCL bullishBar; // Bullish Order Block Bar + + // + XSCCFInput mInputs; // Configs ... +}; + +// \ No newline at end of file diff --git a/Classes/x-saherelm.xsctrend.class.mq5 b/Classes/x-saherelm.xsctrend.class.mq5 index 74124907..8fce72e9 100644 --- a/Classes/x-saherelm.xsctrend.class.mq5 +++ b/Classes/x-saherelm.xsctrend.class.mq5 @@ -120,7 +120,9 @@ public: // // Deconstructor ... - void ~XSCTrend() {} + void ~XSCTrend() { + Remove(); + } // // Initialize ... @@ -281,6 +283,15 @@ public: return secondSwingHighBar; } + // + // Overrides ... + + // + string GetTag() override + { + return "XTREND"; + } + // // Tools ... @@ -320,7 +331,8 @@ public: } // - result = mSymbol + "_" + + result = GetTag() + "_" + + mSymbol + "_" + ToString(mPeriod) + "_" + ToFormatString(zBar.time); @@ -354,7 +366,7 @@ public: } // - result = RemoveDraw( + RemoveDraws( prefix, chartId, subWindow // diff --git a/Classes/x-saherelm.xsczone.class.mq5 b/Classes/x-saherelm.xsczone.class.mq5 index 4ba0f052..1b692785 100644 --- a/Classes/x-saherelm.xsczone.class.mq5 +++ b/Classes/x-saherelm.xsczone.class.mq5 @@ -29,7 +29,7 @@ // // Definitions ... -#define defZoneBGColor clrLightGray +#define defZoneBGColor CLR_NONE // clrLightGray #define defZoneLBLColor clrWhite // @@ -286,6 +286,56 @@ public: return Init(inputs); } + // + // Overrides ... + + // + string GetTag() override + { + return "XZONE"; + } + + // + // Retrieve Title Prefix ... + string GetIdentifier() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetTag() + "_" + + mSymbol + "_" + + ToString(mPeriod) + + ToFormatString(mStartTime) + "_" + + ToFormatString(mEndTime); + + // + return result; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + // + mZones.Total() > 0 + // + ; + + // + return result; + } + // // Add Specified Level/Color ... void AddLevelColor( @@ -502,7 +552,7 @@ public: } // - bool DrawZones( + bool Draw( long chartId = 0, string prefix = "XSCZone", int subWindow = 0, @@ -645,6 +695,31 @@ public: return result; } + // + bool Remove( + long chartId = 0, + string prefix = "XSCZone", + int subWindow = 0, + bool redraw = false // + ) + { + // + bool result = false; + + // + mChartObjects.Clear(); + + // + result = + // + true + // + ; + + // + return result; + } + // // Protected ... protected: diff --git a/Classes/x-saherelm.xtrade.class.mq5 b/Classes/x-saherelm.xtrade.class.mq5 index a6dd344d..9e5933f3 100644 --- a/Classes/x-saherelm.xtrade.class.mq5 +++ b/Classes/x-saherelm.xtrade.class.mq5 @@ -1845,7 +1845,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) bool filterByMagic = true // Get Only Self Open Positions ) { @@ -2034,7 +2034,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) bool filterByMagic = true // Get Only Self Open Positions ) { @@ -2099,7 +2099,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) bool filterByMagic = true, // Get Only Self Open Positions bool forceClean = true // Clean Result Array ) @@ -2215,7 +2215,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) ENUM_X_POSITION_SELECT_METHODS method = NULL, // Selection Method bool filterByMagic = true, // Get Only Self Open Positions bool forceClean = true // Clean Result Array @@ -2346,7 +2346,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) ENUM_X_POSITION_SELECT_METHODS method = NULL, // Selection Method bool filterByMagic = true, // Get Only Self Open Positions bool forceClean = true // Clean Result Array @@ -2567,7 +2567,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) ENUM_ORDER_STATE state = NULL, // Order State bool filterByMagic = true, // Get Only Self Open Positions bool forceClean = true // Clean Result Array @@ -2649,7 +2649,7 @@ public: string symbol = NULL, // Trading Symbol string provider = NULL, // Signal Provider ENUM_TIMEFRAMES period = NULL, // Trading Period - ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) ENUM_ORDER_STATE state = NULL, // Order State datetime startDate = NULL, // Specify Start Date datetime endDate = NULL, // Specify End Date diff --git a/Documents/BKP/usefull.mq5 b/Documents/BKP/usefull.mq5 index dd190bbf..1caa21f5 100644 --- a/Documents/BKP/usefull.mq5 +++ b/Documents/BKP/usefull.mq5 @@ -1742,3 +1742,600 @@ } return; } + + +////////////////////////////////////////////////////////////////////// + + // // + // // Check Signal Has TP and SL ... + // if (signal.tp > 0 && signal.sl > 0) + // { + // // + // // Here we Can Provide Orders based on Signal TP and SL ... + + // // + // // Calculate TP/Entry Distance ... + // double tpDistance = + // isLong + // ? signal.tp - signal.entry + // : signal.entry - signal.tp; + + // // + // // Calculate Recovery Zone Step ... + // double slDistance = + // isLong + // ? signal.entry - signal.sl + // : signal.sl - signal.entry; + // } + + // // + // // Add Zone Based Signals ... + // if (canUseZones) + // { + // // + // // signal.zones.DrawZones(); + + // // + // // Try to Find a Hot Level based on Signal Direction + // // as Resistance ... + + // // + // 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; + // } + + // // + // if (iZone.high > signal.entry && iZone.low > signal.entry) + // { + // // + // // Here we can Use Resistance Zone as SL Recovery for + // // Short Positions ... + // if (!isLong && + // (signal.sl <= 0 + // ? true + // : iZone.high < signal.sl && iZone.low < signal.sl)) + // { + // // + // // Opposit Support on Resistance Upper ... + + // // + // // rTP = signal.sl <= 0 + // // ? iZone.high - (onePointValue * 15) + // // : signal.sl; + // // rSL = signal.entry; + // rType = POSITION_TYPE_BUY; + // rEntry = iZone.high + (onePointValue * 2); + // rMode = X_ORDER_MODE_STOP; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + + // // + // // Support Directional on Resistance Lower ... + + // // + // // rTP = signal.entry; + // // rSL = signal.sl <= 0 + // // ? signal.entry - (onePointValue * 15) + // // : signal.sl; + // rEntry = iZone.low - (onePointValue * 2); + // rVolume = signal.volume * 3; + // rType = POSITION_TYPE_SELL; + // rMode = X_ORDER_MODE_LIMIT; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // rVolume = signal.volume * 2; + // } + // } + // } + + // // + // if (iZone.high < signal.entry && iZone.low < signal.entry) + // { + // // + // } + // } + // } + + // // + // if (canUseTrend) + // { + // // + // // Check Ask and Bid Price ... + + // // + // XOHCL fHighBar = signal.trend.GetFirstSwingHighBar(); + // XOHCL sHighBar = signal.trend.GetSecondSwingHighBar(); + + // // + // XOHCL fLowBar = signal.trend.GetFirstSwingLowBar(); + // XOHCL sLowBar = signal.trend.GetSecondSwingLowBar(); + + // // + // double twoPoint = onePointValue * 2; + // double fiftyPoint = onePointValue * 15; + + // // + // // add resistance ... + // bool canAdd = + // isLong && + // entryPrice < (sHighBar.high - fiftyPoint); + // if (canAdd) + // { + // // + // rSignal.Clean(); + + // // + // rEntry = sHighBar.high - fiftyPoint; + // rType = POSITION_TYPE_BUY; + // rMode = X_ORDER_MODE_STOP; + // rVolume = signal.volume * 2; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + + // // + // rEntry = sHighBar.high - fiftyPoint; + // rType = POSITION_TYPE_SELL; + // rMode = X_ORDER_MODE_LIMIT; + // rVolume = signal.volume * 3; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + // } + + // // + // canAdd = + // isLong && + // entryPrice > (sLowBar.low + fiftyPoint); + // if (canAdd) + // { + // // + // rSignal.Clean(); + + // // + // rEntry = (sLowBar.low + fiftyPoint); + // rType = POSITION_TYPE_SELL; + // rMode = X_ORDER_MODE_STOP; + // rVolume = signal.volume * 2; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + + // // + // rEntry = (sLowBar.low - fiftyPoint); + // rType = POSITION_TYPE_BUY; + // rMode = X_ORDER_MODE_LIMIT; + // rVolume = signal.volume * 3; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // 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 support ... + // canAdd = + // !isLong && + // entryPrice > (sLowBar.low + fiftyPoint); + // if (canAdd) + // { + // // + // rSignal.Clean(); + + // // + // rEntry = sLowBar.low + fiftyPoint; + // rType = POSITION_TYPE_SELL; + // rMode = X_ORDER_MODE_STOP; + // rVolume = signal.volume * 2; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + + // // + // rEntry = sLowBar.low + fiftyPoint; + // rType = POSITION_TYPE_BUY; + // rMode = X_ORDER_MODE_LIMIT; + // rVolume = signal.volume * 3; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + // } + + // // + // canAdd = + // !isLong && + // entryPrice < (sHighBar.high - fiftyPoint); + // if (canAdd) + // { + // // + // rSignal.Clean(); + + // // + // rEntry = (sHighBar.high - fiftyPoint); + // rType = POSITION_TYPE_BUY; + // rMode = X_ORDER_MODE_STOP; + // rVolume = signal.volume * 2; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + + // // + // rEntry = (sHighBar.high - fiftyPoint); + // rType = POSITION_TYPE_SELL; + // rMode = X_ORDER_MODE_LIMIT; + // rVolume = signal.volume * 3; + + // // + // isSignalPrepared = rSignal.Prepare( + // signal.symbol, + // signal.provider, + // signal.period, + // rType, + // rMode, + // rEntry, + // rVolume, + // rSL, + // rTP // + // ); + // if (isSignalPrepared) + // { + // // + // AddRef( + // rSignal, + // signal.supports // + // ); + + // // + // rSignal.Clean(); + + // // + // rSL = 0; + // rTP = 0; + // rEntry = 0; + // isSignalPrepared = false; + // } + // } + // } + + +/////////////////////////////////////////////////////////////// + + // + // Directional ... + rEntry = signal.entry; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_LIMIT; + rVolume = signal.volume * directionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken, + signal.period, + rType, + rMode, + rEntry, + rVolume, + rSL, + rTP // + ); + if (isSignalPrepared) + { + // + AddRef( + rSignal, + signal.supports // + ); + + // + rSignal.Clean(); + + // + rSL = 0; + rTP = 0; + rEntry = 0; + isSignalPrepared = false; + } + + + // + // Directional ... + rEntry = signal.entry; + rType = POSITION_TYPE_SELL; + rMode = X_ORDER_MODE_STOP; + rVolume = signal.volume * directionalVolumeMultiplier; + + // + isSignalPrepared = rSignal.Prepare( + signal.symbol, + XEQMSupportToken, + 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/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index 9fd25302..014fae0b 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -332,6 +332,7 @@ bool InitialEA() // Configure Indicators ... X121SetupInputs setupInputsDefault; setupInputsDefault.Default(); + PreConfigureStyles(setupInputsDefault); // // Prepare Providers and Add them into mX121EA class ... @@ -366,3 +367,73 @@ bool InitialEA() // return result; } + +// +void PreConfigureStyles(X121SetupInputs &inputs) { + // + if (!inputs.IsValid()) { + return; + } + + // + // XPV ... + inputs.pvInputs.showPeaksAndVales = true; + inputs.pvInputs.showLevels = false; + inputs.pvInputs.showConsolidations = false; + inputs.pvInputs.showFibo1Levels = true; + inputs.pvInputs.showFibo2Levels = true; + inputs.pvInputs.showFibo3Levels = true; + inputs.pvInputs.showFibo4Levels = true; + inputs.pvInputs.showFibo5Levels = true; + + // + // XHK ... + inputs.hkInputs.drawHikenAshi = false; + inputs.hkInputs.drawSmoothedHikenAshi = false; + + // + // XCHE ... + inputs.cheInputs.showLongExit1Line = false; + inputs.cheInputs.showShortExit1Line = false; + inputs.cheInputs.showLongExit2Line = false; + inputs.cheInputs.showShortExit2Line = false; + + // + // XICH ... + inputs.ichInputs.showTenkanSen = false; + inputs.ichInputs.showKijunSen = false; + inputs.ichInputs.showKijunSenPlus = false; + inputs.ichInputs.showKijunSenNegative = false; + inputs.ichInputs.showChikouSpan = false; + inputs.ichInputs.showSenkouSpanA = false; + inputs.ichInputs.showSenkouSpanB = false; + inputs.ichInputs.showKumo = false; + + // + // XSTR ... + inputs.strInputs.showTrends = false; + inputs.strInputs.fillTrends = false; + + // + // XMRB ... + inputs.mrbInputs.showFastMa = false; + inputs.mrbInputs.showSlowMa = false; + inputs.mrbInputs.showRibbon = false; + + // + // XASCT ... + inputs.asctInputs.showLongs = false; + inputs.asctInputs.showShorts = false; + + // + // XSSLC ... + inputs.sslcInputs.showUp = false; + inputs.sslcInputs.showDown = false; + + // + // XHULL ... + inputs.hullInputs.showUpZone = false; + inputs.hullInputs.showDownZone = false; +} + +// \ No newline at end of file diff --git a/Libraries/x-saherelm.xtrade.lib.mq5 b/Libraries/x-saherelm.xtrade.lib.mq5 index 3999f1f1..f97d8b58 100644 --- a/Libraries/x-saherelm.xtrade.lib.mq5 +++ b/Libraries/x-saherelm.xtrade.lib.mq5 @@ -23,6 +23,7 @@ // Imports ... #include #include "../Libraries/x-saherelm.draw.lib.mq5" +#include "../Classes/x-saherelm.xsccf.class.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" #include "../Classes/x-saherelm.xsczone.class.mq5" #include "../Classes/x-saherelm.xsctrend.class.mq5" @@ -62,6 +63,10 @@ string XSLTrailToken = "SLT"; // string XActionToken = "A"; +// +string XDirectionalToken = "D"; +string XINDirectionalToken = "IND"; + // // Available Order Modes ... enum ENUM_X_ORDER_MODES @@ -148,7 +153,7 @@ enum ENUM_X_GUARD_ACTIONS }; // -enum ENUM_X_POSITION_TYPE +enum ENUM_X_POSITION_TYPES { X_POSITION_TYPE_NONE = 0, X_POSITION_TYPE_ALL = 1, @@ -157,7 +162,7 @@ enum ENUM_X_POSITION_TYPE }; // -string ToString(ENUM_X_POSITION_TYPE value) +string ToString(ENUM_X_POSITION_TYPES value) { // string result = NULL; @@ -191,7 +196,7 @@ string ToString(ENUM_X_POSITION_TYPE value) } // -bool IsLong(ENUM_X_POSITION_TYPE value) +bool IsLong(ENUM_X_POSITION_TYPES value) { return value == X_POSITION_TYPE_LONG; } @@ -199,7 +204,7 @@ bool IsLong(ENUM_X_POSITION_TYPE value) // bool ToPositinType( ENUM_POSITION_TYPE &dest, - ENUM_X_POSITION_TYPE source // + ENUM_X_POSITION_TYPES source // ) { // @@ -224,7 +229,7 @@ bool ToPositinType( } // -ENUM_X_POSITION_TYPE ToPositionType(ENUM_POSITION_TYPE value) +ENUM_X_POSITION_TYPES ToPositionType(ENUM_POSITION_TYPE value) { return IsLong(value) ? X_POSITION_TYPE_LONG @@ -232,10 +237,10 @@ ENUM_X_POSITION_TYPE ToPositionType(ENUM_POSITION_TYPE value) } // -ENUM_X_POSITION_TYPE GetOppositPositionType(ENUM_POSITION_TYPE type) +ENUM_X_POSITION_TYPES GetOppositPositionType(ENUM_POSITION_TYPE type) { // - ENUM_X_POSITION_TYPE result = X_POSITION_TYPE_NONE; + ENUM_X_POSITION_TYPES result = X_POSITION_TYPE_NONE; // bool isLong = IsLong(type); @@ -635,7 +640,7 @@ struct XPosition string mSymbol = NULL, // Trading Symbol string mProvider = NULL, // Signal Provider ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe - ENUM_X_POSITION_TYPE mType = NULL, // Long (Buy), Short (Sell) + ENUM_X_POSITION_TYPES mType = NULL, // Long (Buy), Short (Sell) ulong mMagic = NULL, // Magic Number bool mFilterByMagic = true // Get Only Self Open Positions ) @@ -730,9 +735,10 @@ struct XSignal XSignal supports[]; // a Collecion of Support Signals ... // - // Zones for Signal ... + // TODO: Temp ... XSCZones *zones; XSCTrend *trend; + XSCCF *cf; // // Constructor ... @@ -1925,7 +1931,7 @@ struct XOrder string mSymbol = NULL, // Trading Symbol string mProvider = NULL, // Signal Provider ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe - ENUM_X_POSITION_TYPE mType = NULL, // Long (Buy), Short (Sell) + ENUM_X_POSITION_TYPES mType = NULL, // Long (Buy), Short (Sell) ENUM_ORDER_STATE mState = NULL, // Order State ulong mMagic = NULL, // Magic Number bool mFilterByMagic = true // Get Only Self Open Positions @@ -2476,7 +2482,7 @@ struct XGuard string symbol; // Trading Symbol ... string provider; // Signal Provider ... ENUM_TIMEFRAMES period; // Trading Timeframe ... - ENUM_X_POSITION_TYPE type; // Position Type ... + ENUM_X_POSITION_TYPES type; // Position Type ... ENUM_X_GUARD_ACTIONS action; // Which Action to Do ... // @@ -2499,7 +2505,7 @@ struct XGuard string mSymbol, // Trading Symbol ... ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ... ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ... - ENUM_X_POSITION_TYPE mType = NULL, // Position Type ... + ENUM_X_POSITION_TYPES mType = NULL, // Position Type ... string mProvider = NULL, // Signal Provider ... double mDblPayLoad = NULL, string mStrPayload = NULL // @@ -3469,7 +3475,7 @@ bool IsTypeFilterPassed( } template bool IsTypeFilterPassed( - ENUM_X_POSITION_TYPE type, + ENUM_X_POSITION_TYPES type, T &item // ) @@ -3978,7 +3984,7 @@ ENUM_ORDER_TYPE ToOrderType(ENUM_POSITION_TYPE value) // return result; } -ENUM_ORDER_TYPE ToOrderType(ENUM_X_POSITION_TYPE value) +ENUM_ORDER_TYPE ToOrderType(ENUM_X_POSITION_TYPES value) { // ENUM_POSITION_TYPE mType =