EaseOfMovementValue uses a stale midpoint after a flat bar

Open Beginner friendly
#10,197 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend

Research direction

Read Indicators/EaseOfMovementValue.cs lines 74–92 and find the related indicator tests. Reproduce the issue with period 1 using the flat bar followed by a non-flat bar described in the issue. Add a regression test that checks the next value is 2, while confirming ordinary bars and the flat bar’s own result retain their existing behavior.

Written by the indexing model from the issue text.

Description

priority:p2

Problem

EaseOfMovementValue returns before updating its previous high/low when a bar is flat. The next non-flat bar therefore measures its midpoint change against an older bar, producing an incorrect indicator value.

Source: Indicators/EaseOfMovementValue.cs, lines 74–92.

Reproduction

Run these updates with period 1, so smoothing does not obscure the result. All bars have positive volume and distinct, increasing timestamps.

using System;
using QuantConnect;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;

var symbol = new Symbol(SecurityIdentifier.GenerateEquity("SPY", Market.USA, false), "SPY");
var time = new DateTime(2024, 1, 2, 9, 30, 0);
var emv = new EaseOfMovementValue(1, 10000);
emv.Update(new TradeBar(time, symbol, 9, 10, 8, 9, 10000, TimeSpan.FromMinutes(1)));
emv.Update(new TradeBar(time.AddMinutes(1), symbol, 20, 20, 20, 20, 10000, TimeSpan.FromMinutes(1)));
emv.Update(new TradeBar(time.AddMinutes(2), symbol, 20, 22, 20, 22, 10000, TimeSpan.FromMinutes(1)));
Console.WriteLine(emv.Current.Value);

Executed result: 24. Expected: 2.

The final midpoint is 21 and the preceding bar's midpoint is 20. The box ratio is (10000 / 10000) / (22 - 20) = 0.5, so EMV should be (21 - 20) / 0.5 = 2. Instead, the flat bar leaves the saved midpoint at 9, yielding (21 - 9) / 0.5 = 24.

Required result

A flat bar must still become the preceding bar for the next midpoint calculation. Cover a positive-volume flat bar followed by a non-flat bar in a regression test, while preserving existing behavior for ordinary bars and the flat bar's own result.

Priority is low because the reproduction is limited to a particular indicator/input sequence; there is no evidence of widespread impact.

Dominant language
C#
Stars
22.6k
Forks
5.4k
Avg merge
11h 39m
Merged PRs (30d)
104

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantConnect/Lean

All issues in QuantConnect/Lean

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.