Fix MGSHBacktest edit hedge position

This commit is contained in:
2025-06-30 10:22:48 -04:00
parent 837bf1a0fc
commit c2596b40f4

View File

@@ -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;