Add average time
This commit is contained in:
@@ -799,6 +799,26 @@ public class TradingBot : Bot, ITradingBot
|
||||
{
|
||||
if (Positions.Any(p => p.Identifier == position.Identifier))
|
||||
{
|
||||
// Update the close date for the trade that actually closed the position
|
||||
var currentCandle = Config.IsForBacktest
|
||||
? OptimizedCandles.LastOrDefault()
|
||||
: ExchangeService.GetCandle(Account, Config.Ticker, DateTime.UtcNow);
|
||||
|
||||
if (currentCandle != null && position.ProfitAndLoss != null)
|
||||
{
|
||||
// Determine which trade closed the position based on realized P&L
|
||||
if (position.ProfitAndLoss.Realized > 0)
|
||||
{
|
||||
// Profitable close = Take Profit
|
||||
position.TakeProfit1.SetDate(currentCandle.Date);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loss or breakeven close = Stop Loss
|
||||
position.StopLoss.SetDate(currentCandle.Date);
|
||||
}
|
||||
}
|
||||
|
||||
await SetPositionStatus(position.SignalIdentifier, PositionStatus.Finished);
|
||||
Logger.LogInformation(
|
||||
$"Position {position.SignalIdentifier} type correctly close. Pnl on position : {position.ProfitAndLoss?.Realized}");
|
||||
|
||||
Reference in New Issue
Block a user