Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automatic Horizontal Line that plots open and close of candle

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

    Automatic Horizontal Line that plots open and close of candle

    Hello all,

    I am a long time lurker but finally came to a problem I couldn't solve just by lurking.

    I am in need of an indicator that plots a horizontal line on both the open and close of a candle that is changing trend. So basically, if a down candle has printed after printing many up candles, then draw then plot the horizontal line at the open and close prices, same for the opposite direction. The lines should disappear if a new direction is formed. I tried to use N bars up/down but couldnt get it to work. Let me know if anyone has any code/ideas!
    Attached is a picture of how I would want the lines plotted.
    Thanks

    #2
    Hello mattmill4,

    Thanks for your post, and welcome to the NinjaTrader forum.

    The following snippet will draw a signal on down bars after N amount of up bars:

    private int NBarUp = 4;
    protected override void OnBarUpdate()
    {
    if(CurrentBar < NBarUp)
    {
    return;
    }

    if(Close[0] < Open[0])
    {
    double value = NBarsUp(3, true, false, false)[1];
    if(value == 1)
    {
    Draw.Dot(this, "LowBar"+CurrentBar, false, 0, High[0]+TickSize*2, Brushes.Red);
    }
    }
    }

    Comment


      #3
      Thanks for the response. Is there any way to do this on the candle close direction though? I am trying to draw on the first opposite direction candle which cant really be counted.

      Originally posted by NinjaTrader_ChrisL View Post
      Hello mattmill4,

      Thanks for your post, and welcome to the NinjaTrader forum.

      The following snippet will draw a signal on down bars after N amount of up bars:

      private int NBarUp = 4;
      protected override void OnBarUpdate()
      {
      if(CurrentBar < NBarUp)
      {
      return;
      }

      if(Close[0] < Open[0])
      {
      double value = NBarsUp(3, true, false, false)[1];
      if(value == 1)
      {
      Draw.Dot(this, "LowBar"+CurrentBar, false, 0, High[0]+TickSize*2, Brushes.Red);
      }
      }
      }

      Comment


        #4
        Even just help with a single horizontal line that plots the closing price of the first opposite colored candle.

        Comment


          #5
          Hi mattmill4, thanks for your reply.

          The code I posted will only signal on reversal bars. If this is not a solution, could you please post a screenshot of your chart describing the condition?

          I look forward to hearing of your results.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          636 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          568 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X