Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Lines for Min / Max Last (N) Bars

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

    Draw Lines for Min / Max Last (N) Bars

    I'm trying to draw lines on the price chart that shows the Min and Max price range of the last (n) bars. Can't quite get it right using the Strategy Wizard or editing existing examples in the forum.

    Essentially, the two lines would form a channel that draws from the current bar backward. The boundaries of the channel are defined by the Min and Max prices of the previous (n) bars. In the example attached, it uses a value of 8 for (n) bars back. But I also want the lines to extend back past the 8th bar back just so it is more visually appealing.

    The idea is to make it apparent when the current bar breaks out of the range of the channel. So an audio alert should be added when price breaks the boundary.

    As each new bar closes the channel needs to be redrawn. I'd appreciate ideas from anyone that can help with this indicator.
    Attached Files

    #2
    Hondo,

    this link explains how to draw a line on to the chart without restrictions. Not exactely what you are looking for, but with some modifications it would serve your purpose:



    Regards
    Ralph

    Comment


      #3
      Thanks Ralph, that helps. Still having a few issues with it but at least I think I'm on the right track now.

      Comment


        #4
        A simpler way to do this.

        Do not go with the PLOT method to solve something as simple as this. Just use OnBarUpdate()




        Just use something like :-
        1. Calculate the values for your line. Try the MAX & MIN functions. Ensure you have a parmameter called Period.
        Code:
        [FONT=Courier New][COLOR=#008000]1. Max Function to find the Max High in the past "Period" bars.[/COLOR][/FONT]
        [FONT=Courier New][COLOR=#0000ff]double[/COLOR] HHV = [COLOR=magenta][B]MAX[/B][/COLOR](High, period)[0];[/FONT]
        2. Have another parameter which says how many bars back you want the line to start. eg: LinePeriods

        3. then draw the line, starting "LinePeriods" back.
        Code:
        [FONT=Courier New][COLOR=magenta][B]DrawLine[/B][/COLOR]("Rest"+CurrentBar.ToString(), [COLOR=#0000ff]false[/COLOR], LinePeriods, HHV, 0, HHV, Color.LimeGreen, DashStyle.Dot, 2);[/FONT]
        4. Then when the High[0] > HHV you have a breakout.
        Code:
        [FONT=Courier New][COLOR=#008000]// Plays the wav file mySound.wav[/COLOR] [/FONT]
        [FONT=Courier New][B][COLOR=magenta]PlaySound[/COLOR][/B](@"C:\mySound.wav");[/FONT]
        5. Then raise an alert.
        Code:
        [FONT=Courier New][COLOR=#008000]// Generate[/COLOR][COLOR=seagreen]s an alert[/COLOR][/FONT]
        [FONT=Courier New][COLOR=magenta][B]Alert[/B][/COLOR]("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);[/FONT]
        6. To prevent you indicator from getting errors do not plot anything untill you have sufficient bars. The 1st line in your OnBarsUpdate Method() should be
        Code:
        if(CurrentBar < [FONT=Courier New]LinePeriods[/FONT] )
        return.
        Hope this helps

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        577 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X