Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator colour coding one bar too early

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

    Indicator colour coding one bar too early

    Hi all,

    I attach an image of an indicator I've written. The indicator panel should be coloured red for instance if the curve is between the two dashed horizontal lines. However you can see that it draws the colour one bar early everywhere.

    The colour is chosen after the indicator is set by testing on its value. In rough pseudocode:

    Set value of indicator using Close[0] and SMA(50)[0]
    If the set value is between -0.01 and -0.02 then set background color as red

    What is my obvious error here?

    Thanks,
    darmbk.
    Attached Files

    #2
    Originally posted by darmbk View Post
    Hi all,

    I attach an image of an indicator I've written. The indicator panel should be coloured red for instance if the curve is between the two dashed horizontal lines. However you can see that it draws the colour one bar early everywhere.

    The colour is chosen after the indicator is set by testing on its value. In rough pseudocode:

    Set value of indicator using Close[0] and SMA(50)[0]
    If the set value is between -0.01 and -0.02 then set background color as red

    What is my obvious error here?

    Thanks,
    darmbk.
    Congrats on writing the indicator, looks good.

    When it comes to painting a background, note that the painting occurs from the center of the distance between bars, so the background will always encompass (both sides of) the bar. While your calculations are correct it is the width of the bar and space between bars that is creating the illusion of being one bar early. You can validate this yourself by drawing an object such as a triangle at the point of the detection and it should be plotted at that point of detection and not one bar before.

    Comment


      #3
      Hello Darmbk,

      Thank you for your post and thank you to Tasker for answering.

      Yes, this is correct. I would follow Tasker's example with the triangle and see how that plots in relation to the chart.

      Let me know if I can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 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
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X