Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help writing trade data to file

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

    Need help writing trade data to file

    I would like to program my strategy to write the PnL data (or if possible, all the order executions) to a file at the end of the day. Sometimes my machine freezes after trading hours, which causes all my trade data from the simulator that day to be lost.

    I wrote the following code that seems like it should work:

    if (ToTime(Time[0]) == ToTime(15, 30, 0)
    && ToDay(Time[0]) == 20070601)
    {
    FileInfo fi = new FileInfo("c:/stats.txt");
    StreamWriter sw = fi.CreateText();
    sw.WriteLine("Trading Statistics for " + ToDay(Time[0]));
    sw.WriteLine("Swap: " + GetAtmStrategyRealizedProfitLoss("Swap").ToString());
    sw.WriteLine("CTL: " + GetAtmStrategyRealizedProfitLoss("CTL").ToString());
    sw.WriteLine("CTS: " + GetAtmStrategyRealizedProfitLoss("CTS").ToString());
    sw.WriteLine("S36L: " + GetAtmStrategyRealizedProfitLoss("S36L").ToString());
    sw.WriteLine("S36S: " + GetAtmStrategyRealizedProfitLoss("S36S").ToString());
    sw.WriteLine("Total Realized PnL:" + Performance.AllTrades.Performance.Currency.CumProf it);
    sw.Close();
    }


    However, the output I'm getting is:
    Trading Statistics for 20070601
    Swap: 0
    CTL: 0
    CTS: 0
    S36L: 0
    S36S: 0
    Total Realized PnL:-1000

    Where there should be some profit on the individual strategies, and the PnL should be positive. Any ideas?

    #2
    Hi,

    If your strategy only generates ATM strategies then "Performance.AllTrades..." is of no value. The Performance object only holds strategy generated trades excluding ATM strategies.

    The paramters you pass in such as "Swap" is that a unique strategyId or the name of the strategy template? If the latter, this will not work. You have to pass in a unique strategy id value that you used to initiate the ATM strategy.
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    65 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    41 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    23 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    26 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    52 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X