Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.


    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by RDTrader16, Today, 10:19 PM
    0 responses
    3 views
    0 likes
    Last Post RDTrader16  
    Started by gemify, 03-08-2023, 08:02 AM
    9 responses
    148 views
    0 likes
    Last Post culpepper  
    Started by elirion, Today, 10:03 PM
    0 responses
    1 view
    0 likes
    Last Post elirion
    by elirion
     
    Started by RaddiFX, Today, 09:55 PM
    0 responses
    6 views
    0 likes
    Last Post RaddiFX
    by RaddiFX
     
    Started by Trader146, 03-29-2024, 01:22 PM
    4 responses
    25 views
    0 likes
    Last Post Trader146  
    Working...
    X