Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Heikin-Ashi docs #1161

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/_indicators/HeikinAshi.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ IEnumerable<HeikinAshiResult>
- This method returns a time series of all available indicator values for the `quotes` provided.
- It always returns the same number of elements as there are in the historical quotes.
- It does not return a single incremental indicator value.
- The first period will have `null` values since there's not enough data to calculate.
- `HeikinAshiResult` is based on `IQuote`, so it can be used as a direct replacement for `quotes`.

### HeikinAshiResult
Expand Down
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
Loading