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

Adding condition to stop DrawDot not working

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

    Adding condition to stop DrawDot not working

    I turn to this community for help once again. Please know I spent several hours researching my own question, trying new things, before taking a step back and asking for help. I learn the old fashion way, trail and error.

    I have the following code that works perfectly:

    if (downScore == 0 && High [0] < upTarget && upStop == 0)

    {DrawDot ("upTarget1" + CurrentBar,true,0,upTarget,Color.Green);}

    The problem is when I want DrawDot to stop. Once the high of the current bar exceeds the upTarget (which is a set price) I want to change the value of upStop to 1, so I tried this:

    if High [0] > upTarget
    {upStop = 1}

    My thinking was that this first piece of code above would no longer Draw the Dot because upStop would not = 0.

    What happens when I add that second piece of code is ALL my dots disappear. I don't understand why since on bar close of the past bars the condition for the DrawDot was met. It is only when price is above the target that I want to stop DrawDot, not wipeout all previous dots.

    What am I missing. Thanks in advance for your guidance.

    #2
    Hello sarasotavince,

    Thank you for your post.

    Is upStop ever set to zero in the OnBarUpdate() method? Or only initially? How is the upStop defined when set to zero?

    I look forward to your response.

    Comment


      #3
      Good Evening Patrick,

      I had upStop set to "0" under
      protected override void Initialize() initially, but moved under
      protected override void OnBarUpdate()
      and after reading your post.

      (If I have it in both places no dots print at all)

      I added back the code:

      if (High [0] > upTarget)
      {upStop = 1;}

      Dots are printing but they are not turning off when price drops below upTarget price, which I cannot explain. I have added an image with some markings. In short, when price drops below the upTarget price, the dots are printing again, ignoring the upStop = 1 condition, which must not be working with the above code.

      By the way, If I set upStop to 1 under OnBarUpdate(), no green dots print at all, which makes sense since the condition to print is not met.

      If you need to see more code or I have not been clear, please ask for whatever you need.
      Attached Files

      Comment


        #4
        My first guess is that there is an issue with values being set/reset after the condition is met. depending on what's in the script you might need to create an additional variable to track the state and then set your upStop based on the state of that variable.

        Would you be able to post a simple script that replicates the error so that I can take a closer look?

        Located in (MY)Documents\NinjaTrader 7\bin\Custom\Indicator
        LanceNinjaTrader Customer Service

        Comment


          #5
          I will look at my code again and if needed I will post a simple script.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AveryFlynn, Today, 04:57 AM
          0 responses
          3 views
          0 likes
          Last Post AveryFlynn  
          Started by RubenCazorla, 08-30-2022, 06:36 AM
          3 responses
          77 views
          0 likes
          Last Post PaulMohn  
          Started by f.saeidi, Yesterday, 12:14 PM
          9 responses
          23 views
          0 likes
          Last Post f.saeidi  
          Started by Tim-c, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          5 views
          0 likes
          Last Post FrancisMorro  
          Working...
          X