Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X