Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Excessive state changes in OnStateChange?

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

    Excessive state changes in OnStateChange?

    Hello. I'm trying to create custom market analyzer columns, but I'm seeing very strange behavior with even simple scripts. Here is my test script:

    Code:
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public class TestColumn : MarketAnalyzerColumn
        {
            protected override void OnStateChange()
            {
                Print(State);
            }
        }
    }
    After this script is compiled, I go to New > Market Analyzer, then Add Instrument(s) > AAPL, and finally Columns > TestColumn. I only have this one row and four columns (including the default Ask price, Bid price, and Last price), yet the output window looks like this:

    Code:
    SetDefaults
    Terminated
    SetDefaults
    SetDefaults
    Terminated
    SetDefaults
    Configure
    SetDefaults
    SetDefaults
    Terminated
    Terminated
    Terminated
    Terminated
    SetDefaults
    Configure
    DataLoaded
    Historical
    Transition
    Realtime
    I don't understand where all of this came from. Why are there so many SetDefaults states? Why are there two Configure states when the docs claim it's only supposed to be called once in the lifetime of the object? Why are there any Terminated states at all, let alone so many? This is not expected behavior at all.

    #2
    Hello Phoenix2518,

    NinjaTrader must create instances of all scripts to display in the Columns window, and creates a new instance when one is added, and when its enabled.

    Below is a public link to the help guide on NinjaScript Lifecycle.


    Below is a public link to a forum post where Matthew has described the lifecycle of a NinjaScript using prints.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I finally had time to review both pages after the holiday. According to the life cycle chart from the first link, we have:

      1) SetDefaults > Terminated for all indicators, to build the list.
      2) SetDefaults > Terminated when selecting an indicator to display its properties.
      3) SetDefaults > Configure > [active/processing states] while the indicator is displayed in the Market Analyzer, followed by Terminated upon exiting.

      Official documentation gives us a total of three SetDefaults, three Terminated, and one Configure. In stark contrast, my situation produces seven SetDefaults, six Terminated (seven upon exiting), and two Configure.

      Just to be sure I didn't have any other classes interfering with my results, I added "this.GetType().ToString()" to the Print statement and tested again. Before each test, I close the Market Analyzer; only then do I clear the output window. Then I open a new Analyzer, add a single stock, and finally add my test column. The following output was produced:

      Code:
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Terminated
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Terminated
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Configure
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Terminated
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Terminated
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Terminated
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Terminated
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... SetDefaults
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Configure
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... DataLoaded
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Historical
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Transition
      NinjaTrader.NinjaScript.MarketAnalyzerColumns.TestColumn ... Realtime
      So the exact same, demonstrated to be from the one trivial class. The question now is, where are four SetDefaults, four Terminated, and one Configure coming from?

      Comment


        #4
        Hello Phoenix2518,

        Our Development has stated they are not wanting to provide the inner workings of how script instances are created / destroyed for the Market Analyzer.

        I can mention there will be new instances created when the Columns window is opened, when an item is selected in the Available list, when the add button is clicked, when the OK button is clicked, and as the actual instance that will be run in the window is created. There may be other internal instances created.

        They have asked if you have a specific use case where this is causing an issue you are not able to work around.

        Are you finding that the instance that makes it to the DataLoaded state is not terminating correctly?
        Last edited by NinjaTrader_ChelseaB; 12-31-2018, 01:55 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by r68cervera, Today, 05:29 AM
        0 responses
        3 views
        0 likes
        Last Post r68cervera  
        Started by geddyisodin, Today, 05:20 AM
        0 responses
        6 views
        0 likes
        Last Post geddyisodin  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        6 responses
        35 views
        0 likes
        Last Post JonesJoker  
        Started by GussJ, 03-04-2020, 03:11 PM
        12 responses
        3,241 views
        0 likes
        Last Post Leafcutter  
        Started by AveryFlynn, Today, 04:57 AM
        0 responses
        7 views
        0 likes
        Last Post AveryFlynn  
        Working...
        X