Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades not completing on Strategy analyzer

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

    Trades not completing on Strategy analyzer


    Good evening. I'm having an issue with strategy analyzer that I don't understand. My strategy will generate expected results, but occasionally, it will execute a position and hold it until it stops out at end of session. It happens to both long and short posistions, yet for every one time it does this, I have dozens of properly executed trades. It's severly skewing the data when max loss shoulld be around $20 and you have a handful around $1000. I'd appreciate any insight you guys could offer!
    Last edited by medicmiked; 07-05-2024, 04:56 PM.

    #2
    Hello medicmiked,

    Thank you for your post.

    What Calculate setting is your strategy using? Have you implemented intrabar granularity for backtesting? If you not using Calculate.OnBarClose, have you enabled Tick Replay?

    If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true and the order is not being submitted, or the order is being ignored for other reasons, or the order is being cancelled.

    To understand why the script is behaving as it is, such as placing orders or not placing orders (or drawing objects or other actions) 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.​

    Comment


      #3
      Thanks for the detailed response. I have tried both On Bar Close and On Price Change for my calculate method and both yield the same results. I can download the historical data for the instances of it exiting on session close and replay the script and it will execute appropriately on the chart, just not in the strategy builder. I will try the trace orders and see. I've heard others about talk about the intrabar granularity but was unsure exactly how to add it. Thanks for your assistance.

      Comment


        #4
        Hello,

        Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics. Instead these are filled based on logical rules from processing historical data.
        • When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data.
          • This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known
          • Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.
        Intra-bar granularity adds a second data series such as a 1 tick series using AddDataSeries() so that the strategy or indicator has the individual ticks in the historical data in between the High and Low of the primary series.

        In NinjaTrader 8, there have been two new enhancements so that programmers may not have to manually add this secondary series and code the script for high accuracy fills (Order Fill Resolution) or for intra-bar actions (TickReplay) depending on the needs of the script.
        Note: bar types that are IsRemoveLastBarSupported cannot be used with TickReplay and generally cause inaccurate results when backtesting in historical data.
        Note: High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

        Please see this support article for a detailed explanation:


        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        53 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X