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 NullPointStrategies, Today, 05:17 AM
        0 responses
        30 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X