mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-18 10:38:05 +00:00
style: format code with dotnet-format
This commit fixes the style issues introduced in 931bbdb according to the output
from dotnet-format.
Details: https://github.com/mihakralj/QuanTAlib/pull/30
This commit is contained in:
+22
-11
@@ -8,7 +8,8 @@ namespace QuanTAlib;
|
||||
/// of the true range. The true range is the greatest of: current high - current low,
|
||||
/// absolute value of current high - previous close, or absolute value of current low - previous close.
|
||||
/// </remarks>
|
||||
public class Atr : AbstractBase {
|
||||
public class Atr : AbstractBase
|
||||
{
|
||||
private readonly Ema _ma;
|
||||
private double _prevClose, _p_prevClose;
|
||||
|
||||
@@ -19,11 +20,13 @@ public class Atr : AbstractBase {
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// Thrown when period is less than 1.
|
||||
/// </exception>
|
||||
public Atr(int period) {
|
||||
if (period < 1) {
|
||||
public Atr(int period)
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
||||
}
|
||||
_ma = new(1.0/period);
|
||||
_ma = new(1.0 / period);
|
||||
WarmupPeriod = _ma.WarmupPeriod;
|
||||
Name = $"ATR({period})";
|
||||
}
|
||||
@@ -33,7 +36,8 @@ public class Atr : AbstractBase {
|
||||
/// </summary>
|
||||
/// <param name="source">The source object to subscribe to for bar updates.</param>
|
||||
/// <param name="period">The period over which to calculate the ATR.</param>
|
||||
public Atr(object source, int period) : this(period) {
|
||||
public Atr(object source, int period) : this(period)
|
||||
{
|
||||
var pubEvent = source.GetType().GetEvent("Pub");
|
||||
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||
}
|
||||
@@ -41,7 +45,8 @@ public class Atr : AbstractBase {
|
||||
/// <summary>
|
||||
/// Initializes the Atr instance by setting up the initial state.
|
||||
/// </summary>
|
||||
public override void Init() {
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
_ma.Init();
|
||||
_prevClose = double.NaN;
|
||||
@@ -51,11 +56,15 @@ public class Atr : AbstractBase {
|
||||
/// Manages the state of the Atr instance based on whether a new bar is being processed.
|
||||
/// </summary>
|
||||
/// <param name="isNew">Indicates whether the current input is a new bar.</param>
|
||||
protected override void ManageState(bool isNew) {
|
||||
if (isNew) {
|
||||
protected override void ManageState(bool isNew)
|
||||
{
|
||||
if (isNew)
|
||||
{
|
||||
_index++;
|
||||
_p_prevClose = _prevClose;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
_prevClose = _p_prevClose;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +80,8 @@ public class Atr : AbstractBase {
|
||||
/// to smooth the true range values. For the first bar, it uses the high-low range
|
||||
/// as the true range.
|
||||
/// </remarks>
|
||||
protected override double Calculation() {
|
||||
protected override double Calculation()
|
||||
{
|
||||
ManageState(BarInput.IsNew);
|
||||
|
||||
double trueRange = Math.Max(
|
||||
@@ -81,7 +91,8 @@ public class Atr : AbstractBase {
|
||||
),
|
||||
Math.Abs(BarInput.Low - _prevClose)
|
||||
);
|
||||
if (_index < 2) {
|
||||
if (_index < 2)
|
||||
{
|
||||
trueRange = BarInput.High - BarInput.Low;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user