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


problem with strategy seeing dates and times

  • Filter
  • Time
  • Show
Clear All
new posts

    problem with strategy seeing dates and times

    Hello Kate,

    I'm trying to create parameters for days and times to trade within NinjaScript. I'd like to enter:

    - On Sundays AND after 3:30pm - shown on lines 265-267, OR
    - On Mondays thru Friday before 12:00p - shown on lines 268-274
    - Then I have my Buy Entry criteria beneath this - shown on lines 275-291
    - My Long Entry command is shown on line 293

    My indicators are entering and exiting trades correctly. However, I'm having problems with the strategy seeing my days and times correctly. For example, the strategy is entering in trades on Monday thru Friday AFTER 12:00p, but based on lines 268-274, I shouldn't enter in trades after 12:00p on Mon-Fri. I think my parentheses are off, but am unsure where I'm going wrong. Can you please take a look and tell me where I'm going wrong?

    Hello Ttrade12,

    I have moved this post into its own thread since it was not directly related to the original poster's question and the thread was quite old.

    Your conditions appear to be set up correctly, I would recommend debugging the script to further diagnose the behavior.

    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 -
    OnOrderUpdate() -

    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


      Thanks, Gaby. I'll work on this.


        Hi Gaby,

        I was able to figure out what was wrong by stripping my code and taking it line by line. Thanks for the resources!


        Latest Posts


        Topics Statistics Last Post
        Started by MatthewLesko, 05-21-2021, 09:37 PM
        4 responses
        Last Post Mahmad1323  
        Started by samish18, Today, 03:02 PM
        3 responses
        Last Post bltdavid  
        Started by Jakub, Today, 11:06 AM
        1 response
        Last Post NinjaTrader_LuisH  
        Started by samish18, Today, 03:50 AM
        10 responses
        Last Post samish18  
        Started by Mestor, 06-03-2018, 10:09 AM
        16 responses
        Last Post myaha1000