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 DayTradingDEMON, Today, 09:28 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Stanfillirenfro, Today, 07:23 AM
        9 responses
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by George21, Today, 10:07 AM
        0 responses
        8 views
        0 likes
        Last Post George21  
        Started by navyguy06, Today, 09:28 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        8 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X