Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8's ChartControl.Indicators collection

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

    #16
    Just a quick remark:
    If you .SetInput(Input) the actual IndicatorRenderBase objects on the chart, it all starts working (which means the Values arrays are populated and correct) no matter how you cast them (between IChartObject, IndicatorRenderbase, NinjaSriptBase, IndicatorBase, etc) / how you use them.

    So according to my findings, adding another list just to hold the same objects is not necessary, and the SetInput seems to be callable from anywhere.

    So the following MAY NOT BE the best practice, it works nonetheless:

    PHP Code:
    protected override void OnBarUpdate()
    {
         if (BarsInProgress != 0 ||  CurrentBar <= 1) return;
         
         foreach (Gui.NinjaScript.IndicatorRenderBase irb in ChartControl.Indicators)
         {
                irb.SetInput(Input);
                Print("R "+irb.Name + "\t" + irb.Value[1].ToString());
         }
    } 
    
    Last edited by Zapzap; 11-16-2015, 05:11 AM.

    Comment


      #17
      Originally posted by Zapzap View Post
      Just a quick remark:
      If you .SetInput(Input) the actual IndicatorRenderBase objects on the chart, it all starts working (which means the Values arrays are populated and correct) no matter how you cast them (between IChartObject, IndicatorRenderbase, NinjaSriptBase, IndicatorBase, etc) / how you use them.

      So according to my findings, adding another list just to hold the same objects is not necessary, and the SetInput seems to be callable from anywhere.

      So the following MAY NOT BE the best practice, it works nonetheless:

      PHP Code:
      protected override void OnBarUpdate()
      {
           if (BarsInProgress != 0 ||  CurrentBar <= 1) return;
           
           foreach (Gui.NinjaScript.IndicatorRenderBase irb in ChartControl.Indicators)
           {
                  irb.SetInput(Input);
                  Print("R "+irb.Name + "\t" + irb.Value[1].ToString());
           }
      } 
      
      Fabulous. Now we just need some validation, and maybe they can stick it into the documentation after all? Fingers crossed.

      In fact, methinks that I shall start to use it to initialize all my named instances of indicators.
      Last edited by koganam; 11-16-2015, 07:48 AM.

      Comment


        #18
        This is very similar to the issue I'm facing too. Basically I have defined a new Indicator as below and exposed a new public member that's not previously defined in any of the interfaces it implements (IChartObject, IIndicatorRenderBase etc):

        class MyIndicator : Indicator
        {
        public X {get;}
        }

        However, I want to access this public value (X) in a new drawing tool. So I retrieve the indicator from the collection of indicators that come as part of chartControl object and try to cast it as below:

        MyIndicator myInd = chartControl.Indicators.First() as MyIndicator;
        myInd.X // Throws null ref exception

        However, this always results to null, even though I know its an active real time indicator.
        myInd is always null.

        I think it definitely would be useful to be able to access an indicators property in a non-static way. I can define a global static variable for this, but that's not an ideal design, as I could have this indicator running on multiple charts.

        PS: This is also on NT8

        Comment


          #19
          Originally posted by tanbyte View Post
          However, I want to access this public value (X) in a new drawing tool ...
          Hello,

          I am using this code to reference to the main indicator inside the drawing tool:

          Code:
          public override void OnRender(ChartControl chartControl, ChartScale chartScale)
          		{	
          			
          			if( this.refToIndi == null && chartControl != null && chartControl.Indicators != null && chartControl.Indicators.Count > 0)
          			{
          				foreach( NinjaTrader.Gui.NinjaScript.IndicatorRenderBase o in chartControl.Indicators )
          				{
          					if( o.Panel == -1 && o is Zi8MyIndicator )
          					{
          						this.refToIndi = (Zi8MyIndicator)o;
          						break;
          					}
          				}
          			}
          			
          			if( this.refToIndi == null || this.refToIndi.Myconfig == null )
          			{
          				//
          				// refToIndi.Myconfig vale null si se ha pasado por el Disposed del indicador,
          				// p.ej. al eliminar el indicador del chart o al reinicializarlo.
          				//
          				return;
          			}
          I hope this helps you to find your solution.
          Last edited by cls71; 02-07-2016, 04:48 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          637 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X