• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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, 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 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 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.

    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]));
    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 - https://www.youtube.com/watch?v=BA0W...tu.be&t=51m51s
    NT7 - 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.
    NT8 Strategy Builder - https://drive.google.com/file/d/1CCl...gEIwJKv6L/view

    To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):
    NT8 - https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s
    NT7 - https://www.youtube.com/watch?v=K8v_...utu.be&t=5m33s

    It is also helpful to enable TraceOrders and print the order object in OnOrderUpdate.
    TraceOrders NT7 - https://ninjatrader.com/support/help...raceorders.htm
    TraceOrders NT8 - https://ninjatrader.com/support/help...raceorders.htm
    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 occuring. 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]); <-- this 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

    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; 05-08-2019, 02:51 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

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Vincere, Yesterday, 11:20 PM
          0 responses
          3 views
          0 likes
          Last Post Vincere
          by Vincere
           
          Started by lMagi, 05-18-2019, 09:34 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by uday12, Yesterday, 10:26 PM
          0 responses
          2 views
          0 likes
          Last Post uday12
          by uday12
           
          Started by uday12, Yesterday, 10:07 PM
          0 responses
          0 views
          0 likes
          Last Post uday12
          by uday12
           
          Started by Nabil, Yesterday, 07:46 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X