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


Date Conditions Not Working

  • Filter
  • Time
  • Show
Clear All
new posts

    Date Conditions Not Working


    Anyone have an idea why this is giving zero data. I know the time series works but when I added the date conditions......nothing. Appreciate the help.

    Attached Files

    Hello Bob,

    To understand why the script is behaving as it is, either placing orders or not placing orders when expected, drawing or not drawing objects, or understanding why any actions are happening or not happening, 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.

    See the help guide on Debugging your NinjaScript Code.

    In the strategy add prints (outside of any conditions) that print the time of the bar and all values used in every condition that submits the order in question.

    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 from both computers to your reply.

    The print should be added 1 line above the condition or action being investigated.
    The print should be outside of any condition action block so also this prints when the condition is not evaluating as true.

    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.

    Output from prints will appear in the NinjaScript Output window.

    NT7: Tools -> Output window

    NT8: New -> NinjaScript Output

    Should you want to share the output, run 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 location if desired), then click save.

    For example if I wanted a print for the condition set:
    if (CrossAbove(SMA(7), SMA(14), 1))
    I would print:
    Print(string.Format("{0} | SMA(7)[1]: {1} < SMA(14)[1]: {2} & SMA(7)[0]: {3} > SMA(14)[0]: {4}", Time[0], SMA(7)[1], SMA(14)[1], SMA(7)[0], SMA(14)[0]));
    The output for this would appear as:
    6/16/2017 1:39:00 PM | SMA(7)[1]: 2399.96428571429 < SMA(14)[1]: 2400.125 & SMA(7)[0]: 2400.07142857143 > SMA(14)[0]: 2400.08928571429
    6/16/2017 1:40:00 PM | SMA(7)[1]: 2400.07142857143 < SMA(14)[1]: 2400.08928571429 & SMA(7)[0]: 2400.21428571429 > SMA(14)[0]: 2400.125
    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 NinjaScript Editor 401 -
    NT7 NinjaScript Editor 401 -

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

    Below is a link to a video on 'Debugging using prints with the Strategy Builder'.
    NT8 Strategy Builder -

    For a strategy and orders specifically, the next step is to set TraceOrders = true; in Initialize() for NinjaTrader 7 or in State.Configure within OnStateChange() of NinjaTrader 8.
    If TraceOrders is set to true in State.SetDefaults instead of State.Configure, the change will not take effect until a new instance of the script is added. Defaults are only pulled for new instances.
    In the Strategy Builder TraceOrders is set in the Defaults (and requires removing and adding a new instance).

    TraceOrders will print to the output window when orders are being submitted (so we can see if they are being submitted) and also provides information if orders are being ignored or cancelled.

    Help Guide TraceOrders NT7 -
    Forum tips page on TraceOrders NT7 -

    Help Guide TraceOrders NT8 -
    Forum tips page on TraceOrders NT8 -

    Further, print the order object within OnOrderUpdate.
    These will provide information about when orders are being submitted, and provide the updates of orders as they become accepted, working, filled/cancelled.
    OnOrderUpdate() NT7 -
    OnOrderUpdate() NT8 -

    Also, below is a public link to the Microsoft documentation on string.Format() which can be handy for writing prints with lots of variables.

    Prints can also be added throughout the script to see where in the code the error is occurring. By printing enumerated prints, this can show which print in the last to print.

    For example:
    Print("step 1");
    if (Close[0] > Open[0])
    Print("step 2");
    EnterLongLimit(Low[1]); // <-- the use of 1 barsAgo for the Low series may be an invalid index causing an error
    Print("step 3");
    With this example, if CurrentBar was 0 this would cause an index error calling Low[1]. The last print to appear would be "step 2" in the output window and then the error would appear. There would be no print of "step 3". This lets you target in that the line of code below the print of "step 2" is likely where the issue is.

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

    To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):
    NT8 -
    NT7 -

    It's also very helpful to create a new blank script and copy only the few relevant parts to ensure the code is reduced as much as possible.
    This can be exported and then easily shared.

    Below are links to the help guide on exporting.
    NT7 -
    NT8 -

    Please add prints to your script and send the output from the script and I will assist in analyzing this output to understand the behavior.
    Last edited by NinjaTrader_ChelseaB; 01-31-2023, 02:02 PM.
    Chelsea B.NinjaTrader Customer Service


      Hi Chelsea,

      I reviewed this but I am not comfortable with the programming side. Could you not just set up this exact same condition (using any moving average cross over condition) and see what it gives you? Thank you for your support.




        I see that I didn't answer your question. There is definitely historical data for this time period.

        Thanks again.



          Hello Bob,

          At this point you will need to add prints to the code to understand the behavior.

          For example:
          Print(string.Format("{0} | MACDSMA[0]: {1} > MACDSMA[1]: {2} & ToTime(Time[0]): {3} >= ToTime(10, 0, 0): {4} & ToTime(Time[0]): {3} < ToTime(14, 50, 0): {5} & ToTime(Time[0]): {3} >= ToDay(2014, 1, 1): {6} & ToTime(Time[0]): {3} <= ToDay(2014, 9, 1): {7}", Time[0], MACDSMA(FastSMA, SlowSMA, SmoothSMA)[0], MACDSMA(FastSMA, SlowSMA, SmoothSMA)[1], ToTime(Time[0]), ToTime(10, 0, 0), ToTime(14, 50, 0), ToDay(2014, 1, 1), ToDay(2014, 9, 1)));
          This would print all of the values in the conditions so that you would be able to see what is not evaluating as true.

          As I started writing a print to assist you and I think I've noticed what is causing the issue.
          ToTime(Time[0]) >= ToDay(2014, 1, 1)

          The Strategy Wizard appears to be comparing a time with a date.
          I believe this is incorrect and I've sent a notice to our development about this. Once I have more information or when I receive a tracking ID for this item, I will post in this thread.

          If you would like, since there may be an issue with the Strategy Wizard, you can finish the script and post an export of this and I will unlock and correct the code to show:
          ToDay(Time[0]) >= ToDay(2014, 1, 1)
          ToDay(Time[0]) >= ToDay(2014, 9, 1)
          Last edited by NinjaTrader_ChelseaB; 08-07-2017, 08:12 AM.
          Chelsea B.NinjaTrader Customer Service


            Originally posted by NinjaTrader_ChelseaB View Post

            Below is a link to a video on 'Debugging using prints with the Strategy Builder'.
            NT8 Strategy Builder -
            Hi, please can you check whether this link actually works?
            I cannot get it open.


              Hello guidoisot,

              Please make sure you are not browsing in incognito mode. We have not had issue viewing these videos in regular browser mode when we are logged into a Google account.

              Please test the above and if issues are persisting, please try clearing your browser cache. If issues are still persisting, please try a different browser. We will be interested to here what specific browsers are not working for you when you are logged into a Google account, are in regular browser mode, and have cleared browser cache.

              We look forward to assisting.
              JimNinjaTrader Customer Service


                Hello guidoisot,

                Yes, the link is working..

                Are you clicking the link or copying and pasting it? (you may notice that the forum abbreviates the text of links)

                Below is a link to a direct video file of me opening the link in edge.

                I recommend clearing your browser cache if the video is not playing which I demonstrate at the beginning of the video (and also to make sure i'm signed out to test).
                Chelsea B.NinjaTrader Customer Service


                  thank you for your replies.
                  I had been using firefox.
                  However as per your example I have now been able to acess the video using Edge browser.
                  It does not work yet with Firefox (in order to see what happens with this browser, please see video at this wetransfer link )


                    Hello guidoisot,

                    We have been able to view the videos in Firefox without issue. If you have not cleared your browser cache in Firefox, please do so. If issues are persisting, you may wish to troubleshoot your Firefox installation. I.E. uninstall Firefox and unsure to install the latest version.

                    The issue would be specific to streaming GoogleDrive videos from Firefox, so you may wish to follow up with Mozilla's support services if you are still unable to view these videos from Firefox.

                    We look forward to assisting.
                    JimNinjaTrader Customer Service


                    Latest Posts


                    Topics Statistics Last Post
                    Started by chbruno, Today, 04:10 PM
                    0 responses
                    Last Post chbruno
                    by chbruno
                    Started by josh18955, 03-25-2023, 11:16 AM
                    6 responses
                    Last Post Delerium  
                    Started by FAQtrader, Today, 03:35 PM
                    0 responses
                    Last Post FAQtrader  
                    Started by rocketman7, Today, 09:41 AM
                    5 responses
                    Last Post NinjaTrader_Jesse  
                    Started by frslvr, 04-11-2024, 07:26 AM
                    9 responses
                    1 like
                    Last Post caryc123