diff --git a/Classes/x-saherelm.x121.xtrade.handler.class.mq5 b/Classes/x-saherelm.x121.xtrade.handler.class.mq5 index f119171b..da8c1645 100644 --- a/Classes/x-saherelm.x121.xtrade.handler.class.mq5 +++ b/Classes/x-saherelm.x121.xtrade.handler.class.mq5 @@ -1194,176 +1194,176 @@ class X121SCTradeHandler : public XSCBaseAlert // // In Drawdown Positions Protecting ... - // - // Freeze ... - bool AllowFreeze() - { - return mAllowFreeze; - } + // // + // // Freeze ... + // bool AllowFreeze() + // { + // return mAllowFreeze; + // } - // - void AllowFreeze(bool value) - { - mAllowFreeze = value; - } + // // + // void AllowFreeze(bool value) + // { + // mAllowFreeze = value; + // } - // - double FreezeDistance() - { - return mFreezeDistance; - } + // // + // double FreezeDistance() + // { + // return mFreezeDistance; + // } - // - void FreezeDistance(double value) - { - // - if (value < 0) - { - value = 0; - } + // // + // void FreezeDistance(double value) + // { + // // + // if (value < 0) + // { + // value = 0; + // } - // - mFreezeDistance = value; - } + // // + // mFreezeDistance = value; + // } - // - bool RemoveFreezedPositionTPSL() - { - return mRemoveFreezedPositionTPSL; - } + // // + // bool RemoveFreezedPositionTPSL() + // { + // return mRemoveFreezedPositionTPSL; + // } - // - void RemoveFreezedPositionTPSL(bool value) - { - mRemoveFreezedPositionTPSL = value; - } + // // + // void RemoveFreezedPositionTPSL(bool value) + // { + // mRemoveFreezedPositionTPSL = value; + // } - // - bool DisableTrailWhenFreezedPosition() - { - return mDisableTrailWhenFreezedPosition; - } + // // + // bool DisableTrailWhenFreezedPosition() + // { + // return mDisableTrailWhenFreezedPosition; + // } - // - void DisableTrailWhenFreezedPosition(bool value) - { - mDisableTrailWhenFreezedPosition = value; - } + // // + // void DisableTrailWhenFreezedPosition(bool value) + // { + // mDisableTrailWhenFreezedPosition = value; + // } // // Support ... - // - bool AllowSupport() - { - return mAllowSupport; - } + // // + // bool AllowSupport() + // { + // return mAllowSupport; + // } - // - void AllowSupport(bool value) - { - mAllowSupport = value; - } + // // + // void AllowSupport(bool value) + // { + // mAllowSupport = value; + // } - // - double SupportStartDistance() - { - return mSupportStartDistance; - } + // // + // double SupportStartDistance() + // { + // return mSupportStartDistance; + // } - // - void SupportStartDistance(double value) - { - // - if (value < 0) - { - value = 0; - } + // // + // void SupportStartDistance(double value) + // { + // // + // if (value < 0) + // { + // value = 0; + // } - // - mSupportStartDistance = value; - } + // // + // mSupportStartDistance = value; + // } - // - int MaxAllowedSupport() - { - return mMaxAllowedSupport; - } + // // + // int MaxAllowedSupport() + // { + // return mMaxAllowedSupport; + // } - // - void MaxAllowedSupport(int value) - { - // - if (value < 0) - { - value = 0; - } + // // + // void MaxAllowedSupport(int value) + // { + // // + // if (value < 0) + // { + // value = 0; + // } - // - mMaxAllowedSupport = value; - } + // // + // mMaxAllowedSupport = value; + // } - // - double SupportVolumeMultiplier() - { - return mSupportVolumeMultiplier; - } + // // + // double SupportVolumeMultiplier() + // { + // return mSupportVolumeMultiplier; + // } - // - void SupportVolumeMultiplier(double value) - { - // - if (value < 0) - { - value = 0; - } + // // + // void SupportVolumeMultiplier(double value) + // { + // // + // if (value < 0) + // { + // value = 0; + // } - // - mSupportVolumeMultiplier = value; - } + // // + // mSupportVolumeMultiplier = value; + // } - // - bool MultiplySupportLevelOnVolume() - { - return mMultiplySupportLevelOnVolume; - } + // // + // bool MultiplySupportLevelOnVolume() + // { + // return mMultiplySupportLevelOnVolume; + // } - // - void MultiplySupportLevelOnVolume(bool value) - { - mMultiplySupportLevelOnVolume = value; - } + // // + // void MultiplySupportLevelOnVolume(bool value) + // { + // mMultiplySupportLevelOnVolume = value; + // } - // - bool DoSupportOnConditions() - { - return mDoSupportOnConditions; - } + // // + // bool DoSupportOnConditions() + // { + // return mDoSupportOnConditions; + // } - // - void DoSupportOnConditions(bool value) - { - mDoSupportOnConditions = value; - } + // // + // void DoSupportOnConditions(bool value) + // { + // mDoSupportOnConditions = value; + // } - // - int DelayBetweenTwoSupport() - { - return mDelayBetweenTwoSupport; - } + // // + // int DelayBetweenTwoSupport() + // { + // return mDelayBetweenTwoSupport; + // } - // - void DelayBetweenTwoSupport(int value) - { - // - if (value < 0) - { - value = 0; - } + // // + // void DelayBetweenTwoSupport(int value) + // { + // // + // if (value < 0) + // { + // value = 0; + // } - // - mDelayBetweenTwoSupport = value; - } + // // + // mDelayBetweenTwoSupport = value; + // } // // Partial Close (In Drawdown) ... @@ -2649,42 +2649,44 @@ class X121SCTradeHandler : public XSCBaseAlert // Reading Requirement for Freezing Positions ... // - bool allowFreeze = AllowFreeze(); - double freezeDistance = FreezeDistance(); - bool removeFreezedPositionTPSL = RemoveFreezedPositionTPSL(); - bool canFreeze = allowFreeze && - !isInProfit && - profitInPoint < 0 && - freezeDistance > 0 && - !mData[iDX].freezed && - MathAbs(profitInPoint) >= freezeDistance; + // bool allowFreeze = AllowFreeze(); + // double freezeDistance = FreezeDistance(); + // bool removeFreezedPositionTPSL = RemoveFreezedPositionTPSL(); + // bool canFreeze = allowFreeze && + // !isInProfit && + // profitInPoint < 0 && + // freezeDistance > 0 && + // !mData[iDX].freezed && + // MathAbs(profitInPoint) >= freezeDistance; + bool canFreeze = false; // // Reading Requirement for Support Positions ... - bool allowSupport = AllowSupport(); - double supportStartDistance = SupportStartDistance(); - int maxAllowedSupport = MaxAllowedSupport(); - int delayBetweenTwoSupport = DelayBetweenTwoSupport(); - double supportVolumeMultiplier = SupportVolumeMultiplier(); - bool multiplySupportLevelOnVolume = MultiplySupportLevelOnVolume(); - bool doSupportOnConditions = DoSupportOnConditions(); - bool canSupport = allowSupport && - (!isInProfit || - (isInProfit && supportsCount > 0)) && - maxAllowedSupport >= 0 && - supportStartDistance >= 0 && - supportVolumeMultiplier > 0 && - MathAbs(profitInPoint) >= supportStartDistance && - // - // Check Max Allowed Support ... - (maxAllowedSupport == 0 - ? true - : supportsCount < maxAllowedSupport) && - // - // Check Delay ... - (!IsValid(mData[iDX].lastSupportedOn) - ? true - : (TimeToSeconds(currentTime) - TimeToSeconds(mData[iDX].lastSupportedOn)) >= ulong(delayBetweenTwoSupport)); + // bool allowSupport = AllowSupport(); + // double supportStartDistance = SupportStartDistance(); + // int maxAllowedSupport = MaxAllowedSupport(); + // int delayBetweenTwoSupport = DelayBetweenTwoSupport(); + // double supportVolumeMultiplier = SupportVolumeMultiplier(); + // bool multiplySupportLevelOnVolume = MultiplySupportLevelOnVolume(); + // bool doSupportOnConditions = DoSupportOnConditions(); + // bool canSupport = allowSupport && + // (!isInProfit || + // (isInProfit && supportsCount > 0)) && + // maxAllowedSupport >= 0 && + // supportStartDistance >= 0 && + // supportVolumeMultiplier > 0 && + // MathAbs(profitInPoint) >= supportStartDistance && + // // + // // Check Max Allowed Support ... + // (maxAllowedSupport == 0 + // ? true + // : supportsCount < maxAllowedSupport) && + // // + // // Check Delay ... + // (!IsValid(mData[iDX].lastSupportedOn) + // ? true + // : (TimeToSeconds(currentTime) - TimeToSeconds(mData[iDX].lastSupportedOn)) >= ulong(delayBetweenTwoSupport)); + bool canSupport = false; // result = @@ -2988,204 +2990,204 @@ class X121SCTradeHandler : public XSCBaseAlert // // Freeze ... bool isFreezed = false; - if (canFreeze) - { - // - // Temparory Requirement for Recover Signal ... - double sl = removeFreezedPositionTPSL ? 0 : position.tp; - double tp = removeFreezedPositionTPSL ? 0 : position.sl; - ENUM_POSITION_TYPE type = isLong - ? POSITION_TYPE_SELL - : POSITION_TYPE_BUY; - double entry = GetEntry( - position.symbol, - type // - ); - ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; + // if (canFreeze) + // { + // // + // // Temparory Requirement for Recover Signal ... + // double sl = removeFreezedPositionTPSL ? 0 : position.tp; + // double tp = removeFreezedPositionTPSL ? 0 : position.sl; + // ENUM_POSITION_TYPE type = isLong + // ? POSITION_TYPE_SELL + // : POSITION_TYPE_BUY; + // double entry = GetEntry( + // position.symbol, + // type // + // ); + // ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; - // - // Prepare Signal ... - XSignal signal; - bool isPrepared = signal.Prepare( - position.symbol, - position.provider, - position.period, - type, - mode, - entry, - position.volume, - sl, - tp // - ); + // // + // // Prepare Signal ... + // XSignal signal; + // bool isPrepared = signal.Prepare( + // position.symbol, + // position.provider, + // position.period, + // type, + // mode, + // entry, + // position.volume, + // sl, + // tp // + // ); - // - if (isPrepared) - { - // - // Generate Comment for Recover and Support ... - string comment = GenerateSupportTag(position.ticket); + // // + // if (isPrepared) + // { + // // + // // Generate Comment for Recover and Support ... + // string comment = GenerateSupportTag(position.ticket); - // - signal.comment = comment; + // // + // signal.comment = comment; - // - ENUM_X_SIGNAL_EXECUTION_RESULT state; - bool isFreezed = ExecuteSignal( - signal, - state, - true // Support Signal need to Ignore Policies ... - ); - if (isFreezed) - { - // - mData[iDX].freezed = true; + // // + // ENUM_X_SIGNAL_EXECUTION_RESULT state; + // bool isFreezed = ExecuteSignal( + // signal, + // state, + // true // Support Signal need to Ignore Policies ... + // ); + // if (isFreezed) + // { + // // + // mData[iDX].freezed = true; - // - string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Freeze Position for (" + ToString(position.ticket) + ") ..."; - Alert(message); + // // + // string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Freeze Position for (" + ToString(position.ticket) + ") ..."; + // Alert(message); - // - if (removeFreezedPositionTPSL) - { - // - string comment = "EQM Removes Freezed TP/SL ..."; - bool isModified = mTrader.Modify( - position.ticket, - 0, - 0, - comment // - ); + // // + // if (removeFreezedPositionTPSL) + // { + // // + // string comment = "EQM Removes Freezed TP/SL ..."; + // bool isModified = mTrader.Modify( + // position.ticket, + // 0, + // 0, + // comment // + // ); - // - if (isModified) - { - // - string message = "EQM Remove Freezed Position (" + ToString(position.ticket) + ") TP/SL ..."; - Alert(message); - } - } - } - } - } + // // + // if (isModified) + // { + // // + // string message = "EQM Remove Freezed Position (" + ToString(position.ticket) + ") TP/SL ..."; + // Alert(message); + // } + // } + // } + // } + // } // // Support ... bool isSupported = false; - if (canSupport) - { - // - // supportsCount - // bool isDistancePassed = - // supportStartDistance <= 0 - // ? true - // : mData[iDX].lastSupportDistance < 0 - // ? profitInPoint < 0 && (true) - // : profitInPoint > 0 && (true); + // if (canSupport) + // { + // // + // // supportsCount + // // bool isDistancePassed = + // // supportStartDistance <= 0 + // // ? true + // // : mData[iDX].lastSupportDistance < 0 + // // ? profitInPoint < 0 && (true) + // // : profitInPoint > 0 && (true); - // - bool hasLongSupportCondition = !doSupportOnConditions - ? true - : (isTicksBullishForLong && - hasBullishConditions); + // // + // bool hasLongSupportCondition = !doSupportOnConditions + // ? true + // : (isTicksBullishForLong && + // hasBullishConditions); - // - bool hasShortSupportConditions = !doSupportOnConditions - ? true - : (isTicksBearishForShort && - hasBearishConditions); + // // + // bool hasShortSupportConditions = !doSupportOnConditions + // ? true + // : (isTicksBearishForShort && + // hasBearishConditions); - // - bool hasSupportConditions = - !doSupportOnConditions - ? true - : (hasLongSupportCondition || - hasShortSupportConditions); - if (hasSupportConditions) - { - // - // Temparory Requirement for Recover Signal ... - double sl = - isLong - ? hasLongSupportCondition - ? position.sl - : position.tp - : hasLongSupportCondition - ? position.tp - : position.sl; - double tp = - isLong - ? hasLongSupportCondition - ? position.tp - : position.sl - : hasLongSupportCondition - ? position.sl - : position.tp; - ENUM_POSITION_TYPE type = - hasLongSupportCondition - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; - double entry = GetEntry( - position.symbol, - type // - ); - ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; - double volume = position.volume * supportVolumeMultiplier; - if (multiplySupportLevelOnVolume) - { - // - volume = supportsCount <= 0 - ? position.volume * supportVolumeMultiplier - : position.volume * ((supportsCount + 1) * supportVolumeMultiplier); - } + // // + // bool hasSupportConditions = + // !doSupportOnConditions + // ? true + // : (hasLongSupportCondition || + // hasShortSupportConditions); + // if (hasSupportConditions) + // { + // // + // // Temparory Requirement for Recover Signal ... + // double sl = + // isLong + // ? hasLongSupportCondition + // ? position.sl + // : position.tp + // : hasLongSupportCondition + // ? position.tp + // : position.sl; + // double tp = + // isLong + // ? hasLongSupportCondition + // ? position.tp + // : position.sl + // : hasLongSupportCondition + // ? position.sl + // : position.tp; + // ENUM_POSITION_TYPE type = + // hasLongSupportCondition + // ? POSITION_TYPE_BUY + // : POSITION_TYPE_SELL; + // double entry = GetEntry( + // position.symbol, + // type // + // ); + // ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; + // double volume = position.volume * supportVolumeMultiplier; + // if (multiplySupportLevelOnVolume) + // { + // // + // volume = supportsCount <= 0 + // ? position.volume * supportVolumeMultiplier + // : position.volume * ((supportsCount + 1) * supportVolumeMultiplier); + // } - // - // Prepare Signal ... - XSignal signal; - bool isPrepared = signal.Prepare( - position.symbol, - position.provider, - position.period, - type, - mode, - entry, - volume, - sl, - tp // - ); + // // + // // Prepare Signal ... + // XSignal signal; + // bool isPrepared = signal.Prepare( + // position.symbol, + // position.provider, + // position.period, + // type, + // mode, + // entry, + // volume, + // sl, + // tp // + // ); - // - if (isPrepared) - { - // - // Generate Comment for Recover and Support ... - string comment = GenerateSupportTag(position.ticket); + // // + // if (isPrepared) + // { + // // + // // Generate Comment for Recover and Support ... + // string comment = GenerateSupportTag(position.ticket); - // - signal.comment = comment; + // // + // signal.comment = comment; - // - ENUM_X_SIGNAL_EXECUTION_RESULT state; - bool isSupported = ExecuteSignal( - signal, - state, - true // Support Signal need to Ignore Policies ... - ); - if (isSupported) - { - // - mData[iDX].supportLevel++; - mData[iDX].lastSupportedOn = currentTime; - mData[iDX].lastSupportDistance = profitInPoint; + // // + // ENUM_X_SIGNAL_EXECUTION_RESULT state; + // bool isSupported = ExecuteSignal( + // signal, + // state, + // true // Support Signal need to Ignore Policies ... + // ); + // if (isSupported) + // { + // // + // mData[iDX].supportLevel++; + // mData[iDX].lastSupportedOn = currentTime; + // mData[iDX].lastSupportDistance = profitInPoint; - // - string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Support Position in Level: " + - ToString(mData[iDX].supportLevel) + - " for (" + ToString(position.ticket) + ") ..."; - Alert(message); - } - } - } - } + // // + // string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Support Position in Level: " + + // ToString(mData[iDX].supportLevel) + + // " for (" + ToString(position.ticket) + ") ..."; + // Alert(message); + // } + // } + // } + // } // result = @@ -3248,20 +3250,20 @@ class X121SCTradeHandler : public XSCBaseAlert // // Freeze ... - bool mAllowFreeze; // Allow Freezing - double mFreezeDistance; // Specify Freeze Start Drawdown in Point - bool mRemoveFreezedPositionTPSL; // Remove Freezed Positions TPSL - bool mDisableTrailWhenFreezedPosition; // Disable Trail when has Freezed Position + // bool mAllowFreeze; // Allow Freezing + // double mFreezeDistance; // Specify Freeze Start Drawdown in Point + // bool mRemoveFreezedPositionTPSL; // Remove Freezed Positions TPSL + // bool mDisableTrailWhenFreezedPosition; // Disable Trail when has Freezed Position // // Support ... - bool mAllowSupport; // Allow Support - double mSupportStartDistance; // Specify Start Support Drawdown in Point - int mMaxAllowedSupport; // Max Allowed Number of Support Position - double mSupportVolumeMultiplier; // Specify Support Volume Multiplier - bool mMultiplySupportLevelOnVolume; // Multiply Support Level on Volume Multiplier - bool mDoSupportOnConditions; // Do Support on Conditions - int mDelayBetweenTwoSupport; // Delay Between To Support in Second + // bool mAllowSupport; // Allow Support + // double mSupportStartDistance; // Specify Start Support Drawdown in Point + // int mMaxAllowedSupport; // Max Allowed Number of Support Position + // double mSupportVolumeMultiplier; // Specify Support Volume Multiplier + // bool mMultiplySupportLevelOnVolume; // Multiply Support Level on Volume Multiplier + // bool mDoSupportOnConditions; // Do Support on Conditions + // int mDelayBetweenTwoSupport; // Delay Between To Support in Second // // Partial Close (In Drawdown) ... diff --git a/Experts/x-saherelm.test-panel.ea.mq5 b/Experts/x-saherelm.test-panel.ea.mq5 index 5cf6c3bc..ed70257d 100644 --- a/Experts/x-saherelm.test-panel.ea.mq5 +++ b/Experts/x-saherelm.test-panel.ea.mq5 @@ -16,6 +16,7 @@ CTrade trade; string mTag; // +// SIGNALLING GUI ... XCPanel eaSignallingPanel; string eaSignallingPanelName; XCButton eaSignallingBtn; @@ -25,10 +26,45 @@ string eaSignallingLongBtnName; XCButton eaSignallingShortBtn; string eaSignallingShortBtnName; +// +// PROTECTOR GUI ... +XCPanel eaProtectorPanel; +string eaProtectorPanelName; +XCButton eaHedgingBtn; +string eaHedgingBtnName; +XCButton eaTraillingBtn; +string eaTraillingBtnName; +XCButton eaFreezingBtn; +string eaFreezingBtnName; +XCButton eaSupportingBtn; +string eaSupportingBtnName; + // bool eaEnableLongs = true; bool eaEnableShorts = true; +// +bool mAllowHedge = true; // Allow Protector to Hedge Positions +double eaHedgeMinVolumeStep = 0.01; // Minimum Volume Step For Hedge +int eaMinimumOpenPositionsForHEHedge = 2; // Minimum Open Positions For HE Hedge +double eaHedgeHEMinProfitPerVolumeStep = 1; // Minimum Required Profit For HE Hedge Per Volume Step +double eaHedgeBEMinProfitPerVolumeStep = 0.5; // Minimum Required Profit For BE Hedge Per Volume Step + +// +bool mAllowTrail = true; // Allow Trail Stop for Positions +double eaTrailStartDistance = 35; // Specify Trail Start in Point +double eaTrailStep = 10; // Trail Step in Point + +// +bool mllowFreeze = false; // Allow Freezing +double eaFreezeVolumeMultiplier = 3; // Specify Freeze Volume Multiplier +double eaFreezeDistance = 100; // Specify Freeze Start Drawdown in Point + +// +bool mAllowSupport = false; // Allow Support +double eaSupportStartDistance = 0; // Specify Start Support Drawdown in Point +double eaSupportVolumeMultiplier = 1; // Specify Support Volume Multiplier + //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ @@ -69,6 +105,7 @@ void OnChartEvent(const int id, const long &lparam, const double &dparam, const { // // Handle Object Movement ... + eaProtectorPanel.OnEvent(id, lparam, dparam, sparam); eaSignallingPanel.OnEvent(id, lparam, dparam, sparam); // @@ -97,6 +134,13 @@ bool InitialGUI() return result; } + // + result = InitialProtectorGUI(); + if (!result) + { + return result; + } + // ChartRedraw(0); @@ -111,8 +155,116 @@ void UpdateGUI() { // UpdateSignallingGUI(); + UpdateProtectorGUI(); } +/** + * Destroy GUI ... + */ +void DestroyGUI() +{ + // + DestroySignallingGUI(); + DestroyProtectorGUI(); +} + +/** + * Handle Object's Click Events ... + * + * @param name: Clicked Object Name + */ +void HandleOnClickEvent(string name) +{ + // + if (!IsValid(name)) + { + return; + } + + // + bool isClicked = false; + + // + // Signalling State Button ... + if (name == eaSignallingBtnName) + { + // + isClicked = true; + HandleChangeState(); + eaSignallingBtn.SetState(false); + Print("State Button Clicked ..."); + } + // + // Long Signalling State ... + else if (name == eaSignallingLongBtnName) + { + // + isClicked = true; + HandleChangeLongsState(); + eaSignallingLongBtn.SetState(false); + Print("Long State Button Clicked ..."); + } + // + // Short Signalling State ... + else if (name == eaSignallingShortBtnName) + { + // + isClicked = true; + HandleChangeShortsState(); + eaSignallingShortBtn.SetState(false); + Print("Short State Button Clicked ..."); + } + // + // Hedging State Button ... + else if (name == eaHedgingBtnName) + { + // + isClicked = true; + HandleChangeHedgingState(); + eaHedgingBtn.SetState(false); + Print("Hedging State Button Clicked ..."); + } + // + // Trailling State Button ... + else if (name == eaTraillingBtnName) + { + // + isClicked = true; + HandleChangeTraillingState(); + eaTraillingBtn.SetState(false); + Print("Trailling State Button Clicked ..."); + } + // + // Freezing State Button ... + else if (name == eaFreezingBtnName) + { + // + isClicked = true; + HandleChangeFreezingState(); + eaFreezingBtn.SetState(false); + Print("Freezing State Button Clicked ..."); + } + // + // Supporting State Button ... + else if (name == eaSupportingBtnName) + { + // + isClicked = true; + HandleChangeSupportingState(); + eaSupportingBtn.SetState(false); + Print("Supporting State Button Clicked ..."); + } + + // + if (isClicked) + { + UpdateGUI(); + } +} + +// +// SIGNALLING GUI ... + /** * Initialize State and Signalling GUI ... * @@ -143,7 +295,7 @@ bool InitSignallingGUI() // // Create Activation Button ... - string eaSignallingPrefix = eaSignallingPanelName + "_State_"; + string eaSignallingPrefix = eaSignallingPanelName + "_"; // // Signalling ... @@ -248,9 +400,9 @@ void UpdateSignallingGUI() } /** - * Destroy GUI ... + * Destroy Signalling GUI ... */ -void DestroyGUI() +void DestroySignallingGUI() { // eaSignallingBtnName = NULL; @@ -264,54 +416,210 @@ void DestroyGUI() eaSignallingShortBtn.Destroy(); } +// +// PROTECTOR GUI ... + /** - * Handle Object's Click Events ... + * Initial Protector GUI ... * - * @param name: Clicked Object Name + * @return ( bool ) */ -void HandleOnClickEvent(string name) +bool InitialProtectorGUI() { // - if (!IsValid(name)) - { - return; - } + bool result = false; // - // State Button ... - bool isClicked = false; - if (name == eaSignallingBtnName) - { - // - isClicked = true; - HandleChangeState(); - eaSignallingBtn.SetState(false); - Print("State Button Clicked ..."); - } - // - else if (name == eaSignallingLongBtnName) - { - // - isClicked = true; - HandleChangeLongsState(); - eaSignallingLongBtn.SetState(false); - Print("Long State Button Clicked ..."); - } - // - else if (name == eaSignallingShortBtnName) - { - // - isClicked = true; - HandleChangeShortsState(); - eaSignallingShortBtn.SetState(false); - Print("Short State Button Clicked ..."); - } + eaProtectorPanelName = mTag + "PROTECTOR"; // - if (isClicked) + // Create a Panel ... + result = eaProtectorPanel.Create( + eaProtectorPanelName, + 10, + 110, + 300, + 100 // + ); + if (!result) { - UpdateGUI(); + return result; } + eaProtectorPanel.Caption("Protector"); + + // + string eaProtectorPrefix = eaProtectorPanelName + "_"; + + // + // Hedging ... + eaHedgingBtnName = eaProtectorPrefix + "HEDGING_btn"; + result = eaHedgingBtn.Create( + eaHedgingBtnName, + 10, + 130, + 300, + 25 // + ); + if (!result) + { + return result; + } + eaHedgingBtn.SetText(""); + eaProtectorPanel.Add(eaHedgingBtnName); + + // + // Trailling ... + eaTraillingBtnName = eaProtectorPrefix + "TRAILLING_btn"; + result = eaTraillingBtn.Create( + eaTraillingBtnName, + 10, + 155, + 300, + 25 // + ); + if (!result) + { + return result; + } + eaTraillingBtn.SetText(""); + eaProtectorPanel.Add(eaTraillingBtnName); + + // + // Freezing ... + eaFreezingBtnName = eaProtectorPrefix + "FREEZING_btn"; + result = eaFreezingBtn.Create( + eaFreezingBtnName, + 10, + 180, + 300, + 25 // + ); + if (!result) + { + return result; + } + eaFreezingBtn.SetText(""); + eaProtectorPanel.Add(eaFreezingBtnName); + + // + // Supporting ... + eaSupportingBtnName = eaProtectorPrefix + "SUPPORTING_btn"; + result = eaSupportingBtn.Create( + eaSupportingBtnName, + 10, + 205, + 300, + 25 // + ); + if (!result) + { + return result; + } + eaSupportingBtn.SetText(""); + eaProtectorPanel.Add(eaSupportingBtnName); + + // + UpdateProtectorGUI(); + + // + return result; +} + +/** + * Update Signalling GUI Content ... + */ +void UpdateProtectorGUI() +{ + // + // Hedging ... + bool isHedgingEnabled = + mAllowHedge && + eaHedgeMinVolumeStep > 0 && + (eaHedgeHEMinProfitPerVolumeStep > 0 || + eaHedgeBEMinProfitPerVolumeStep > 0) && + eaMinimumOpenPositionsForHEHedge >= 0; + + // + color eaHedgingBtnTextColor = isHedgingEnabled + ? clrRed + : clrGreen; + string eaHedgingBtnText = isHedgingEnabled + ? "Deactive Hedging" + : "Active Hedging"; + eaHedgingBtn.SetText(eaHedgingBtnText); + eaHedgingBtn.SetColor(eaHedgingBtnTextColor); + + // + // Trailling ... + bool isTraillingEnabled = + mAllowTrail && + eaTrailStep > 0 && + eaTrailStartDistance >= 0; + + // + color eaTraillingBtnColor = isTraillingEnabled + ? clrRed + : clrGreen; + string eaTraillingBtnText = isTraillingEnabled + ? "Deactive Trailling" + : "Active Trailling"; + eaTraillingBtn.SetText(eaTraillingBtnText); + eaTraillingBtn.SetColor(eaTraillingBtnColor); + + // + // Freezing ... + bool isFreezingEnabled = + mllowFreeze && + eaFreezeDistance > 0 && + eaFreezeVolumeMultiplier > 0; + + // + color eaFreezingBtnColor = isFreezingEnabled + ? clrRed + : clrGreen; + string eaFreezingBtnText = isFreezingEnabled + ? "Deactive Freezing" + : "Active Freezing"; + eaFreezingBtn.SetText(eaFreezingBtnText); + eaFreezingBtn.SetColor(eaFreezingBtnColor); + + // + // Supporting ... + bool isSupportingEnabled = + !isFreezingEnabled && + mAllowSupport && + eaSupportStartDistance > 0 && + eaSupportVolumeMultiplier > 0; + + // + color eaSupportingBtnColor = isSupportingEnabled + ? clrRed + : clrGreen; + string eaSupportingBtnText = isSupportingEnabled + ? "Deactive Supporting" + : "Active Supporting"; + eaSupportingBtn.SetText(eaSupportingBtnText); + eaSupportingBtn.SetColor(eaSupportingBtnColor); +} + +/** + * Destroy Protector GUI ... + */ +void DestroyProtectorGUI() +{ + // + eaHedgingBtnName = NULL; + eaFreezingBtnName = NULL; + eaTraillingBtnName = NULL; + eaSupportingBtnName = NULL; + eaProtectorPanelName = NULL; + + // + eaHedgingBtn.Destroy(); + eaFreezingBtn.Destroy(); + eaTraillingBtn.Destroy(); + eaSupportingBtn.Destroy(); + eaProtectorPanel.Destroy(); } // @@ -357,4 +665,32 @@ void HandleChangeShortsState() eaEnableShorts = !eaEnableShorts; } +/** + * Toggle Hedging State ... + */ +void HandleChangeHedgingState() +{ +} + +/** + * Toggle Trailling State ... + */ +void HandleChangeTraillingState() +{ +} + +/** + * Toogle Freezing State ... + */ +void HandleChangeFreezingState() +{ +} + +/** + * Toogle Supporting State ... + */ +void HandleChangeSupportingState() +{ +} + // \ No newline at end of file diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index a7047058..d9417a8c 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -123,22 +123,22 @@ input group "In Drawdown Positions Protecting"; // // Freeze ... -input group "Freeze"; -input bool eaAllowFreeze = false; // Allow Freezing -input double eaFreezeDistance = 100; // Specify Freeze Start Drawdown in Point -input bool eaRemoveFreezedPositionTPSL = true; // Remove Freezed Positions TPSL -input bool eaDisableTrailWhenFreezedPosition = true; // Disable Trail when has Freezed Position +// input group "Freeze"; +// input bool eaAllowFreeze = false; // Allow Freezing +// input double eaFreezeDistance = 100; // Specify Freeze Start Drawdown in Point +// input bool eaRemoveFreezedPositionTPSL = true; // Remove Freezed Positions TPSL +// input bool eaDisableTrailWhenFreezedPosition = true; // Disable Trail when has Freezed Position // // Support ... -input group "Support"; -input bool eaAllowSupport = false; // Allow Support -input double eaSupportStartDistance = 0; // Specify Start Support Drawdown in Point -input int eaMaxAllowedSupport = 2; // Max Allowed Number of Support Position -input double eaSupportVolumeMultiplier = 1; // Specify Support Volume Multiplier -input bool eaMultiplySupportLevelOnVolume = false; // Multiply Support Level on Volume Multiplier -input bool eaDoSupportOnConditions = true; // Do Support on Conditions -input int eaDelayBetweenTwoSupport = 60; // Delay Between To Support in Second +// input group "Support"; +// input bool eaAllowSupport = false; // Allow Support +// input double eaSupportStartDistance = 0; // Specify Start Support Drawdown in Point +// input int eaMaxAllowedSupport = 2; // Max Allowed Number of Support Position +// input double eaSupportVolumeMultiplier = 1; // Specify Support Volume Multiplier +// input bool eaMultiplySupportLevelOnVolume = false; // Multiply Support Level on Volume Multiplier +// input bool eaDoSupportOnConditions = true; // Do Support on Conditions +// input int eaDelayBetweenTwoSupport = 60; // Delay Between To Support in Second // // Partial Close (In Drawdown) ... @@ -610,20 +610,20 @@ bool InitialEA() // // Freeze ... - eaTradeHandler.AllowFreeze(eaAllowFreeze); - eaTradeHandler.FreezeDistance(eaFreezeDistance); - eaTradeHandler.RemoveFreezedPositionTPSL(eaRemoveFreezedPositionTPSL); - eaTradeHandler.DisableTrailWhenFreezedPosition(eaDisableTrailWhenFreezedPosition); + // eaTradeHandler.AllowFreeze(eaAllowFreeze); + // eaTradeHandler.FreezeDistance(eaFreezeDistance); + // eaTradeHandler.RemoveFreezedPositionTPSL(eaRemoveFreezedPositionTPSL); + // eaTradeHandler.DisableTrailWhenFreezedPosition(eaDisableTrailWhenFreezedPosition); // // Support ... - eaTradeHandler.AllowSupport(eaAllowSupport); - eaTradeHandler.SupportStartDistance(eaSupportStartDistance); - eaTradeHandler.MaxAllowedSupport(eaMaxAllowedSupport); - eaTradeHandler.SupportVolumeMultiplier(eaSupportVolumeMultiplier); - eaTradeHandler.MultiplySupportLevelOnVolume(eaMultiplySupportLevelOnVolume); - eaTradeHandler.DoSupportOnConditions(eaDoSupportOnConditions); - eaTradeHandler.DelayBetweenTwoSupport(eaDelayBetweenTwoSupport); + // eaTradeHandler.AllowSupport(eaAllowSupport); + // eaTradeHandler.SupportStartDistance(eaSupportStartDistance); + // eaTradeHandler.MaxAllowedSupport(eaMaxAllowedSupport); + // eaTradeHandler.SupportVolumeMultiplier(eaSupportVolumeMultiplier); + // eaTradeHandler.MultiplySupportLevelOnVolume(eaMultiplySupportLevelOnVolume); + // eaTradeHandler.DoSupportOnConditions(eaDoSupportOnConditions); + // eaTradeHandler.DelayBetweenTwoSupport(eaDelayBetweenTwoSupport); // // Partial Close (In Profit) ... diff --git a/Strategies/x-saherelm.xch.che.strategy.mq5 b/Strategies/x-saherelm.xch.che.strategy.mq5 index f1b390f6..a6028ba3 100644 --- a/Strategies/x-saherelm.xch.che.strategy.mq5 +++ b/Strategies/x-saherelm.xch.che.strategy.mq5 @@ -147,6 +147,7 @@ public: double entry = 0; double reward = 0; double r2r = R2R(); + double volume = Volume(); ENUM_POSITION_TYPE type = POSITION_TYPE_BUY; ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; @@ -623,7 +624,7 @@ public: type, mode, entry, - mVolume, + volume, sl, tp // ); diff --git a/Strategies/x-saherelm.xch.strategy.mq5 b/Strategies/x-saherelm.xch.strategy.mq5 index 71bd18bb..e30947ab 100644 --- a/Strategies/x-saherelm.xch.strategy.mq5 +++ b/Strategies/x-saherelm.xch.strategy.mq5 @@ -559,6 +559,7 @@ public: double entry = 0; double reward = 0; double r2r = R2R(); + double volume = Volume(); ENUM_POSITION_TYPE type = POSITION_TYPE_BUY; ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; @@ -1292,7 +1293,7 @@ public: type, mode, entry, - mVolume, + volume, sl, tp // );