• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:
    https://ninjatrader.com/support/help...t_overview.htm
    https://ninjatrader.com/support/help..._interface.htm

    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 futurenick, Today, 06:26 AM
        1 response
        11 views
        0 likes
        Last Post nkhoi
        by nkhoi
         
        Started by NinjaCustomer, Today, 12:29 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by Steve L, Today, 11:32 AM
        0 responses
        5 views
        0 likes
        Last Post Steve L
        by Steve L
         
        Started by prabbala, Today, 10:41 AM
        0 responses
        3 views
        0 likes
        Last Post prabbala  
        Started by bebbus, Today, 10:36 AM
        0 responses
        4 views
        0 likes
        Last Post bebbus
        by bebbus
         
        Working...
        X