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

StreamWriter and Optimization

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

    StreamWriter and Optimization

    Hello,
    I have a strategy that is used to output some values into a file. I have clean up in State.Terminated for StreamWriter like this:

    private StreamWriter sw;

    else if(State == State.Terminated)
    {
    // Necessary to call in order to clean up resources used by the StreamWriter object
    if (sw != null)
    {
    sw.Close();
    sw.Dispose();
    sw = null;
    }
    }


    End everything work fine in backtest mode but when I try optimization I got error: The process cannot access the file .... because it is being used by another process.
    I need this to output optimization variables and my own calculations.

    #2
    Hello Leeroy_Jenkins,

    That would be correct, a backtest is running a single test where an optimization runs many which may overlap. A single file cannot be used by multiple scripts running at once, you would need to write individual files to avoid that.

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

    Comment


      #3
      And it's not possible to run some code at 1st or last iteration, right?

      Comment


        #4
        Hello Leeroy_Jenkins,

        Not that I am aware of, you would likely need to make unique filenames similar to the example shown in the following post: https://ninjatrader.com/support/foru...85#post1042885

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        603 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        6 responses
        23 views
        0 likes
        Last Post xiinteractive  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        22 views
        0 likes
        Last Post Pattontje  
        Started by flybuzz, 04-21-2024, 04:07 PM
        17 responses
        230 views
        0 likes
        Last Post TradingLoss  
        Working...
        X