• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Type Class Using Indicators Class Data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • aligator
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello aligator,

    Where you have mentioned:
    "Just trying to figure out a way to create a chart style that paints based on a data series resulted from a math function in NinjaTrader"

    This sounds like something that would be better accomplished with an indicator that sets the BarBrush.


    However, chartStyles do get the bars object.
    This means you can get the data of the bar with bars.GetClose(int index) and do any calculations with the data you would like.

    For example:
    bars.GetClose(bars.Count) - bars.GetOpen(bars.Count - 1)

    This would give the difference of the current bars close minus the open of the previous bar.

    I wouldn't be able to completely re-write these scripts on your behalf, but I am happy to assist if you decide to re-write these and get stuck.
    Thanks Chelsea. Yes, I know I can use a separate indicator to paint bars. But I am exploring ways to possibly accomplish that by using an Indicators Class within the ChartStyle Class.

    Many thanks.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello aligator,

    Where you have mentioned:
    "Just trying to figure out a way to create a chart style that paints based on a data series resulted from a math function in NinjaTrader"

    This sounds like something that would be better accomplished with an indicator that sets the BarBrush.


    However, chartStyles do get the bars object.
    This means you can get the data of the bar with bars.GetClose(int index) and do any calculations with the data you would like.

    For example:
    bars.GetClose(bars.Count) - bars.GetOpen(bars.Count - 1)

    This would give the difference of the current bars close minus the open of the previous bar.

    I wouldn't be able to completely re-write these scripts on your behalf, but I am happy to assist if you decide to re-write these and get stuck.

    Leave a comment:


  • aligator
    replied
    Originally posted by NinjaTrader_Jesse View Post
    Hello aligator,

    This would be more involved than I could provide a sample for.

    The logic in the existing cci is intended to be used going forward in processing, or with OnBarUpdate because it uses a price series and sma indicator in its calculation.

    If you wanted to use a ChartStyle for this you would essentially need to work out a way to calculate the value yourself in a different way than using a series and SMA. You will also need to write the SMA logic into this ChartStyle so the cci calculation can access that value

    The existing chart styles use loops to iterate over just the visible bars, however if you wanted to calculate something for the whole series like an indicator you would likely need to loop over all bars to do that. This can be a major impact on performance in this context because you would need to recalculate the whole value every time OnRender is called which is frequent. An indicator does not share this trait because it can reference the prior data in its series and avoids recalculating all bars.

    To expand on how chart styles work I would suggest looking at how the existing chart styles work to paint bars.

    I look forward to being of further assistance.


    Thank you Jesse,

    The CCI is just an example. It can be anything with a simple math expression such as SMA that simply any bar above is green or red if below SMA. Just trying to figure out a way to create a chart style that paints based on a data series resulted from a math function in NinjaTrader.

    Thanks.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello aligator,

    This would be more involved than I could provide a sample for.

    The logic in the existing cci is intended to be used going forward in processing, or with OnBarUpdate because it uses a price series and sma indicator in its calculation.

    If you wanted to use a ChartStyle for this you would essentially need to work out a way to calculate the value yourself in a different way than using a series and SMA. You will also need to write the SMA logic into this ChartStyle so the cci calculation can access that value

    The existing chart styles use loops to iterate over just the visible bars, however if you wanted to calculate something for the whole series like an indicator you would likely need to loop over all bars to do that. This can be a major impact on performance in this context because you would need to recalculate the whole value every time OnRender is called which is frequent. An indicator does not share this trait because it can reference the prior data in its series and avoids recalculating all bars.

    To expand on how chart styles work I would suggest looking at how the existing chart styles work to paint bars.

    I look forward to being of further assistance.



    Leave a comment:


  • aligator
    replied
    Originally posted by NinjaTrader_Jesse View Post
    Hello aligator,

    you would need to make a custom ChartStyle and include a custom calculation in that style. Calling the CCI is not an option, you can however try to recreate the same math it uses in OnRender in the ChartStyle.


    I look forward to being of further assistance.
    Sorry, my mistake, I meant Chart Style not Bars Type. Any chance you can provide an example of script for creating the a math example in OnRender in a ChartStyle (i.e. CandleSticks)?

    Thanks.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello aligator,

    This concept would not be possible, a BarsType cannot call an indicator. Also the BarsType does not control the coloring, that would be the ChartStyle which calling an indicator from is still not possible.

    The most simple solution is to use an indicator, otherwise you would need to make a custom ChartStyle and include a custom calculation in that style. Calling the CCI is not an option, you can however try to recreate the same math it uses in OnRender in the ChartStyle. The OnBarUpdate concepts in the indicator will not directly apply in a ChartStyle, this is something you would need to work out with logic if that is something you wanted to do. Otherwise the best solution is to just use an Indicator for this purpose because that can call the CCI and also paint the bars in much more simple ways.



    I look forward to being of further assistance.

    Leave a comment:


  • aligator
    started a topic Bars Type Class Using Indicators Class Data

    Bars Type Class Using Indicators Class Data

    Dear Support,

    How to use the results of an indicator in a Bars Type class? Any sample scripts is appreciated.

    Here is an example:

    Modify a Bars Type code (i.e. CandleSticks) so that the bars are painted green if CCI >= 100 or Red if CCI <= -100.

    I know that I can add a simple indicator to the chart to accomplish the bar painting, but I want to do this within the Bars Type code.

    Many thanks

Latest Posts

Collapse

Topics Statistics Last Post
Started by cmarkb, Today, 02:15 AM
0 responses
1 view
0 likes
Last Post cmarkb
by cmarkb
 
Started by terminatorT1000, Today, 01:23 AM
0 responses
6 views
0 likes
Last Post terminatorT1000  
Started by jointnusa, Today, 01:00 AM
0 responses
6 views
0 likes
Last Post jointnusa  
Started by jointnusa, Today, 12:59 AM
0 responses
5 views
0 likes
Last Post jointnusa  
Started by alstondn, Today, 12:15 AM
0 responses
5 views
0 likes
Last Post alstondn  
Working...
X