Announcement

Collapse
No announcement yet.

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.

    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.

        Comment

        Latest Posts

        Collapse

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