Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BUG - CashValue vs RealizedPnL when 2+ charts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    BUG - CashValue vs RealizedPnL when 2+ charts

    When trading the same account with the same strategy running in 2 or more identical charts the Account CashValue and Realized PnL
    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
    }
    }
    Attached Files

    #2
    Hello ATI user,

    Thanks for the detailed information.

    This is a limitation of NinjaTrader 7, since each strategy is going to have its own virtual position different from the Account Position so with two strategies the Account will see it as scaling in which is why it does not update until the Account Position is flat.

    I will send you vote to have this changed on our Feedback list again to our Development team, but I do not believe this will change in NinjaTrader 7 but is possible to change in NinjaTrader 8.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    668 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    377 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    110 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    575 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X