Skip to content

Commit

Permalink
Add a variable to track if the previous symbol is the target
Browse files Browse the repository at this point in the history
  • Loading branch information
JosueNina committed Dec 18, 2024
1 parent b35326c commit 15929c4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Indicators/Beta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class Beta : BarIndicator, IIndicatorWarmUpPeriodProvider
/// </summary>
private IBaseDataBar _previousInput;

/// <summary>
/// Indicates whether the previous symbol is the target symbol.
/// </summary>
private bool _previousSymbolIsTarget;

/// <summary>
/// Indicates if the time zone for the target and reference are different.
/// </summary>
Expand Down Expand Up @@ -176,6 +181,7 @@ protected override decimal ComputeNextValue(IBaseDataBar input)
if (_previousInput == null)
{
_previousInput = input;
_previousSymbolIsTarget = input.Symbol == _targetSymbol;
var timeDifference = input.EndTime - input.Time;
_resolution = timeDifference.TotalHours > 1 ? Resolution.Daily : timeDifference.ToHigherResolutionEquivalent(false);
return decimal.Zero;
Expand All @@ -186,8 +192,8 @@ protected override decimal ComputeNextValue(IBaseDataBar input)

if (_isTimezoneDifferent)
{
inputEndTime = inputEndTime.ConvertToUtc(_targetTimeZone);
previousInputEndTime = previousInputEndTime.ConvertToUtc(_referenceTimeZone);
inputEndTime = inputEndTime.ConvertToUtc(_previousSymbolIsTarget ? _referenceTimeZone : _targetTimeZone);
previousInputEndTime = previousInputEndTime.ConvertToUtc(_previousSymbolIsTarget ? _targetTimeZone : _referenceTimeZone);
}

// Process data if symbol has changed and timestamps match
Expand All @@ -198,6 +204,7 @@ protected override decimal ComputeNextValue(IBaseDataBar input)
ComputeBeta();
}
_previousInput = input;
_previousSymbolIsTarget = input.Symbol == _targetSymbol;
return _beta;
}

Expand Down

0 comments on commit 15929c4

Please sign in to comment.