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 AaronKoRn, Today, 09:49 PM
    0 responses
    6 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    9 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    10 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,976 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X