Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Market Replay PlayBack Account Position not updating

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

    Market Replay PlayBack Account Position not updating

    Hello NinjaTrader Team and Community, as you can see from the picture below my entry order was filled and the execution showed a Long 1 NQ contract but the Position of the account never updated leading to the target getting filled and setting me on an inverse position and the OCO stop getting Rejected and then error can't be submitted cancel is pending. Do you guys know why this happens? it only happens VERY rarely, how can I be prevented or checked to exit the trade setup?





    Here how a normal order should look like, with the target set to working, stop loss getting accepted then playback account position updating to 1NQ Long , then target getting filled, OCO stop loss getting cancelled , target execution and then Playback account position to flat .


    Click image for larger version

Name:	Screenshot 2024-06-15 at 01.59.40.png
Views:	13
Size:	524.8 KB
ID:	1307308
    Attached Files

    #2
    Hello Pole123,

    Thank you for your post.

    I am not seeing any error messages in this screenshot, is this the correct screenshot you meant to post?

    To check the strategy's current position, you can use Position.MarketPosition.




    To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    This will print to the output window. Backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Output from prints will appear in the NinjaScript Output window.
    NT8: New -> NinjaScript Output

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

    Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script.
    NT8 —


    If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.
    NT8 Strategy Builder —



    It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().

    TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.

    Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.
    These tools will let you know what happens to the order.

    TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

    I'm also including a link to a forum post with further suggestions on debugging a script.


    Save the output from the output window to a text file. Let me know if you need assistance creating a print or enabling TraceOrders.

    I am happy to assist with analyzing the output from prints and TraceOrders.​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      My question was why after the execution the position of the account was never updated to be 1 Long as it normally should, you are saying that I need to check each time the position value and if its not updated do something? From the bottom you can see the order being created and filled, the execution log but no position update until target is hit which makes it reverse since there was no long position since the start

      Click image for larger version

Name:	Screenshot 2024-06-15 at 01.54.02.png
Views:	8
Size:	427.1 KB
ID:	1307636

      Comment


        #4
        Hello Pole123,

        how can I be prevented or checked to exit the trade setup?
        You inquired how to check the position for exiting, which is why I mentioned how to check Position.MarketPosition:

        Can you provide the output from the prints? These screenshots from the Control Center do not provide enough information in order to determine what could be happening with the script, or if there is indeed a bug.

        In particular, make sure to print the order object in OnOrderUpdate(). Printing the order object in OnOrderUpdate() will allow us to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.

        OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

        TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.

        Also print out the Position.MarketPostion so we can verify if it is not updating properly.
        Gaby V.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, Today, 12:24 PM
        0 responses
        2 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by reekotubbs, Yesterday, 01:09 PM
        3 responses
        26 views
        0 likes
        Last Post reekotubbs  
        Started by Blaze212, 07-07-2024, 08:58 PM
        2 responses
        18 views
        0 likes
        Last Post Blaze212  
        Started by medicmiked, Today, 11:56 AM
        0 responses
        2 views
        0 likes
        Last Post medicmiked  
        Started by miaolivi9, Today, 06:59 AM
        0 responses
        8 views
        0 likes
        Last Post miaolivi9  
        Working...
        X