as I switch from MetaTrader to NinjaTrader, I'm new to Object Oriented Programming. I have an issue which puzzles me currently and I run out of ideas to solve it by myself:
In my strategy there's a class which is intended to export trading data (e.g. entry and exit price and date etc.) in a CSV file:
internal class JournalData
{
private static string
strSymbol,
strPositionSize,
strOrderOpen,
strDateOpen,
strDirection,
strPriceOpen,
strPriceStopLossInitial,
strDateBreakeven,
strDateClose,
strPriceClose;
public void WriteResults (string FileName)
{
FileInfo f = new FileInfo (NinjaTrader.Core.Globals.UserDataDir + FileName);
StreamWriter w = f.AppendText();
w.WriteLine (strSymbol+";"+strPositionSize+";"+strOrderOpen+";"+strDateOpen+";"+strDirection+";"+strPriceOpen+";"+strPriceStopLossInitial+";"+strDateBreakeven+";"+strDateClose+";"+strPriceClose);
w.Close();
// Reset variables for possible subsequent opening in opposite direction
strSymbol = null;
strPositionSize = null;
strOrderOpen = null;
strDateOpen = null;
strDirection = null;
strPriceOpen = null;
strPriceStopLossInitial = null;
strDateBreakeven = null;
strDateClose = null;
strPriceClose = null;
}
public void SetOrderOpen (Order OrderOpen)
{
strSymbol = OrderOpen.Instrument.FullName;
strPositionSize = OrderOpen.Quantity.ToString().Replace (".", ",");
strOrderOpen = OrderOpen.OrderId;
strDateOpen = OrderOpen.Time.ToString ("G", CultureInfo.CreateSpecificCulture ("de-DE"));
strDirection = OrderOpen.OrderAction.ToString();
strPriceOpen = OrderOpen.AverageFillPrice.ToString().Replace (".", ",");
}
public void SetPriceStopLossInitial (double Price)
{
if (String.IsNullOrEmpty (strPriceStopLossInitial))
{
strPriceStopLossInitial = Price.ToString().Replace (".", ",");
}
}
public void SetDateBreakeven()
{
strDateBreakeven = DateTime.Now.ToString ("G", CultureInfo.CreateSpecificCulture ("de-DE"));
}
public void SetOrderClose (Order OrderClose)
{
strDateClose = OrderClose.Time.ToString ("G", CultureInfo.CreateSpecificCulture ("de-DE"));
strPriceClose = OrderClose.AverageFillPrice.ToString().Replace (".", ",");
}
}
JournalData JournalDataTmp = new JournalData();
;;;;;;;;06.07.2018 20:37:29;2761
Thanks in advance,
Frederik

Comment