Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom export of trades throws errors

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

    Custom export of trades throws errors

    Hello,

    I have a strategy where i have implemented a very simple trade exporter.

    Code:
    if (SLOrder != null && SLOrder.OrderState == OrderState.Filled)
    {
    
    entryOrder = null;
    SLOrder = null;
    TPOrder = null;
    
    trailSLSet = false;
    entryTriggered = false;
    
    tm_string = tm_entryDate + ";" + Instrument.MasterInstrument.Name.ToString() + ";"+ amountStocks + ";" + tm_entryPrice + ";" + tm_exitDate + ";" + tm_exitPrice + Environment.NewLine;
    File.AppendAllText(path, tm_string);
    
    }
    The Backtest has as input the S&P500 instrument list.

    Unfortunately this implementation throws a lot of errors, any idea why this is happening?

    Thanks,
    Lukas
    Attached Files

    #2
    Hello lakman184,

    A backtest runs multiple tests at one time so if you use a file you will get read/write errors. You would essentially need a new file for each instance that is run in the backtest to completely avoid file IO errors in a backtest. In a normal single use you could write to the same file because the one strategy instance is using it at any given time.

    The best solution for avoiding file errors would be to not use a file for storing the data but store the data in memory then export it later after the test is done. That could be achieved using an addon and C# static objects. A simple example would be to create an addon with a UI which has 1 button, the action of the button would be to save the collected data. In the addons class you could have a static variable which your strategies add the strings to.


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 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
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X