Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 03:20 PM
        0 responses
        5 views
        0 likes
        Last Post cre8able  
        Started by Fran888, 02-16-2024, 10:48 AM
        3 responses
        47 views
        0 likes
        Last Post Sam2515
        by Sam2515
         
        Started by martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        31 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X