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

Date Conditions Not Working

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

    Date Conditions Not Working

    Hi,

    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.


    Bob
    Attached Files

    #2
    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.
    https://ninjatrader.com/support/help...script_cod.htm

    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
    https://ninjatrader.com/support/help...tools_menu.htm

    NT8: New -> NinjaScript Output
    https://ninjatrader.com/support/help...tWindowDisplay

    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:
    Code:
    if (CrossAbove(SMA(7), SMA(14), 1))
    I would print:
    Code:
    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 - https://youtu.be/H7aDpWoWUQs?t=2577&...We0Nf&index=14
    NT7 NinjaScript Editor 401 - https://www.youtube.com/watch?v=K8v_...tu.be&t=48m35s

    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 - https://drive.google.com/file/d/1CCl...gEIwJKv6L/view


    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 - https://ninjatrader.com/support/help...raceorders.htm
    Forum tips page on TraceOrders NT7 - https://ninjatrader.com/support/foru...rders#post3755

    Help Guide TraceOrders NT8 - https://ninjatrader.com/support/help...raceorders.htm
    Forum tips page on TraceOrders NT8 - https://ninjatrader.com/support/foru...963#post671963

    Further, print the order object within OnOrderUpdate.
    Code:
    Print(order.ToString());
    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 - https://ninjatrader.com/support/help...rderupdate.htm
    OnOrderUpdate() NT8 - https://ninjatrader.com/support/help...rderupdate.htm


    Also, below is a public link to the Microsoft documentation on string.Format() which can be handy for writing prints with lots of variables.
    https://docs.microsoft.com/en-us/dot...ramework-4.7.2

    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:
    Code:
    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.
    https://ninjatrader.com/support/foru...749#post413749

    To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):
    NT8 - https://youtu.be/H7aDpWoWUQs?t=355&l...We0Nf&index=14
    NT7 - https://www.youtube.com/watch?v=K8v_...utu.be&t=5m33s

    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 - https://ninjatrader.com/support/helpGuides/nt7/export.htm
    NT8 - https://ninjatrader.com/support/help...tAsSourceFiles

    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

    Comment


      #3
      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.


      Bob

      Comment


        #4
        Cheslea,

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

        Thanks again.

        Bob

        Comment


          #5
          Hello Bob,

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

          For example:
          Code:
          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

          Comment


            #6
            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 - https://drive.google.com/file/d/1CCl...gEIwJKv6L/view
            Hi, please can you check whether this link actually works?
            I cannot get it open.
            Thanks.

            Comment


              #7
              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

              Comment


                #8
                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

                Comment


                  #9
                  Hello
                  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 https://we.tl/t-IiyCGjB9om )
                  Best.

                  Comment


                    #10
                    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

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    27 views
                    0 likes
                    Last Post alifarahani  
                    Started by Waxavi, Today, 02:10 AM
                    1 response
                    17 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    13 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Waxavi, Today, 02:00 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by gentlebenthebear, Today, 01:30 AM
                    3 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X