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

Refactor AverageTrueRange code with TrueRange code #8171

Open
4 tasks done
femtotrader opened this issue Jul 8, 2024 · 0 comments
Open
4 tasks done

Refactor AverageTrueRange code with TrueRange code #8171

femtotrader opened this issue Jul 8, 2024 · 0 comments

Comments

@femtotrader
Copy link
Contributor

Expected Behavior

Avoid repeating code

Actual Behavior

var greatest = input.High - input.Low;
var value2 = Math.Abs(_previousInput.Close - input.High);
if (value2 > greatest)
greatest = value2;
var value3 = Math.Abs(_previousInput.Close - input.Low);
if (value3 > greatest)
greatest = value3;
_previousInput = input;
return greatest;

public static decimal ComputeTrueRange(IBaseDataBar previous, IBaseDataBar current)
{
var range1 = current.High - current.Low;
if (previous == null)
{
return range1;
}
var range2 = Math.Abs(current.High - previous.Close);
var range3 = Math.Abs(current.Low - previous.Close);
return Math.Max(range1, Math.Max(range2, range3));
}

Looks very similar

Potential Solution

either

  • uses TrueRange inside AverageTrueRange

or (probably harder in C#)

  • creates a SmootherFactory which takes an indicator class and a moving average and return a "SmoothedIndicator" ie an indicator which can return values of internal indicator using the moving average which was defined.

This concept was experimented in Python with talipp in this PR https://github.com/nardew/talipp/pull/147/files

Reproducing the Problem

not concerned

System Information

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant