Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Consecutive red or green bars supply and demand

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

    Consecutive red or green bars supply and demand

    I am trying to make a custom indicator for supply and demand based on range bars. If there are 4 consecutive up bars or down bars then I want to draw a rectangle. I have looked at nBarsUp and nBarsDown but that did not help me much. The rectangle for a supply would be drawn based on the high of the bar before the 3 consecutive bars down until the low of the first bar after the green candle. It would be the opposite for Demand.

    I would so much appreciate your help! Thanks!!



    #2
    Hello Graci117,

    Thanks for your post.

    To check if a bar is an up bar you could create a condition that checks if the Close price (Close[0]) is greater than the Open price (Open[0]).

    Checking for consecutive up bars would require creating multiple price comparisons and supplying a BarsAgo value to check previous bars.

    For example, Close[0] and Open[0] have a BarsAgo value of 0 so this would check if the current bar is an up bar. Close[1] and Open[1] have a BarsAgo value of 1 so this would check if the previous bar is an up bar. Close[2] and Open[2] have a BarsAgo value of 2 so this would check if the bar 2 bars prior from the current bar is an up bar, and so on.

    To check if there are 4 consecutive up bars, the code might look something like this:

    if (Close[0] > Open[0] && Close[1] > Open[1] && Close[2] > Open[2] && Close[3] > Open[3])
    {
    //do something.
    }

    Note to check if a bar is a down bar you would compare if the Close price (Close[0]) is less than the Open price (Open[0]).

    PriceSeries: https://ninjatrader.com/support/help...riceseries.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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    150 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    303 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    243 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    345 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    174 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X