PDA

View Full Version : Need help writing trade data to file


oriondesign
06-01-2007, 09:29 AM
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?

NinjaTrader_Ray
06-02-2007, 02:17 PM
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.