Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling an Indicator that contains a timer

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

    Calling an Indicator that contains a timer

    I am working with the Timer Example on this page. I've got it working in my script however, when I try to call my Indicator from a hosting Indicator the Timer seems to throw an error. I decided to try to call the TimerExample directly from a new Indicator and I get the same error. Here is the hosting Indicator that I am using to call the TimerExample:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators{
    
        public class CallTimer : Indicator
        {
            TimerExample GUEST = null;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = "Call Timer Test";
                    Name                        = "CallTimer";
                    IsOverlay                    = true;
                    BarsRequiredToPlot            = 0;
                    IsSuspendedWhileInactive    = true;
                }
                else if (State == State.DataLoaded)
                {
                    GUEST = TimerExample(true,true,1500);
                }            
            }
        }
    }
    When I add this to a chart I get these errors:
    Code:
    Indicator 'CallTimer': Error on calling 'SetState' method: Object reference not set to an instance of an object.
    Indicator 'TimerExample': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object
    Last edited by swcooke; 03-03-2020, 12:59 AM.

    #2
    Hello swcooke,

    The example I created uses the ChartControl and is intended to be applied directly to a chart. If the indicator is called from another indicator it is not added to a chart and does not have a ChartControl object.

    I've updated the script to return if the ChartControl is null to ensure this does not cause an error (or function) when called from another indicator.


    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Can you supply a link to the updated zip? Same location?

      Comment


        #4
        Hello swcooke,

        Certainly, below is a link to the post with the updated scripts.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea, for the great support!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          575 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X