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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    56 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X