Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

adding script not working

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

    adding script not working

    I am trying to draw a box around certain bar patterns. My code works and a box is draw, but only when I code for one pattern. When I try to add patterns using the "IF" statement the boxes vanish. For example Pattern #1 works independently. Patern #2 works independently. Pattern #1 and #2 combined in same indicator do not work.

    What am I missing here?

    here is my code:

    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar < 1) return;

    // Trying to draw box on certain patterns

    // Pattern #1
    if ( Criteria )

    { Draw Rectangle }

    // Pattern #2
    if ( Criteria )
    {Draw Rectangle}
    }

    #2
    You are most likely using the same string name for your rectangles. If they share the same name the latest call to the Draw() method will override the old rectangle.

    You want unique rectangle names. Try this as a technique:
    "Rectangle" + CurrentBar
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      thanks for responding, I tried your suggestion but no luck.

      here is a sample bit of code. Each pattern will display on their own, but together, I get nothing.

      any ideas?

      protectedoverridevoid OnBarUpdate()
      {
      if (CurrentBar < 1) return;

      // Put Patterns below here:
      // Pattern #1
      if (
      High[
      0] > High[1] &&
      High[
      1] > High[2] &&
      High[
      2] > High[3]
      )

      {
      DrawRectangle(
      "MyRectangle"+ CurrentBar, 4, MIN(Low, 4)[0] - TickSize, 0, MAX(High,4)[0] + TickSize , Color.Blue, Color.Yellow,2);
      }

      //Pattern #2
      if (High[0] > High[3])
      {
      DrawRectangle(
      "rectwo"+CurrentBar, 4, MIN(Low, 4)[0] - TickSize, 0, MAX(High,4)[0] + TickSize , Color.Blue, Color.Yellow,2);
      }

      }

      Comment


        #4
        Please check your error logs for any messages. You might be running into this: http://www.ninjatrader-support.com/v...ead.php?t=3170

        Also, you seem to be drawing over in the same spot for both patterns. To confirm you may want to draw in different areas and not rely on colors/transparencies to tell if it is drawing or not.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          I figured out the problem. However I want to make sure I understand what I did.

          I changed the code from:

          if (CurrentBar < 1)
          return;


          to

          if (CurrentBar < 5)
          return;



          Does this mean my indicator needs 5 bars to plot instead of 1 ?

          So by using "1", I did not have enough bars to plot?

          Comment


            #6
            Correct. Judging from the code you provided earlier you were using index values up to 3. This means you need at least 3 bars to work with beforehand and so you would need at least an if-statement with CurrentBar < 3.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              got it, thank you

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              574 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              332 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
              553 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