From ef88f8ec6aa6e003d3203b7d7b88d98eef3888ec Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 5 Oct 2024 13:00:10 +0330 Subject: [PATCH] add new features to trade handler and protector ... --- .../x-saherelm.x121.xtrade.handler.class.mq5 | Bin 167572 -> 177998 bytes Experts/x-saherelm.x121.ea.mq5 | 29 +++++----- Libraries/x-saherelm.xtrade.lib.mq5 | 52 +++++++++++------- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Classes/x-saherelm.x121.xtrade.handler.class.mq5 b/Classes/x-saherelm.x121.xtrade.handler.class.mq5 index 21044ed47a652ad45e2055291849e6c2127dbf88..641df2a6894a67039adfe462db9a8ac994e240bb 100644 GIT binary patch delta 3176 zcmb_edu&tZ75~l`$8lWa-Xyk@K;qm5NS)w3NU|z%oDe62J_y7qsWQ4K*d$I9k(e|| zDXXRswoaQmsRA9wS?L4QQc4kOO`%*=RjrY>R;dt*)Jm;DVnNzgwjyd!|Jbyt+qu4Z zjMu8H)z#Jg?)NI-#!p^84$%5N_)8tXg&h1H`7l;)e*0*x z87E(~R6fG63^NQnQosd8fB_lj_9(+R%3uvLcoEUZz(w>qc>U%2MX%X%u#vh~fo)|c zJN7LHh#`FG-G8oLq*=UbFRee>^yZ3R(sUOnG&%r2`q&2>sp=}YG5)2wXd4qoy@?b< z>|K;8qKdU5O1p=l2Ak`>6f2Qc6l#$sGW(&9f)9X+9`=Kmf=|QyG?W4Mv_Ub3Ph82t zOJ8~@5d}LIT=me645+2aap|~+hxwo%hoqh2yQDj9M08>xe-*jP zp@NbLu+!mUS+Hvz-@+)vb31!f(a1L5Y2^Q=Jm0ZLl!^wiL|9X=ibbw+vcC$BjM+`m zX(+aF-yYCflVA-!(yx0jzxdV#j3yNVX)nrWdz>*7+=TP3pqIbl|s)s zp^V(EP>^%m4q}Kd{{mLibO4r8^B=*jx9l`o%CMwbpZ9`|rc1#MBebRh?xWZ>uz(jo z_)8boei78|qGTH=X>2iur})4@E5`h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herelm.x121.ea.mq5 index f3c429c2..57882902 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -93,7 +93,8 @@ input double eaMaxDrawdownPercentForOpenTrades = 3; // Max Drawdown Percent for // Protector ... input group "Protector"; input bool eaUseForceMomentumsInProtection = false; // Use Force Momentums In Protection; -input int eaDelayBarBetweenTwoSameSignal = 5; // Delay Bars Between Two Same Type Signal +input int eaDelayBarBetweenTwoSignal = 5; // Delay Bars Between Two Signal +input double mAcceptNextSameTypeSignalWhenLastInProfit = 50; // Accept Next Same Type Signal When Last in Profit in Point // // Protector > Hedging Properties ... @@ -114,6 +115,7 @@ input group "Trail"; input bool eaAllowTrail = true; // Allow Trail Stop for Positions input double eaTrailStartDistance = 35; // Specify Trail Start in Point input double eaTrailStep = 10; // Trail Step in Point +input int eaRemoveTPAfterTrailedLevel = 4; // Remove Trailed Position TP after Level input bool eaOnlyTrailUnprotected = true; // Only Trail Unprotected Positionss // @@ -586,7 +588,7 @@ bool InitEA() // eaTradeHandler.UseForceMomentumsInProtection(eaUseForceMomentumsInProtection); - eaTradeHandler.DelayBarBetweenTwoSameSignal(eaDelayBarBetweenTwoSameSignal); + eaTradeHandler.DelayBarBetweenTwoSignal(eaDelayBarBetweenTwoSignal); // // Configure Hedging ... @@ -602,9 +604,10 @@ bool InitEA() // // Trail ... eaTradeHandler.AllowTrail(eaAllowTrail); - eaTradeHandler.TrailStartDistance(eaTrailStartDistance); eaTradeHandler.TrailStep(eaTrailStep); + eaTradeHandler.TrailStartDistance(eaTrailStartDistance); eaTradeHandler.OnlyTrailUnprotected(eaOnlyTrailUnprotected); + eaTradeHandler.RemoveTPAfterTrailedLevel(eaRemoveTPAfterTrailedLevel); // // Partial Close (In Profit) ... @@ -816,15 +819,15 @@ bool InitEA() // // Register XICHWAP Strategy ... - // - bool isEURUSD = _symbolParser.IsEURUSD(_Symbol); - bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol); - bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol); - bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol); - bool canRegisterICHWAP = isEURUSD || - isGBPUSD || - isUSDCHF || - isUSDJPY; + // + bool isEURUSD = _symbolParser.IsEURUSD(_Symbol); + bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol); + bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol); + bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol); + bool canRegisterICHWAP = isEURUSD || + isGBPUSD || + isUSDCHF || + isUSDJPY; if (canRegisterICHWAP) { // @@ -1353,7 +1356,7 @@ void OnSignalRecieved( // // Check Signal Delay ... datetime currentTime = TimeCurrent(); - int delay = eaDelayBarBetweenTwoSameSignal; + int delay = eaDelayBarBetweenTwoSignal; bool isDelayPassed = delay <= 0 ? true : !IsValid(lastSignalOn) diff --git a/Libraries/x-saherelm.xtrade.lib.mq5 b/Libraries/x-saherelm.xtrade.lib.mq5 index 5985c04a..c0f0128a 100644 --- a/Libraries/x-saherelm.xtrade.lib.mq5 +++ b/Libraries/x-saherelm.xtrade.lib.mq5 @@ -527,26 +527,6 @@ struct XPosition return result; } - // - // Find Risk ... - double GetRisk() - { - // - double result = 0; - - // - if (!IsValid()) - { - return 0; - } - - // - result = MathAbs(entry - sl); - - // - return result; - } - // double GetPointsValue() { @@ -591,6 +571,26 @@ struct XPosition return result; } + // + // Find Risk ... + double GetRisk() + { + // + double result = 0; + + // + if (!IsValid()) + { + return 0; + } + + // + result = MathAbs(entry - sl); + + // + return result; + } + // // Find Reward ... double GetReward() @@ -611,6 +611,18 @@ struct XPosition return result; } + // + double GetRewardInPoint() { + // + double result = 0; + + // + result = GetReward() / GetPoints(); + + // + return result; + } + // // Find Risk Reward Ratio ... double GetRiskRewardRatio()