Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Discrepancy Between Outputs for Sim101 and Cash Account

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

    Discrepancy Between Outputs for Sim101 and Cash Account

    Hello everyone, I have a bit of code here and it's outputting different integers for my simulated account versus my cash account.


    Code:
    }
    else if (State == State.DataLoaded)
    {
    lock (Account.All)
    myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
    
    if (myAccount != null)
    myAccount.PositionUpdate += MyAccount_PositionUpdate;
    }
    else if (State == State.Terminated)
    {
    if (myAccount != null)
    myAccount.PositionUpdate -= MyAccount_PositionUpdate;
    }
    }
    
    private void MyAccount_PositionUpdate(object sender, PositionEventArgs e)
    {
    
    //Code
    marketPos = System.Convert.ToInt32(e.MarketPosition);
    Print(marketPos);
    }

    When the account is Long, Flat, and Short the outputs are, respectively:

    Sim101: 0, 2, 1

    Cash: 0, 1, 1


    Any clue what's going on here? Why do the outputs change depending on which account I'm using? This discrepancy prevents my program from properly identifying what my accounts' true position is without otherwise superfluous code. Any help would be greatly appreciated!

    Thank you in advance NinjaTrader Community

    #2
    Hello centsthousandthsllc,

    Thank you for your inquiry.

    Who is your broker for the live account? We've had reports where the PositionUpdate event was differing between different connection adapters.

    Next, MarketPosition is an enum. What do you see if you simply print the enum value?



    The position from the account (which is separate from the strategy position) will update from the PositionUpdate event and will match the positions tab / accounts tab of the Control Center.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Thank you for the quick response. Dorman is my broker.

      Just printing the market position, like so...

      Code:
      Print(e.MarketPosition);
      ...yields the correct 'Long', 'Flat' and 'Short' outputs for the Sim account, but says my position is 'Short' when it is flat in my cash account.

      Comment


        #4
        Hello centsthousandthsllc,

        Thank you for your reply.

        Do you know if your connection to your Dorman account is Rithmic based or CQG based? This makes a difference, as there are known issues with position updates using Rithmic based connections that could certainly cause you to see the account as in a position when the actual account is flat.

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Yes, it is CQG

          Comment


            #6
            Hello centsthousandthsllc,

            Thank you for your reply.

            We'd expect that to possibly occur on a Rithmic based connection but wouldn't expect to see that on a CQG connection. Would you be able to provide a simple example script that reproduces so we may test on our end?

            Thanks in advance, I look forward to assisting you further.

            Comment


              #7
              Yes

              Code:
              #region Using declarations
              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.ComponentModel.DataAnnotations;
              using System.Linq;
              using System.Text;
              using System.Threading.Tasks;
              using System.Windows;
              using System.Windows.Input;
              using System.Windows.Media;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Gui;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Gui.SuperDom;
              using NinjaTrader.Gui.Tools;
              using NinjaTrader.Data;
              using NinjaTrader.NinjaScript;
              using NinjaTrader.Core.FloatingPoint;
              using NinjaTrader.NinjaScript.DrawingTools;
              #endregion
              
              //This namespace holds Indicators in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.Indicators
              {
              public class Test : Indicator
              {
              private Account myAccount;
              
              protected override void OnStateChange()
              
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Indicator here.";
              Name = "Test";
              Calculate = Calculate.OnBarClose;
              IsOverlay = true;
              DisplayInDataBox = true;
              DrawOnPricePanel = true;
              DrawHorizontalGridLines = true;
              DrawVerticalGridLines = true;
              PaintPriceMarkers = true;
              ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
              //Disable this property if your indicator requires custom values that cumulate with each new market data event.
              //See Help Guide for additional information.
              IsSuspendedWhileInactive = true;
              }
              else if (State == State.DataLoaded)
              {
              lock (Account.All)
              myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
              
              if (myAccount != null)
              myAccount.PositionUpdate += MyAccount_PositionUpdate;
              }
              else if (State == State.Terminated)
              {
              if (myAccount != null)
              myAccount.PositionUpdate -= MyAccount_PositionUpdate;
              }
              }
              
              private void MyAccount_PositionUpdate(object sender, PositionEventArgs e)
              {
              
              Print(e.MarketPosition);
              
              }
              
              protected override void OnBarUpdate()
              {
              //Add your custom indicator logic here.
              }
              }
              }
              
              #region NinjaScript generated code. Neither change nor remove.
              
              namespace NinjaTrader.NinjaScript.Indicators
              {
              public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
              {
              private Test[] cacheTest;
              public Test Test()
              {
              return Test(Input);
              }
              
              public Test Test(ISeries<double> input)
              {
              if (cacheTest != null)
              for (int idx = 0; idx < cacheTest.Length; idx++)
              if (cacheTest[idx] != null && cacheTest[idx].EqualsInput(input))
              return cacheTest[idx];
              return CacheIndicator<Test>(new Test(), input, ref cacheTest);
              }
              }
              }
              
              namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
              {
              public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
              {
              public Indicators.Test Test()
              {
              return indicator.Test(Input);
              }
              
              public Indicators.Test Test(ISeries<double> input )
              {
              return indicator.Test(input);
              }
              }
              }
              
              namespace NinjaTrader.NinjaScript.Strategies
              {
              public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
              {
              public Indicators.Test Test()
              {
              return indicator.Test(Input);
              }
              
              public Indicators.Test Test(ISeries<double> input )
              {
              return indicator.Test(input);
              }
              }
              }
              
              #endregion

              Comment


                #8
                Hello centsthousandthsllc,

                Thank you for your reply.

                I wasn't able to get time to test before the market closed today, so I will test in the morning and let you know my findings.

                Thanks in advance; I look forward to assisting you further.

                Comment


                  #9
                  That would be great, I'm curious to know what your results will be. I can overcome the problem with if else statements, but if there is a cleaner approach I would be all for it.

                  Comment


                    #10
                    Hello centsthousandthsllc,

                    Thank you for your reply.

                    In my testing I'm seeing the position update appropriately with your script using a CQG demo account. What version of the platform are you using? This can be found under Help > About. The current version is 8.0.24.1.

                    Thanks in advance; I look forward to assisting you further.

                    Comment


                      #11
                      Version 8.0.21.1

                      Comment


                        #12
                        Hello centsthousandthsllc,

                        Thank you for your reply.

                        I see that you're using an older version of NinjaTrader 8. To update NinjaTrader, please follow the steps below:
                        • First, copy your license key from NinjaTrader under Help> License Key then exit NinjaTrader
                        • Click on the link: https://ninjatrader.com/PlatformDirect
                        • Enter your license key and press Submit
                        • Select 'Download'
                        • Critical: Before running the installer, ensure NinjaTrader is closed.
                        Once updated, please test with the live account again.

                        Thanks in advance; I look forward to assisting you further.

                        Comment


                          #13
                          It worked! Problem solved, thank you so much for your help!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          621 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          359 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          105 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          562 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          566 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X