Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding programmatically when price approaches manually drawn trend line or channel

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

    Finding programmatically when price approaches manually drawn trend line or channel

    Hello,

    Do you have any reference samples on how to programmatically detect when price is approaching (x number of ticks) to manually drawn trend line or regression channel (upper or lower part of it)?

    Thanks

    #2
    Hello music_p13,

    Thank you for the post.

    Please see this example that can detect every horizontal line on the chart and label them programmatically:

    https://ninjatraderecosystem.com/use...izontal-lines/

    You can do the same thing with a regression line. It does not need to be within OnRender for your purpose. You can do the same in OnBarUpdate like so:

    Code:
    private NinjaTrader.NinjaScript.DrawingTools.RegressionChannel RC;
    
    ...
    
    protected override void OnBarUpdate()
            {
                foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects)
                {
                    if(thisObject is NinjaTrader.NinjaScript.DrawingTools.RegressionChannel)
                    {
                        RC = thisObject as NinjaTrader.NinjaScript.DrawingTools.RegressionChannel;
    
                        Print(RC.StartAnchor.Price.ToString());
                        Print(RC.EndAnchor.Price.ToString());
    
                    }
    
                }
            }
    ​​​​​​​The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Please let me know if I can assist further.

    Comment


      #3
      Thanks Chris,

      And is there an easy way to retrieve price for a simple line or Ray - let's say "2 bars ago" - so see what the value of that line was 2 bars ago (provided it is NOT a horizontal line)... Or even for current bar...

      Thanks

      Comment


        #4
        Hello music_p13,

        Thank you for the reply.

        You would need to use the Time object from the chart start/end anchor and use GetSlotIndexByTime():



        That method will return the bar index of that time. The index counts up from the leftmost bar on the chart. From that data, you can find the price of any bar between the start anchor and the end anchor. You will essentially find the slope of the line in terms of price vs time.

        Please let me know if I can assist further.

        Comment

        Latest Posts

        Collapse

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