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

Is there any SAVE_OPTION/GET_OPTION native methods in NinjaScript?

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

    Is there any SAVE_OPTION/GET_OPTION native methods in NinjaScript?

    For example, If we want to save some data from NinjaScript, like "123", which could be also obtainable from next launch of ninjaTrader, till date, I am using the way to save that value to file somewhere on hard-disk, and then later, read that file.

    Is there any better solution, like ninjaScript built-in method, i.e. like this:
    Code:
    NinjaTrader.Save_Option(option_name, value);
    NinjaTrader.Get_Option(option_name)
    ?

    #2
    Hello TazoTodua,

    Yes, this is built into the platform in various ways, what type of script are you trying to create? If this is specifically an addon window please see both the add-on educational information page and the following link. This contains an example including save/load and also the following documentation explains the IWorkspacePersistence interface:



    For other scripts, it will depend on what type of script for how the data would be saved. For example, an indicator or strategy saves its public property values in templates, charts and workspaces. An addon can have its window settings saved with the workspace. You can also create custom load/save methods as well to serialize objects for things like addons without a window. Serialization is just a C# concept which is not specific to NinjaTrader.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Jesse thanks. My case is simple, not addon, neither i need to save a workspace or restore it. I just want a simpler alternative to File.Write/File.Read methods to save/read a simple value over the platform restart .

      like, in indicator, i want like this:


      SetOption(indicator.Name +"_form_height", 123);
      ...
      GetOption(indicator.Name +"_form_height");


      at this moment, I am using:



      File.WriteAllText(C:/...../indicator.Name +"_form_height", 123);
      ...
      File.ReadAlltext(C:/...../indicator.Name +"_form_height");

      Comment


        #4
        Hello TazoTodua,

        It sounds like what you want would need to be custom if you don't want to use the workspace events to save/load. The platform will natively serialize your indicator and its properties however if you wanted to do this on your own or not during the workspace events, you would just need to write your own method to do so.

        As noted the existing saving all works in combination with the workspace and how the platform normally saves values for indicators. If you wanted to do something different, you would need to make your own SetOption GetOption methods which you can call when you want to save and load values. You could create a class with these methods and any logic needed to save the object which you could then call from each indicator which needs to do this. The State.Terminated and State.DataLoaded would likely be the best states to save and load data.

        You could research online "C# serialize/deserialize objects" to get some examples of saving/loading an object to file.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sidlercom80, 10-28-2023, 08:49 AM
        169 responses
        2,268 views
        0 likes
        Last Post QuantKey_Bruce  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        17 views
        0 likes
        Last Post Irukandji  
        Started by adeelshahzad, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post adeelshahzad  
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        3 views
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Working...
        X