Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Executing code sooner

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

    Executing code sooner

    currently I have a Strategy

    However I don't really care if I make a Strategy or an Indicator for this

    If I switch an instrument on the chart, then I noticed that it only executes my code in it after the new instrument has been fully loaded in the chart (meaning all the indicators and everything have been drawn) - so basically once the chart is idle then it executes my strategy code.

    I would like to execute code sooner, as soon as possible after initiating a symbol change in the chart.

    my code doesn't access fancy stuff most strategies or indicators do like bars. All it accesses is the MasterInstrument

    so where could I put my code in my strategy to execute it sooner? or would it make more sense to switch to an indicator and where would i put my code in the indicator to execute as soon as possible?

    #2
    Hello NinjaCustomer,

    Thanks or your inquiry.

    Strategies and indicators will load all historical data for the instrument before it can process the historical data in OnBarUpdate() and transition to realtime data processing. If you are looking for the soonest moment to reference an object that requires data to be loaded (like the MasterInstrument object,) the code can be added in OnStateChange() under State.DataLoaded.

    More information on Sates and the NinjaScript Lifecycle can be referenced in the publicly available documentation below. Please also make sure that any objects you reference are guaranteed to be available in that State.

    NinjaScript Lifecycle - https://ninjatrader.com/support/help...fecycle_of.htm

    OnStateChange() - https://ninjatrader.com/support/help...tatechange.htm

    MasterInstrument - https://ninjatrader.com/support/help...instrument.htm

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      quick simple question

      do all drawing objects get removed upon changing of a chart instrument?

      it seems that way I just want to make sure that they are not secretly still existing somewhere hogging up memory if I didn't explicitly remove them

      Comment


        #4
        Hello NinjaCustomer,

        User created drawing objects will still exist when switching instruments. These will be removed after the chart has been closed. If these are global drawing objects, they will persist.

        NinjaScript drawn drawing objects will stay attached to the script that drew it. These drawing objects will be removed after switching instruments and will be redrawn when the NinjaScript recalculates and the logic allows the drawing object to be be drawn.

        Please let me know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          so if i delete all drawing objects through the UI - then it will delete all of them from all the symbols of the chart?

          Comment


            #6
            Hello NinjaCustomer,

            If you have a chart window with multiple data series added, Remove All Draw Objects will remove all user drawn draw objects in that chart window. This includes drawing objects in separate panels in that chart window.

            I recommend performing quick tests on a chart to verify the behavior you would like to check. For example, you could set up a chart with multiple data series added in separate chart panels then test adding drawing objects to both panels and removing from the UI. If you have any questions on the behavior you are seeing, please don't hesitate to reach out.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            44 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            180 views
            0 likes
            Last Post jeronymite  
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Working...
            X