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

Is this a Ninjascript bug?

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

    Is this a Ninjascript bug?

    Why is Ninjascript not executing the logic of code below? The Draw.VerticalLine(see below) is not drawn even though the conditions are true, leading to that block of code with the Draw.VerticalLine. See attached pic for more info,

    if((Close[0] < Open[0])
    && (Close[1] < Open[1])
    && (Close[2] > Open[2])
    && (Close[3] > Open[3])

    )

    {
    HSBear11 = true;
    HSBear1 = High[1];

    }


    if((Close[0] > Open[0])
    && (Close[1] > Open[1])
    && (Close[2] < Open[2])
    && (Close[3] < Open[3])
    && (HSBear11 == true)
    && (High[1] < HSBear1 )
    )

    {
    HSBear12 = true;
    HSBear2 = Low[1];

    }


    if((Close[0] < Open[0])
    && (Close[1] < Open[1])
    && (Close[2] > Open[2])
    && (Close[3] > Open[3])
    && (HSBear11 == true)
    && (HSBear12 == true)
    && (High[1] > HSBear1) //****
    )

    {
    HSBear13 = true;
    HSBear3 = High[1];
    Draw.VerticalLine(this, @"Vertical line_1"+CurrentBar, 0, Brushes.Indigo, DashStyleHelper.Solid, 4);
    }​
    Attached Files

    #2
    Hello cryfgg,

    Thanks for your post.

    If the indicator is not working as expected, it is likely that the condition to draw the vertical line is not becoming true. You would need to add debugging prints to the script to ensure that the logic to draw the vertical line is being reached.

    In the indicator, add prints to the script (outside of the condition) that print out each condition being used in your script to draw the vertical line and the Time of the bar. This will allow you to see if the conditions in your script are not becoming true. Prints will appear in a New > NinjaScript Output window.

    Also, note the Log tab of the Control Center for any error messages that may appear when running your indicator.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    Let me know if I may assist further.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello cryfgg,

      Thanks for your post.

      If the indicator is not working as expected, it is likely that the condition to draw the vertical line is not becoming true. You would need to add debugging prints to the script to ensure that the logic to draw the vertical line is being reached.

      In the indicator, add prints to the script (outside of the condition) that print out each condition being used in your script to draw the vertical line and the Time of the bar. This will allow you to see if the conditions in your script are not becoming true. Prints will appear in a New > NinjaScript Output window.

      Also, note the Log tab of the Control Center for any error messages that may appear when running your indicator.

      Below is a link to a forum post that demonstrates how to use prints to understand behavior.

      https://ninjatrader.com/support/foru...121#post791121

      Let me know if I may assist further.​
      I already did everything you said above but the Draw.VerticalLine isn't drawing because of the code below on the 3rd <If (statement)> See original post.

      && (High[1] > HSBear1)

      As you can see from the pic I attached, the above code should return TRUE because that condition has been met. I'm not sure what I'm doing wrong or if Ninjascript is screwing with me.

      Comment


        #4
        Hello cryfgg,

        Thanks for your note.

        To clarify, you added prints to the script that print out 'High[1] > HSBear1', such as Print("High[1] > HSBear1: " + (High[1] > HSBear1) + " Time: " + Time[0]);, and the print in the Output window is reporting True for that condition at that time? Or, is this condition reporting False?

        Please add prints to the script that print out each condition used to draw the vertical line on the chart and share a screenshot of the Output window prints showing all the conditions to draw the vertical line are becoming true so I may investigate further.
        • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
        • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
        ​I look forward to assisting further.​
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello cryfgg,

          Thanks for your note.

          To clarify, you added prints to the script that print out 'High[1] > HSBear1', such as Print("High[1] > HSBear1: " + (High[1] > HSBear1) + " Time: " + Time[0]);, and the print in the Output window is reporting True for that condition at that time? Or, is this condition reporting False?

          Please add prints to the script that print out each condition used to draw the vertical line on the chart and share a screenshot of the Output window prints showing all the conditions to draw the vertical line are becoming true so I may investigate further.
          • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
          • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
          ​I look forward to assisting further.​

          I followed your recommendation, and was able to find out the issue. How do i solve the issue below.

          Here is my current code (simplified)

          If (A)
          {
          B = high[0]
          A1 = True
          }

          If ((A) // that is, if "A" happens again
          && A1 == True
          && High > B ) // which never returns - True. Always, returning False.
          {
          B1 = True
          }

          The problem with the above code is this line "&& High > B​". It is never true because whenever "A" is True it assigns the High[0} to B. Thus, the High[0] is never greater than "B".

          How do I keep track of multiple instances of "A" occurring? I'm trying to track each instances of "A" occurring independently.

          For example, I want to track each occurrence of the below code separately:
          if((Close[0] < Open[0])
          && (Close[1] < Open[1])
          && (Close[2] > Open[2])
          && (Close[3] > Open[3])
          )

          Your assistance will be greatly appreciated. I'm new to NinjasSript. ​
          Last edited by cryfgg; 10-06-2022, 10:39 PM.

          Comment


            #6
            Hello cryfgg,

            To confirm, you need for a condition to evaluate as true and then later for a second condition to evaluate as true, before triggering an action, is this correct?

            You can use a bool or set of bools to track this.

            When the first condition is true, set the bool to true as a trigger. When the second condition is true and the bool is true, then trigger the action.

            Below is a link to an example.
            Hi, To improve a strategy, I would like the condition to enter a trade to be triggered only after a second crossing happens. Meaning, for instance we have a sthocastics crossing, but the strategy would only trigger when a crossing between 2 emas happen. Would the looking back N bars work? Can it be done within the builder
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pechtri, 06-22-2023, 02:31 AM
            10 responses
            124 views
            0 likes
            Last Post Leeroy_Jenkins  
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Yesterday, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Yesterday, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Yesterday, 03:01 PM
            2 responses
            22 views
            0 likes
            Last Post helpwanted  
            Working...
            X