Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to avoid a redundant plot?

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

    How to avoid a redundant plot?

    Hello

    I've developed an indicator that draws a Dot above/below a candle when certain conditions for a short/long are met. If the candle following the signal doesn't make a lower low (for shorts) than the low of the candle that produced the signal, the dot is removed once the bar is closed.

    What I'd like to achieve now is to avoid two dots in a row, ie if two consecutive candles meet the criteria, the second one shouldn't display a dot.

    Any help is much appreciated.

    Here's the code for the first part (for shorts):

    if( conditions here )

    {
    DrawDot("DotShort" + CurrentBar, false, 0, High[0]+ 2*(TickSize), Color.Black);
    }

    if (Low[0] >= Low[1])
    {
    RemoveDrawObject("DotShort" + (CurrentBar -1));
    }
    Last edited by laocoon; 09-20-2010, 09:21 AM.

    #2
    Hello Laocoon,

    You would probably want to use bool flags for this, to create the sequence you're after.

    if( conditions here && myBoolFlag)

    {
    DrawDot("DotShort" + CurrentBar, false, 0, High[0]+ 2*(TickSize), Color.Black);
    myBoolFlag = false;
    }

    if (Low[0] >= Low[1])
    {
    RemoveDrawObject("DotShort" + (CurrentBar -1));
    myBoolFlag = true;
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello RyanM

      Thanks for your reply. I did a search in Ninja's support section about Bool Flags but couldn't find anything. I understand the general logic behind your example but would like to learn a bit more about bool flags.

      Is there another place I should look for explanations or examples?

      Thanks a lot.

      Comment


        #4
        This is more of a programming concept than specific to NinjaScript. I'd check the MSDN documentation if you're looking for help with the structure of bools or a programming guide to understand the concept a little better.

        We have this reference sample on using user variables in the strategy wizard. It uses integer values instead of bools but is helpful for defining sequences, which is essentially what you're doing here.

        Using User Variables in the Strategy Wizard
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi RyanM

          After playing around a bit with the code, I integrated it into my strategy and it works perfectly. Thanks a lot for your help.

          Regards

          Comment


            #6
            Hello RyanM

            I integrated your code in my strategy and it works fine, but I have another question:
            Once a dot has been plotted on the chart I want the strategy to wait until a certain condition is met before it plots another dot (see last part of the code snippet). For some reason the strategy ignores the code although it feels right to me. (The only issue I can think of is that I can't use the same bool flag to verify two conditions.)
            Could I ask you to take a quick look?

            Thanks a lot.

            if( conditions here && myBoolFlag)

            {
            DrawDot("DotShort" + CurrentBar, false, 0, High[0]+ 2*(TickSize), Color.Black);
            myBoolFlag = false;
            }

            if (Low[0] >= Low[1])
            {
            RemoveDrawObject("DotShort" + (CurrentBar -1));
            myBoolFlag = true;
            }

            //New Code
            if (MACD(12, 26, 9).Diff[1] < 0)
            {
            myBoolFlag = true;
            }

            Comment


              #7
              All your statements are if, meaning there's potential for all to evaluate true on the same bar. To debug this, I would use print statements within each block to verify what returns true for a given bar. This may give you a better understanding of what's happening.


              if( conditions here && myBoolFlag)

              {
              DrawDot("DotShort" + CurrentBar, false, 0, High[0]+ 2*(TickSize), Color.Black);
              myBoolFlag = false;
              Print (CurrentBar + ": Condition1);
              }

              if (Low[0] >= Low[1])
              {
              RemoveDrawObject("DotShort" + (CurrentBar -1));
              myBoolFlag = true;
              Print (CurrentBar + ": Condition2);
              }

              //New Code
              if (MACD(12, 26, 9).Diff[1] < 0)
              {
              myBoolFlag = true;
              Print (CurrentBar + ": Condition3);
              }
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              601 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              347 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              559 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              558 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X