1. do not update correctly in real time when positions are closed and pnl realized
2. the Account RealizedPnL remains 0 until all charts are Flat then the RelaizedPnL correctly matches the Strategies tab total Realized however the CashValue is never correct
To reproduce:
1. download replay data for the 6E 12-13
2. open two 50 volume charts
3. start Market Replay at 3:00 AM (Eastern time zone)
4. load the strategy below in one chart with 3 default setting for Target
5. load the strategy below in the second chart with 30 setting for Target
6. open Output Window
7. replay until fast chart (default 3 Target setting) has made 10 trades (per OutputWindow)
8. move the profit target in slow chart down to market Last to close position (3:06:40 AM in attached pics)
9. compare Accounts tab CashValue (1009.40 profit) with RealizedPnL (449.04 actual)
10. note Strategies tab RealizedPnL total 449.04
The major problem here is if you are trying to manage risk via code when running more than one chart in the same instrument the Account RealizedPnL does not update for all charts and the Account CashValue is totally useless.
I reported this a very long time ago and was told that ninja does not work for scaling in, which is effectively what trading 2+ charts in the same direction in the same instrument is. Once again I find I need accurate numbers for risk management over multiple charts and am experiencing the same bug. Being limited to trading one chart per instrument to maintain accuracy is a severe limitation. I would hope this can be fixed in ninja7 now or worst case in ninja8.
==================
// base code from SampleOnOrderUpdate ..... Copyright (C) 2011, NinjaTrader LLC <www.ninjatrader.com>.
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion
namespace NinjaTrader.Strategy
{
[Description("BUG - CashValue does not match RealizedPnL when trading 2+ charts/instances.")]
public class BugCashValue : Strategy
{
#region Variables
private IOrder entryOrder = null;
private IOrder stopOrder = null;
private IOrder targetOrder = null;
private int target = 3;
private int tradeNo = 0;
#endregion
protected override void Initialize()
{ CalculateOnBarClose = true; }
protected override void OnBarUpdate()
{
if (!Historical) {
if (entryOrder == null && Position.MarketPosition == MarketPosition.Flat && Close[0] > Open[0] && tradeNo < 10 )
{ entryOrder = EnterLong(1, "MyEntry"); tradeNo++; Print("Target "+Target+" tradeNo "+tradeNo);}
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + (7 * (TickSize / 2)))
{
if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice)
{ stopOrder = ExitLongStop(0, true, stopOrder.Quantity, Position.AvgPrice, "MyStop", "MyEntry"); }
}
}
}
protected override void OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder == order)
{ if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{ entryOrder = null; } }
}
protected override void OnExecution(IExecution execution)
{
if (entryOrder != null && entryOrder == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
stopOrder = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "MyStop", "MyEntry");
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + Target * TickSize, "MyTarget", "MyEntry");
if (execution.Order.OrderState != OrderState.PartFilled)
{ entryOrder = null; }
}
}
if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{ stopOrder = null; targetOrder = null; }
}
}
protected override void OnPositionUpdate(IPosition position) { DrawTextFixed("MyTag", position.ToString(), TextPosition.BottomRight); }
#region Properties
[Description("profit target")]
[GridCategory("Parameters")]
public int Target
{
get { return target; }
set { target = value; }
}
#endregion
}
}

Comment