Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator not drawing to current bar

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

    Indicator not drawing to current bar

    I have an indicator that I'm using to identify swing highs. But it doesn't draw to the last bar. I'm drawing to Time[0] which I thought would draw the line all the way to the current bar that is forming. What did I miss?



    PHP Code:
                if (Count - 2 == CurrentBar)
                {
                for (int x = 0; x < swingHighs.Count; x++)
                    {
                        Draw.Line(this, "swingHigh" + swingHighs[x].swingHLStartTime, false,
                            swingHighs[x].swingHLStartTime,
                            swingHighs[x].swingHLValue,
                            Time[0],
                            swingHighs[x].swingHLValue,
                            swingHighs[x].EQH == 1 ?  Brushes.Green : Brushes.Lime,
                            swingHighs[x].EQH == 1  ? DashStyleHelper.Dash : DashStyleHelper.Solid,
                            swingHighs[x].EQH, true);
                    }
    &#8203; 
    
    Click image for larger version

Name:	image.png
Views:	97
Size:	2.3 KB
ID:	1294960

    #2
    Oops. I realized I'm using OnBarClose so it wont draw until the bar closes. I don't want to change that so how do I draw the end of the line 1 bar over when using DateTime for the 2 ends of the line?

    When I'm using bar indexing, I would just make it -1.

    How do I shift the end 1 bar to the right?

    Comment


      #3
      Hello cre8able,

      Thanks for your post.

      When using Calculate.OnBarClose the OnBarUpdate() logic in your script will only process at the close of each bar. This means all calculations and actions will occur when the bar closes.

      For an indicator to calculate logic intrabar and draw objects on the currently building bar instead of the bar that closed the script should be set to Calculate.OnPriceChange or Calculate.OnEachTick.

      Calculate: https://ninjatrader.com/support/help.../calculate.htm

      Passing in a negative value for the barsAgo is not supported and would have to be used at your own discretion.

      If you want only some of your logic to occur OnBarClose and other logic to occur OnPriceChange/OnEachTick then you could use IsFirstTickOfBar in the script to separate that logic.

      Please see the reference sample below which demonstrates a technique used for those who need to separate their logic to calculate some values on each tick and others only on the close of a bar. You will set your host script to Calculate.OnEachTick and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnEachTick outside of the IsFirstTickOfBar condition check.

      SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      52 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      71 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      38 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      99 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      60 views
      0 likes
      Last Post PaulMohn  
      Working...
      X