Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Type Class Using Indicators Class Data

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

    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

    #2
    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.
    JesseNinjaTrader Customer Service

    Comment


      #3
      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.

      Comment


        #4
        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.



        JesseNinjaTrader Customer Service

        Comment


          #5
          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.

          Comment


            #6
            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.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              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.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Barry Milan, Today, 10:35 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by WeyldFalcon, 12-10-2020, 06:48 PM
              14 responses
              1,428 views
              0 likes
              Last Post Handclap0241  
              Started by DJ888, Yesterday, 06:09 PM
              2 responses
              9 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              40 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Today, 08:51 AM
              2 responses
              16 views
              0 likes
              Last Post bill2023  
              Working...
              X