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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        93 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        138 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        123 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        73 views
        0 likes
        Last Post PaulMohn  
        Working...
        X