diff --git a/.vscode/vscode-kanban.json b/.vscode/vscode-kanban.json index f9390730..2bcf309d 100644 --- a/.vscode/vscode-kanban.json +++ b/.vscode/vscode-kanban.json @@ -11,13 +11,14 @@ "mime": "text/markdown" }, "details": { - "content": "- [] Hedge;", + "content": "- [] Hedge;\n- [] Protector Start;\n", "mime": "text/markdown" }, "id": "89", "references": [ "90", - "91" + "91", + "92" ], "title": "Complete Position Protector" }, @@ -34,6 +35,17 @@ "references": [], "title": "Implement BE Hedge Mechanism" }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-09-16T13:08:56.494Z", + "id": "92", + "references": [], + "title": "Implement Protector Start Point" + } + ], + "testing": [ { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -48,7 +60,6 @@ "title": "Implement HE Hedge mechanism" } ], - "testing": [], "done": [ { "assignedTo": { diff --git a/Classes/x-saherelm.x121.xtrade.handler.class.mq5 b/Classes/x-saherelm.x121.xtrade.handler.class.mq5 index 4ad013d7..6629f4da 100644 --- a/Classes/x-saherelm.x121.xtrade.handler.class.mq5 +++ b/Classes/x-saherelm.x121.xtrade.handler.class.mq5 @@ -1043,6 +1043,28 @@ class X121SCTradeHandler : public XSCBaseAlert mMaxDrawdownPercentForOpenTrades = value; } + // + // Protector Start ... + + // + double ProtectorStartDistanceInPoint() + { + return mProtectorStartDistanceInPointl + } + + // + void ProtectorStartDistanceInPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mProtectorStartDistanceInPoint = value; + } + // // Hedge Props ... @@ -1849,6 +1871,56 @@ class X121SCTradeHandler : public XSCBaseAlert return; } } + + // + // Loop Through Main Positions ... + double requiredDistance = ProtectorStartDistanceInPoint(); + if (requiredDistance <= 0) + { + return; + } + + // + int protectedPositions = 0; + for (int i = 0; i < pPositionsCount; i++) + { + // + // Check Position is Protectable or not ... + XPosition iProtected = pPositions[i]; + + // + XPosition iPosition = iProtected.main; + + // + double iSymbolPoint = GetPoints(iPosition.symbol); + double iDistance = MathAbs(iPosition.profit) / iSymbolPoint; + + // + bool isDistancePassed = iDistance >= requiredDistance; + bool isProtected = HandlePositionProtecting(iPosition); + if (isProtected) + { + protectedPositions++; + } + } + + // + if (protectedPositions > 0) + { + // + // Renew Data ... + Clean(pPositions); + int pPositionsCount = GetPositions( + pPositions // + ); + + // + // Validate Count ... + if (!IsValidSize(pPositionsCount)) + { + return; + } + } } // @@ -2057,6 +2129,21 @@ class X121SCTradeHandler : public XSCBaseAlert return result; } + /** + * Handle Protecting Position ... + */ + bool HandlePositionProtecting(XPosition &position) + { + // + bool result = false; + + // + // Here we Make Sure this Position has ... + + // + return result; + } + // // Private ... private: @@ -2083,6 +2170,9 @@ class X121SCTradeHandler : public XSCBaseAlert bool mUseMaxAllowedTradesPerSymbol; // Use Max Allowed Trades Per Symbol double mMaxDrawdownPercentForOpenTrades; // Max Drawdown Percent for Open Trades + // + double mProtectorStartDistanceInPoint; // Protector Start Distance in Point + // // Hedging Properties ... bool mAllowHedge; // Allow Protector to Hedge Positions diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index 627ecbc8..fda73c05 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -440,15 +440,21 @@ bool InitialEA() // // Configure Position Protector ... + // TODO: Configure it using Inputs ... + + // + eaTradeHandler.ProtectorStartDistanceInPoint(35); // // Configure Hedging ... - // TODO: Configure it using Inputs ... eaTradeHandler.AllowHedge(true); eaTradeHandler.HedgeMinVolumeStep(0.01); eaTradeHandler.MinimumOpenPositionsForHEHedge(2); eaTradeHandler.HedgeHEMinProfitPerVolumeStep(0.2); + // + // TODO: Implement ... + // // Configure Strategies ...