Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

From One Class to Another Class

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

    From One Class to Another Class

    Dear Support,

    Is it possible in NinjaTrader to use the output data from one Ninjatrader Class as input to a different Class?

    For example: I want to develop a type of ChartStyle that will dynamically behave based on input from the public results of an Indicator.

    I am not sure if Classes can be mixed. For example can I include Indicator code, that would require Data Processing States, as input series to ChartStyle code that is Active State.

    Many Thanks.

    #2
    Hello,

    Thank you for the inquiry.

    You could use the ChartControl that is passed in the OnRender of the ChartStyle to see what indicators are applied.

    I tried getting a value and it appears that it is possible, I am unsure if this has any issues surrounding using the indicator collection in this way but you could certainly try it out:

    Code:
    public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
    {
    	Bars bars = chartBars.Bars;
    			
    	try	{
    				
    		foreach(IndicatorBase indicator in chartControl.Indicators)
    		{
    			NinjaTrader.NinjaScript.Indicators.Bollinger b = indicator as NinjaTrader.NinjaScript.Indicators.Bollinger;
    			for (int idx = chartBars.FromIndex; idx < chartBars.ToIndex; idx++)
    			{
    				Print(b.Upper.GetValueAt(idx));
    			}
    		}
    	} catch { } 
    }
    I had used a try/catch as I did see some errors while trying this. Because OnRender runs a lot and may run before objects are created, you need to check for null/ check if objects are valid etc.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the inquiry.

      You could use the ChartControl that is passed in the OnRender of the ChartStyle to see what indicators are applied.

      I tried getting a value and it appears that it is possible, I am unsure if this has any issues surrounding using the indicator collection in this way but you could certainly try it out:

      Code:
      public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
      {
      Bars bars = chartBars.Bars;
      
      try {
      
      foreach(IndicatorBase indicator in chartControl.Indicators)
      {
      NinjaTrader.NinjaScript.Indicators.Bollinger b = indicator as NinjaTrader.NinjaScript.Indicators.Bollinger;
      for (int idx = chartBars.FromIndex; idx < chartBars.ToIndex; idx++)
      {
      Print(b.Upper.GetValueAt(idx));
      }
      }
      } catch { }
      }
      I had used a try/catch as I did see some errors while trying this. Because OnRender runs a lot and may run before objects are created, you need to check for null/ check if objects are valid etc.


      I look forward to being of further assistance.
      Thanks Jesse,

      This is an old subject that I tried and abandoned due to other priorities. But here in a nut shell is what I want to do:

      Create a ChartBars Style add-on based on CandleStick ChartBar to simply paint the bars based on RSI values at different levels. Is this possible, considering that the two classes are different (Active State vs Data Processing States)?

      I know I can simply write and attach an indicator to the chart that would do the same. However, I want to do this by using a Chart Bars Style as part of a larger project.

      Many thanks.

      Comment


        #4
        Hello aligator,

        Thank you for the reply.

        In contrast to the details on what you want to do, using a ChartStyle would not likely be a good solution. ChartStyles are not intended to use indicator data or process bars in the same way, they use the underlying bar data and do simple calculations to render that data in some way I.E. Mountain VS. Candle.

        If you were to try and implement this into a chart style, you would essentially need to recalculate the RSI code every render pass as there is no OnBarUpdate in a ChartStyle. Calling indicators is also not possible in this context so you would have to duplicate the RSI code in the chart style along with figuring out how to make it work in that context. This would not likely be nearly as efficient as an indicator and would likely take more logic to complete due to using OnRender and not having OnBarUpdate.

        Going back to my prior reply, you can experiment with undocumented uses of the indicators collection, however because these scripts are not specifically linked in any way there is no sync or context of knowing what the CurrentBar is. I really wouldn't have any suggestions on trying to pull data from a script that is applied, but you can access them so potentially you can find some way to use that. Another problem with this idea is that you still need to apply an indicator such as the RSI before any of this would work, so this comes back to just making a custom indicator being the cleanest solution for the goal.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello aligator,

          Thank you for the reply.

          In contrast to the details on what you want to do, using a ChartStyle would not likely be a good solution. ChartStyles are not intended to use indicator data or process bars in the same way, they use the underlying bar data and do simple calculations to render that data in some way I.E. Mountain VS. Candle.

          If you were to try and implement this into a chart style, you would essentially need to recalculate the RSI code every render pass as there is no OnBarUpdate in a ChartStyle. Calling indicators is also not possible in this context so you would have to duplicate the RSI code in the chart style along with figuring out how to make it work in that context. This would not likely be nearly as efficient as an indicator and would likely take more logic to complete due to using OnRender and not having OnBarUpdate.

          Going back to my prior reply, you can experiment with undocumented uses of the indicators collection, however because these scripts are not specifically linked in any way there is no sync or context of knowing what the CurrentBar is. I really wouldn't have any suggestions on trying to pull data from a script that is applied, but you can access them so potentially you can find some way to use that. Another problem with this idea is that you still need to apply an indicator such as the RSI before any of this would work, so this comes back to just making a custom indicator being the cleanest solution for the goal.


          I look forward to being of further assistance.
          Thanks a bunch Jesse, great explanation and saving me hours of wondering in nowhere land.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          21 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Working...
          X