Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Having issues with getting Bars Since Entry to work

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

    Having issues with getting Bars Since Entry to work

    Hello Everyone,


    I am new to coding and am coding in NinjaScript. I'm using multiple time frames in my strategy and I'm entering in trades on 2 of those timeframes. Some of my exits are getting triggered immediately after I enter a trade. I'm trying to fix this by adding to my exits the criteria for there to be at least 2 bars since entry. I've been trying different variations of the below but it either doesn't fix my issue or I don't enter into any trades. Below is the last variation I've tried and it's still not correct. Sigh. Can someone please tell me what I'm doing wrong? Thanks for any guidance you can provide.

    && ((BarsSinceEntryExecution() > 2) || BarsSinceEntryExecution() == -1)

    #2
    Hello Ttrade12,

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects 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 date time of the bar and all values compared in every condition that places an order.
    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 important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
    After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.
    Last, print the order.ToString() at the top of the OnOrderUpdate() override, as this will show us when orders become working and are being filled.

    I am happy to assist you with analyzing the output from the output window.

    Run or 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.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


    Let me know the date and time the behavior occurred or when you are expecting the behavior to occur.

    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ok. Thanks, ChelseaB!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      116 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      61 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      40 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      43 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      82 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X