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 charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          73 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          152 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          162 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          100 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          288 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Working...
          X