Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

'SetState' error

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

    'SetState' error

    Getting this error .. not sure why. Indicator 'Test01': Error on calling 'SetState' method: Exception has been thrown by the target of an invocation.

    Here's my OnStateChange() code:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "Test01";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DrawOnPricePanel = false;
    IsSuspendedWhileInactive = true;
    PaintPriceMarkers = false;
    AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.Line, "Macd");
    AddPlot(new Stroke(Brushes.DarkViolet, 2), PlotStyle.Line, "Avg");
    AddPlot(new Stroke(Brushes.DodgerBlue, 4), PlotStyle.Line, "Diff");
    AddLine(Brushes.DarkGray,0, "Zeroline");
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    fastEma = new Series<double>(this);
    slowEMA = new Series<double>(this);
    diff = new Series<double>(this);
    }
    }

    #2
    Hello pman777,

    I am not able to reproduce this behavior with the provided code.

    Below is a public link to a video of the test.


    Attached is the script exported so that you may import easily on your end and test this script.


    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) 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.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thank you Chelsea

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      55 views
      0 likes
      Last Post CarlTrading  
      Working...
      X