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

Please add a tutorial on adding an indicator #180

Closed
codebeaulieu opened this issue Jan 30, 2022 · 5 comments
Closed

Please add a tutorial on adding an indicator #180

codebeaulieu opened this issue Jan 30, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@codebeaulieu
Copy link

I've got the charts up and running locally. I've plugged in Polygon to get real time data, however, I am unable to get a new indicator to draw on the chart.

I've added a new endpoint to the main controller:

    [HttpGet("ZigZag")]
    public async Task<IActionResult> GetZigZag()
    {
        try
        {
            var candles = await this.PolygonService.GetCandles("TSLA", TimeInterval.Day, 300);
            var quotes = candles.ConvertToQuotes();
            IEnumerable<ZigZagResult> results =
                quotes.GetZigZag(EndType.Close)
                    .Where(x => x.Date >= dateStart);

            return Ok(results);
        }
        catch (ArgumentOutOfRangeException rex)
        {
            return BadRequest(rex.Message);
        }
    }

Then I added an entry into the indicator meta:

// ZigZag
            new IndicatorList
            {
                Name = "ZigZag",
                Uiid = "ZigZag",
                LabelTemplate = "ZigZag([P1])",
                Endpoint = $"{baseUrl}/ZigZag/",
                Category = "pivots",
                ChartType = "overlay",
                Parameters = new List<IndicatorParamConfig>
                {
                    new IndicatorParamConfig {
                        DisplayName = "Percent Change",
                        ParamName = "percentChange",
                        DataType = "number",
                        Order = 1,
                        Required = true,
                        DefaultValue = 5,
                        Minimum = 1,
                        Maximum = 10
                    }
                },
                Results = new List<IndicatorResultConfig>{
                    new IndicatorResultConfig {
                        LabelTemplate = "ZigZag([P1])",
                        DisplayName = "ZigZag",
                        DataName = "zigzag",
                        DataType = "number",
                        LineType = "solid",
                        DefaultColor = standardBlue
                    }
                }
            },

I do have 168 results from the ZigZag output:

Screen Shot 2022-01-30 at 9 42 09 AM

This is the result when I add the indicator to the chart.

screenshot

Could you please provide guidance on getting this indicator to draw?
What are the steps, from a high level to make an indicator draw?

If you can guide me on how to successfully add a new indicator, I'll be happy to write the tutorial.

@DaveSkender
Copy link
Member

So far, everything you've done looks directionally right: 1) add the API endpoint and 2) add the chart metadata -- is mostly all you'd need to do. Adding your own data feed adds one additional challenge around handling date ranges. The .Where(x => x.Date >= dateStart); in the API was really tailored for the static dataset of the demo data.

For troubleshooting, I think the next thing I'd do is:

  1. Use Dev Console in your browser and check the "Network" calls to see if the API data is hitting the browser and that the "data name" matches what you see there.
  2. Check the date range on the API data vs. what's actually shown on the chart. Could be something as simple as the chart visually being out of range.

@DaveSkender
Copy link
Member

DaveSkender commented Jan 30, 2022

The next thing in my backlog for this demo site is to add an updating data-source, so I'll be looking at this particular issue more deeply. If you want to help with those instructions to add indicators; I'd be super happy for that contribution; otherwise, I'll add it, since I do want the demo site to cover all the indicators in the library and if we can make it easier for other contributors to help (or extend on their own), that'd be a good thing to do.

@DaveSkender DaveSkender added the enhancement New feature or request label Jan 30, 2022
@DaveSkender DaveSkender moved this from Maybe to Do Next in Stock Indicators for .NET Jan 30, 2022
@DaveSkender DaveSkender mentioned this issue Jan 30, 2022
@DaveSkender
Copy link
Member

Pull Request #181 shows the code diff of how to add an indicator. One unique thing that I have to improve here is how to handle enum parameters. As you can see, I just made two endpoints, one for each enum option. Not ideal, but it works as an example.

@DaveSkender
Copy link
Member

Dan, you okay with the above PR as an example? I’ll try to make this repo more reusable opportunistically going forward. I had really only set it up as a rough demo site initially, so there might be some aspects that don’t work well out of the box for real world scenarios.

@codebeaulieu
Copy link
Author

@DaveSkender Yeah, that looks great. Sorry for lack of response, this will be a weekend type project for me.

Repository owner moved this from Do Next to Done in Stock Indicators for .NET Feb 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants