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 inanazsocial, Today, 01:15 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    6 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    1 view
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X