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

Trend Line Price Break

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

    Trend Line Price Break

    Hi,

    I'm looking to add a simple price break above or below the TrendLine indicator to my strategy. Is there a simple way to use the TrendLine indicator in a strategy to determine when the current price breaks above a down trend line and breaks below an up trend line? I have tried using the strategy builder, but keep getting a bars error. I don't see an option to identify an up or down trend line in a strategy.

    Thanks,
    Lee
    Last edited by lee612801; 04-10-2020, 12:53 PM.

    #2
    Hello lee612801,

    Thanks for your message.

    Taking a look at the code, the TrendLines indicator adds one plot that can be read from the Strategy Builder. Testing what the plot shows by printing it out in the Strategy Builder, we can see the plot value represents where the line will intersect with the current bar slot. Given this, it can be compared against the processing bar to see if it has current price has crossed above or below the trend line, or to make similar conditions.

    As for checking if the Trend Line is rising or falling you can compare the TrendLine Plot's current bar value (BarsAgo 0) to the last bar's value (BarsAgo 1) and see if it is greater or less than the previous value.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      Thanks for the response. When I do a check of the trend lines plot bars values between 0 and 1, I get a bars ago error. I found that the bars ago 1 value is the problem. I think the issue is the bars ago values depend on the last swing points, which is not always a bars ago of 1. If this is the case, what else can I do?

      Thanks,
      Lee
      Last edited by lee612801; 04-13-2020, 06:50 AM.

      Comment


        #4
        Hello Lee,

        You may have forgotten to add a CurrentBar check.



        You can also test adding your print from the Strategy Builder and it will generate the syntax required.

        We look forward to assisting.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          Thanks for the input. I will give this a try. I did use the Stategy Builder to get the code I am using.

          I'm still wondering if the Bars Ago check will work with the TrendLine indicator, specifically does the Trendline indicator alwasy have a BarsAgo 1 value? I tested on a range of a couple years, so there should have been plenty of bars. If TrendLine (BarsAgo 1) does not always exist, then how I would determine the trend direction by comparing the current bar value (BarsAgo 0) to the last bar's value (BarsAgo 1)?

          Thanks,
          Lee

          Comment


            #6
            Hello Lee,

            Logically, the TrendLines indicator will have to create its first swing in order for plot values to be assigned. After that, a plot value is assigned with each new bar, so BarsAgo 1 references for the indicator's plot will have a meaningful value 1 bar after the first plot is made. This value will otherwise be 0 if the indicator has not yet assigned a plot value for that bar.

            Testing the print from post #4 on a chart with 50 bars to load can help illustrate.

            Please let us know if we can be of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi Jim,

              Tried it out last night and it seems like it worked just like you said. I also had an issue with another part of my code that was looking back 2 bars, so I was able to use the same solution to fix that as well.

              Thanks for the help,
              Lee

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Sparkyboy, Today, 10:57 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by swestendorf, Today, 11:14 AM
              1 response
              2 views
              0 likes
              Last Post swestendorf  
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              21 responses
              3,917 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              156 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              812 views
              1 like
              Last Post grayfrog  
              Working...
              X