From c2596b40f454679c94bb38bb06efd25f13cba085 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 30 Jun 2025 10:22:48 -0400 Subject: [PATCH] Fix MGSHBacktest edit hedge position --- .../Generator/MGSHMomentum/MGSHBacktest.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MarketData/MarketDataLib/Generator/MGSHMomentum/MGSHBacktest.cs b/MarketData/MarketDataLib/Generator/MGSHMomentum/MGSHBacktest.cs index fd99035..920544c 100755 --- a/MarketData/MarketDataLib/Generator/MGSHMomentum/MGSHBacktest.cs +++ b/MarketData/MarketDataLib/Generator/MGSHMomentum/MGSHBacktest.cs @@ -103,10 +103,15 @@ namespace MarketData.Generator.MGSHMomentum if(!BackupSession())return false; MGSHPositions activePositions = ActivePositions.GetPositions(); MGSHPosition position = activePositions.Where(x => x.Symbol.Equals(symbol) && x.PurchaseDate.Equals(purchaseDate)).FirstOrDefault(); - if (null == position) + if (null == position) // if it's not in the active positions then look in the hedge positions { - MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Cannot locate position for symbol '{0}' purchased on {1}.", symbol, purchaseDate.ToShortDateString())); - return false; + MGSHPositions hedgePositions = HedgePositions; + position = hedgePositions.Where(x => x.Symbol.Equals(symbol) && x.PurchaseDate.Equals(purchaseDate)).FirstOrDefault(); + if (null == position) + { + MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Cannot locate position for symbol '{0}' purchased on {1}.", symbol, purchaseDate.ToShortDateString())); + return false; + } } if (!position.PurchaseDate.Equals(purchaseDate)) position.PurchaseDate = purchaseDate; if (!position.TrailingStopLimit.Equals(trailingStop)) position.TrailingStopLimit = trailingStop;