Skip to content

Commit

Permalink
simplify initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Feb 2, 2024
1 parent 73f6ce5 commit 70e1659
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/e-k/HeikinAshi/HeikinAshi.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ internal static List<HeikinAshiResult> CalcHeikinAshi<TQuote>(
decimal prevOpen = decimal.MinValue;
decimal prevClose = decimal.MinValue;

if (length > 0)
{
TQuote q = quotesList[0];
prevOpen = q.Open;
prevClose = q.Close;
}

// roll through quotes
for (int i = 0; i < length; i++)
{
Expand All @@ -23,15 +30,14 @@ internal static List<HeikinAshiResult> CalcHeikinAshi<TQuote>(
decimal close = (q.Open + q.High + q.Low + q.Close) / 4;

// open
decimal open = (prevOpen == decimal.MinValue) ? (q.Open + q.Close) / 2
: (prevOpen + prevClose) / 2;
decimal open = (prevOpen + prevClose) / 2;

// high
decimal[] arrH = { q.High, open, close };
decimal[] arrH = [q.High, open, close];
decimal high = arrH.Max();

// low
decimal[] arrL = { q.Low, open, close };
decimal[] arrL = [q.Low, open, close];
decimal low = arrL.Min();

HeikinAshiResult r = new(q.Date)
Expand Down

0 comments on commit 70e1659

Please sign in to comment.