Announcement

Collapse
No announcement yet.

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.

    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

        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.

            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 NullPointStrategies, Today, 05:17 AM
              0 responses
              50 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              126 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              69 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X