Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsInstantiatedOnEachOptimizationIteration reset indicator

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

    IsInstantiatedOnEachOptimizationIteration reset indicator

    Hello Ninjatrader

    When running with IsInstantiatedOnEachOptimizationIteration set to false i have some indicators that is giving me some wierd issues i am trying to troubleshoot.

    I add all indicators to my strategies like this under data loaded. but when the IsInstantiatedOnEachOptimizationIteration set to false this line some times comes with errors.
    I added a print before and after to nail down that it is this line.

    Print(" Before TMA");

    FiltersTMAInd = TMA(Close, FiltersTMAPeriod);

    Print(" After TMA");​


    How do i actually reset the indicators and everything under it, Plots and variables.

    Or should i change the indicators to reset all values under DataLoaded also ?

    From reading the man pages i hot to clear differant types of variables but how do i clear a plot that is defined under state setDefaults ?
    AddPlot(new Stroke(Brushes.Gold, 1), PlotStyle.Line, "Plotname");

    Is it correctley understood a by instantiating an iSeries like this it is being instantiated as a new clear iSeries and does not need to be cleared ?
    FiltersGlobal = new Series<bool>(this);


    Last edited by donto; 12-21-2024, 08:22 AM.
    Donto
    NinjaTrader Ecosystem Vendor - otrading.dk

    #2
    Hello donto,

    What is the full error message you are getting?

    I've tested the suggested code and I am not seeing an error.
    IsInstantedIndicatorCallTest_NT8.zip


    "How do i actually reset the indicators and everything under it, Plots and variables."

    The indicators are cached and automatically generate a new instance of the data or parameters are different. No need (or way) to reset this.

    Plots and the Values collection are automatically reset (for a new generated instance).

    "Or should i change the indicators to reset all values under DataLoaded also ?"

    If your script has private (non-input) variables, these should be assigned initial values in State.DataLoaded (in all scripts).

    "From reading the man pages i hot to clear differant types of variables but how do i clear a plot that is defined under state setDefaults ?
    AddPlot(new Stroke(Brushes.Gold, 1), PlotStyle.Line, "Plotname");​"

    These are automatically reset (for a new generated instance).

    "Is it correctley understood a by instantiating an iSeries like this it is being instantiated as a new clear iSeries and does not need to be cleared ?
    FiltersGlobal = new Series<bool>(this);​"

    This is correct, this would generate a new instance, and this code should be in State.DataLoaded.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea

      After two weeks of troubleshooting i have this issue pointed a bit further down.
      I have written a bunch of indicators and a strategy that can use these indicators as filters, signals etc..

      if i have everything uncompiled in my NinjaTrader instance i can run with IsInstantiatedOnEachOptimizationIteration set to false.

      However if i compile some of these indicators exclude the code from Ninjatrader and imoports the compiled version i start getting this error under optimizations.
      09-01-2025 19:31:38 Default Strategy 'OT_ST_WaddahAttarExplosion': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

      From my strategy in State DataLoaded i have added these two prints to nail down the excact place where it throws me off.

      Print("2 State " + State);

      OT_WaddahAttarExplosion1 = OT_WaddahAttarExplosion(Close, Convert.ToInt32(Sensitivity), Convert.ToInt32(MACD_Fast), true, Convert.ToInt32(MACD_Smooth), Convert.ToInt32(MACD_Slow), true, Convert.ToInt32(MACD_Smooth), Convert.ToInt32(StDev_Bars), 2, DeadZone, true, true);
      Print("3 State " + State);​



      And this is what is in my output windows.

      2 State DataLoaded
      Strategy 'OT_ST_WaddahAttarExplosion': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
      State Terminated​


      as you see it prints the line before the indicator but not the one after.

      this happens for many of my indicators but why.
      Am i doing something wrong ?
      Donto
      NinjaTrader Ecosystem Vendor - otrading.dk

      Comment


        #4
        Hello donto,

        This suggests that the error is in the indicator. The indicator fails to construct and returns a null to the strategy.

        Have you debugged the indicator?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X