From 2e365b2bc24d5030247a04279453661ecbd29ba7 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 24 Jun 2024 23:12:29 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x121.setup.xea.mq5 | 232 +++++++++++++++----------- Experts/x-saherelm.x121.ea.mq5 | 70 ++++---- 2 files changed, 165 insertions(+), 137 deletions(-) diff --git a/Classes/x-saherelm.x121.setup.xea.mq5 b/Classes/x-saherelm.x121.setup.xea.mq5 index e0413809..0c7c3d84 100644 --- a/Classes/x-saherelm.x121.setup.xea.mq5 +++ b/Classes/x-saherelm.x121.setup.xea.mq5 @@ -5040,115 +5040,143 @@ private: // Handle Force State Management ... void EQMHandleForceState() { - // - return; - // XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); - if (!IsValidSize(positionsCount)) - { - // - EQMClearAllForceStates(); - - // - return; - } - - // - // Search For Force State Per Each Setup ... - // - int forceCount = 0; - int setupsCount = CountSetups(); - if (IsValidSize(setupsCount)) - { - // - int maxAllowed = MaxAllowedTrades(); - bool perDirection = UseMaxAllowedPerDirection(); - - // - for (int i = 0; i < setupsCount; i++) - { - // - string iSymbol = mSetups[i].GetSymbol(); - ENUM_TIMEFRAMES iPeriod = mSetups[i].GetPeriod(); - - // - XPosition iPositions[]; - int iPositionsCount = mTrader.GetPositions( - iPositions, - iSymbol, - NULL, // All Providers ... - NULL, // All Periods ... - NULL, // All Types ... - true // Filter By Magic ... - ); - if (!IsValidSize(iPositionsCount)) - { - continue; - } - - // - // Counting Positions ... - int longs; - double longProfits; - double longVolumes; - - // - int shorts; - double shortProfits; - double shortVolumes; - - // - CountPositions( - iPositions, - // - longs, - longProfits, - longVolumes, - // - shorts, - shortProfits, - shortVolumes // - ); - - // - bool isMaxReached = - maxAllowed <= 0 - ? false - : !perDirection - ? longs + shorts >= maxAllowed - : longs >= maxAllowed && shorts >= maxAllowed; - double volumeSummary = longVolumes + shortVolumes; - double profitsSummary = longProfits + shortProfits; - - // - bool isIInForce = - // - maxAllowed <= 0 - ? profitsSummary < 0 && - longVolumes == shortVolumes - : isMaxReached && - profitsSummary < 0 && - longVolumes == shortVolumes - // - ; - if (isIInForce) - { - // - forceCount++; - mSetups[i].ForceState(true); - } - } - } - - // - bool isForce = forceCount >= 1; - if (!isForce) + if (!IsValidSize(positionsCount) || positionsCount <= 4) { return; } + // + double minRequiredProfitPerTrade = MinRequiredProfitPerTrade(); + double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor(); + + // + double profit = SpecifiedCalculatePositionsProfit(positions); + double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( + positions, + minRequiredProfitPerTrade, + minRequiredProfitPerVolumeFactor // + ); + + // + bool canClose = + profit > 0 && + (profit == requiredProfit || + profit >= requiredProfit / 2); + if (canClose) { + DoEQMForceClose(); + } + + return; + + // // + // XPosition positions[]; + // int positionsCount = mTrader.GetPositions(positions); + // if (!IsValidSize(positionsCount)) + // { + // // + // EQMClearAllForceStates(); + + // // + // return; + // } + + // // + // // Search For Force State Per Each Setup ... + // // + // int forceCount = 0; + // int setupsCount = CountSetups(); + // if (IsValidSize(setupsCount)) + // { + // // + // int maxAllowed = MaxAllowedTrades(); + // bool perDirection = UseMaxAllowedPerDirection(); + + // // + // for (int i = 0; i < setupsCount; i++) + // { + // // + // string iSymbol = mSetups[i].GetSymbol(); + // ENUM_TIMEFRAMES iPeriod = mSetups[i].GetPeriod(); + + // // + // XPosition iPositions[]; + // int iPositionsCount = mTrader.GetPositions( + // iPositions, + // iSymbol, + // NULL, // All Providers ... + // NULL, // All Periods ... + // NULL, // All Types ... + // true // Filter By Magic ... + // ); + // if (!IsValidSize(iPositionsCount)) + // { + // continue; + // } + + // // + // // Counting Positions ... + // int longs; + // double longProfits; + // double longVolumes; + + // // + // int shorts; + // double shortProfits; + // double shortVolumes; + + // // + // CountPositions( + // iPositions, + // // + // longs, + // longProfits, + // longVolumes, + // // + // shorts, + // shortProfits, + // shortVolumes // + // ); + + // // + // bool isMaxReached = + // maxAllowed <= 0 + // ? false + // : !perDirection + // ? longs + shorts >= maxAllowed + // : longs >= maxAllowed && shorts >= maxAllowed; + // double volumeSummary = longVolumes + shortVolumes; + // double profitsSummary = longProfits + shortProfits; + + // // + // bool isIInForce = + // // + // maxAllowed <= 0 + // ? profitsSummary < 0 && + // longVolumes == shortVolumes + // : isMaxReached && + // profitsSummary < 0 && + // longVolumes == shortVolumes + // // + // ; + // if (isIInForce) + // { + // // + // forceCount++; + // mSetups[i].ForceState(true); + // } + // } + // } + + // // + // bool isForce = forceCount >= 1; + // if (!isForce) + // { + // return; + // } + // } diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index 1c855b82..da93cc7b 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -44,15 +44,15 @@ input group "Signals"; //,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb // EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb // EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb,XAUUSDb,NZDUSDb,AUDUSDb,USDCADb,BTCUSD,ETHUSD -input string x121EASymbols = "EURUSDb,USDCHFb,USDJPYb,GBPUSDb"; // Symbols -input bool x121EAUseAllSymbols = false; // Use All Available Symbols -input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols -input bool x121EAAllowLong = true; // Allow Long Trades -input bool x121EAAllowShort = true; // Allow Short Trades -input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts -input int x121EADelayBetweenTwoSignal = 5; // Delay Between two Same Signals -input int x121EAReuiredSignalVerifications = 1; // Required Verifications for Signals -input bool x121EAGetVerificationFromOtherTimeFrames = false; // Get Verifications from Other Time Frames +input string x121EASymbols = "USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols +input bool x121EAUseAllSymbols = false; // Use All Available Symbols +input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols +input bool x121EAAllowLong = true; // Allow Long Trades +input bool x121EAAllowShort = true; // Allow Short Trades +input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts +input int x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals +input int x121EAReuiredSignalVerifications = 3; // Required Verifications for Signals +input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames // // Risk Management ... @@ -60,11 +60,11 @@ input group "Risk Management"; input double x121EAVolume = 0.01; // Static Volume input double x121EATPPoint = 1000; // TP Point input double x121EASLPoint = 1000; // SL Point -input int x121EAMaxAllowedTrades = 4; // Max Allowed Positions Per Symbol +input int x121EAMaxAllowedTrades = 2; // Max Allowed Positions Per Symbol input int x121EAMinFreeMargingForOpenTrades = 500; // Min Margin For Opening Trades input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction input bool x121EAIgnoreSL = true; // Ignore Calculated SL -input bool x121EAIgnoreTP = false; // Ignore Calculated TP +input bool x121EAIgnoreTP = true; // Ignore Calculated TP // // Protection ... @@ -77,43 +77,43 @@ input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit // input group "Trailling"; input bool x121EAAllowTrailStop = false; // Enable Trailling Stop Losses -input bool x121EADisableTrailingWhenOpposit = true; // Disable Trailling When has Opposite In Drawdown -input double x121EAFirstTrailDistance = 100; // Start Trailling Distance -input double x121EAFirstTrailPoint = 60; // First Stop Trail -input double x121EANextTrailDistance = 50; // Next Trailling Distance -input double x121EANextTrailPoint = 25; // Next Trailling Step +input bool x121EADisableTrailingWhenOpposit = false; // Disable Trailling When has Opposite In Drawdown +input double x121EAFirstTrailDistance = 100; // Start Trailling Distance +input double x121EAFirstTrailPoint = 60; // First Stop Trail +input double x121EANextTrailDistance = 50; // Next Trailling Distance +input double x121EANextTrailPoint = 25; // Next Trailling Step // input group "Supporting"; -input bool x121EAAllowSupport = false; // Allow Support Signals -input bool x121EASupportOnlyForces = false; // Support Only Force Signals -double x121EASupportDistance = 50; // Supporting Distance -input int x121EAMaxNumberOfSupports = 1; // Max Number of Support Signals -input double x121EASupportVolumeMultiplier = 2.0; // Support Signals Volume Multiplier -input double x121EAMaxAllowedSupportVolume = 0.04; // Max Allowed Support Signals Volume +input bool x121EAAllowSupport = false; // Allow Support Signals +input bool x121EASupportOnlyForces = false; // Support Only Force Signals +double x121EASupportDistance = 0; // Supporting Distance +input int x121EAMaxNumberOfSupports = 0; // Max Number of Support Signals +input double x121EASupportVolumeMultiplier = 2; // Support Signals Volume Multiplier +input double x121EAMaxAllowedSupportVolume = 0; // Max Allowed Support Signals Volume // input group "Grid"; -input bool x121EAAllowGrid = false; // Allow Grid Signals -input bool x121EAGridOnlyForces = true; // Grid Only Force Signals -input int x121EAMaxNumberOfGrids = 5; // Max Number of Grid Signals -input double x121EAGridDistance = 100; // Grid Distance -input double x121EAGridVolumeMultiplier = 2.0; // Grid Volume Multiplier -input double x121EAMaxAllowedGridVolume = 0.04; // Max Allowed Grid Signals Volume +input bool x121EAAllowGrid = false; // Allow Grid Signals +input bool x121EAGridOnlyForces = false; // Grid Only Force Signals +input int x121EAMaxNumberOfGrids = 0; // Max Number of Grid Signals +input double x121EAGridDistance = 0; // Grid Distance +input double x121EAGridVolumeMultiplier = 0; // Grid Volume Multiplier +input double x121EAMaxAllowedGridVolume = 0; // Max Allowed Grid Signals Volume // input group "Recovery"; -input bool x121EAAllowRecovery = false; // Allow Recovery Signals -input bool x121EARecoverOnlyForces = true; // Recover Only Force Signals -input int x121EAMaxNumberOfRecoveries = 2; // Max Number of Recovery Signals -input double x121EARecoveryDistance = 100; // Recovery Distance -input double x121EARecoveryVolumeMultiplier = 2; // Recovery Volume Multiplier -input double x121EAMaxAllowedRecoveryVolume = 0.08; // Max Allowed Recovery Signals Volume +input bool x121EAAllowRecovery = false; // Allow Recovery Signals +input bool x121EARecoverOnlyForces = false; // Recover Only Force Signals +input int x121EAMaxNumberOfRecoveries = 0; // Max Number of Recovery Signals +input double x121EARecoveryDistance = 0; // Recovery Distance +input double x121EARecoveryVolumeMultiplier = 0; // Recovery Volume Multiplier +input double x121EAMaxAllowedRecoveryVolume = 0; // Max Allowed Recovery Signals Volume // input group "Hedging"; input int x121EARestingAfterHedge = 1000; // Resting Seconds After Hedge -input double x121EAMinRequiredProfitPerTrade = 0.5; // Minimum Required Profit for Hedging +input double x121EAMinRequiredProfitPerTrade = 0.3; // Minimum Required Profit for Hedging input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume //