Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rectangle on BB

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

    Rectangle on BB

    When I try to draw a rectangle when price crosses above or below the BB It doesn't always work. Why is that?
    I'm just using a simple cross above or below bollinger.upper or bollinger.lower.
    Attached Files

    #2
    Hello r3n3v,

    Thanks for your post.

    Can you show your code?

    Can you clarify what you are trying to show/indicate with a rectangle?

    Are you testing on live data, historical data, or Playback with market replay data?

    What calculate setting are you running the script on?

    Comment


      #3
      Live Data. I've used both PriceChange as well as Tick.

      Code:
      if (CrossAbove(Bollinger1.Upper, Close[0], 1))
      {
      
      Rectangle myRec = Draw.Rectangle(this, "bbTop1"+CurrentBar, 0, Low[0], -10, High[0], Brushes.Transparent);
      myRec.AreaBrush = Brushes.LightGray;
      }
      Last edited by r3n3v; 08-27-2021, 11:21 AM.

      Comment


        #4
        Hello r3n3v,

        Thanks for your post.

        Please change your crossabove to: if (CrossAbove(Close, Bollinger1.Upper, 1))

        Comment


          #5
          Thanks! I just did and It doesn't always draw the rectangle when price crosses above the bb.
          Attached Files
          Last edited by r3n3v; 08-27-2021, 12:03 PM.

          Comment


            #6
            Hello r3n3v,

            Thanks for your reply.

            Please add a debug print to your code that will print when the cross condition is true. This will help to determine if the condition is the issue or the draw method.

            For example:


            if (CrossAbove(Bollinger1.Upper, Close[0], 1))
            {
            Print (Time[0]+" Cross condition true");
            Rectangle myRec = Draw.Rectangle(this, "bbTop1"+CurrentBar, 0, Low[0], -10, High[0], Brushes.Transparent);
            myRec.AreaBrush = Brushes.LightGray;
            }


            Before updating the indicator on the chart, open the New>Ninjascript output window to observe the prints when they appear. Once you have print statements compare them to the chart (just a few cases) and see if there is a rectangle drawn at each instance of a print.

            Comment


              #7
              I'm only getting 3 conditions on a 5 min chart. It skips these. And the print statement doesn't identify the other times price did cross. I switched it to use arrows down and same thing.
              Attached Files

              Comment


                #8
                Hello r3n3v,

                Thanks for your reply.

                I made a mistake with my copy and paste.

                Please try:

                if (CrossAbove(Close, Bollinger1.Upper, 1))
                {
                Print (Time[0]+" Cross condition true");
                Rectangle myRec = Draw.Rectangle(this, "bbTop1"+CurrentBar, 0, Low[0], -10, High[0], Brushes.Transparent);
                myRec.AreaBrush = Brushes.LightGray;
                }

                Comment


                  #9
                  I actually used that Code...Close.

                  Comment


                    #10
                    Hello r3n3v,

                    Thanks for your reply.

                    Please replace the CrossAbove() with the following:

                    if (Close[0] > Open[0] && Close[0] > Bollinger1.Upper[0] && Open[0] < Bollinger1.Upper[0])

                    Comment


                      #11
                      Thanks a lot it worked!

                      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