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

The params of my strategy dont change

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

    The params of my strategy dont change

    Hello,

    Its happening an strange thing in my strategy.

    When I try to change the value of params on the Strategies window, the params only change 1 time. From the second time it does not work anymore and Output show:

    "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."



    I declare my var:

    public double myVar{ get; set; }

    and set:

    if (State == State.SetDefaults)
    {
    myVar = 1.5;
    }



    What do you think is happening? I dont have this errors with other strategies with the same params : /

    #2
    Hello ninjo,

    My thoughts would be that this is not the code causing the error.

    Attached is an export of a test script with this code added.

    Are you able to reproduce using this test script?


    Providing a reduced script that can demonstrate the behavior with all other code removed, is very helpful to demonstrate an issue.

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

    Comment


      #3
      Hello Chelsea,

      I solved the problem when I was reduced the script to find the error.

      The problem was that I declared some other vars in "State.Configure". The problem solved when I declared it in "State.Loaded" instead

      Thank you.

      Comment


        #4
        Hello ninjo,

        Variables should be declared within the scope of the class not within a method.
        They should be assigned in a method.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,767 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        7 views
        0 likes
        Last Post rocketman7  
        Working...
        X