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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    80 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X