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

Semi Automated trendline channel

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

    Semi Automated trendline channel

    Hello,
    I have been developing an indicator that creates an automated trend channel.
    My indicator calculates a the initial starting point from the high side (in green below) which i'm happy with. My issue is for how to calculate the other variables in red and im stuck here.

    TChighs = Draw.TrendChannel(this, @"TChighs", false, highestBarZone3, highestBarZone3Price, NextHighestBar, NextHighestBarPrice, LowestBar, LowestBarPrice );

    These are substantially more difficult, and clearly using next highest bar and next lowest bar didnt work as you can see in picture below. Green is from the indicator and the purple is what it is supposed to look like:

    Click image for larger version  Name:	image.png Views:	0 Size:	30.5 KB ID:	1277711


    Is there a way or has anyone solved this? im guessing have to gradually decrease the slope of the top line until it makes contact with price and then save that BarNumber and ​​​​High price?
    then do some similar other calculation with the lower trend line and raise it incrementally ? I have no idea how to begin to calculate this stuff but i think if anyone has, or can help, it would be good for the community (and me ) to derive a full trend channel from just one given price point.
    Last edited by madb123; 11-13-2023, 10:18 AM.

    #2
    Hello madb123,

    I'd like to clarify what you are trying to do.

    On each new bar, are you trying to find if the high is higher than the previous n bars?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello madb123,

      Unfortunately, you have not provided the specific logic you are trying to implement. (Screenshots are not going to help here. Please use words to describe the logic.)

      What is the rule of finding the NextHighestBar value?

      Is this when the current bar's high is greater than a specific previous bar's high?
      (For example, if the high is greater than the high 5 bars ago then draw the trend line from the high of 5 bars ago to the current bar?)
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi Chelsea, ok please ignore what i said before and I'll try to explain myself differently here:
        using this overload:
        Draw.TrendChannel(NinjaScriptBase owner, string tag, bool isAutoScale, int anchor1BarsAgo, double anchor1Y, int anchor2BarsAgo, double anchor2Y, int anchor3BarsAgo, double anchor3Y)


        I have a logic that calculates the first anchor point (anchor1BarAgo and anchor1Y), and this is fine.

        I need to derive 2nd and 3rd anchor points for the TrendChannel. The logic is:

        anchor2BarAgo and anchor2Y: This needs to be set to the bar immediately after anchor1BarAgo and its high for anchor2Y, and then updated on each bar close by checking if High[0] is more than trendline, Bar[0] becomes the new anchor2BarAgo ​and its high the new anchor2Y
        ( this way the upper trendline always attaches to the same original anchor point on the left side of the chart. But on the right side it anchors to the most recent high that crossed the trend line on its prior anchor values).

        anchor3BarsAgo and anchor3Y: similarly, This needs to be set to the bar immediately after anchor1BarAgo and its Low for anchor2Y, and then updated on each bar close by checking if Low[0] crossed below than trendline, in which case Bar[0] becomes the new anchor3BarAgo ​and its Low the new anchor3Y
        ( this way the lower trendline always attaches to the widest point on the low side of the chart that creates only one touch point).

        Is this ok now?​

        Comment


          #5
          Hello madb123,

          updated on each bar close by checking if High[0] is more than trendline

          The NextHighestBar is just the high of the bar?

          Meaning if the current bars high is greater than the previous bars high, update the object again to the high of the current bar? If the high is not greater than the previous bar then don't update the object?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            updated on each bar close by checking if High[0] is more than trendline: correct if this happens update the object.

            This is not the same as checking if current bars high is greater than the previous bars high, and would not result in the same trend channel

            Comment


              #7
              Hello madb123,

              The TrendLine, having been updated on each new bar to the high of the new bar, ends at the high on the last bar correct?

              So the if the high is greater than the high of the previous bar its also above the trend line, correct?

              If not, you can always calculate the y-intercept on the current bar and check the high is greater than this.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                No, unfortunately that does not work for a correct automated trend channel.
                sorry but i have to use a picture example here:
                - see on the right side it is anchored to much lower bars in general than where the anchor was on left side.
                - most recent bar is green, it has higher high than the one before it but it is still not the anchor, not until it crosses the channel, then we will anchor to it so that all other bars remain with in.
                - current right side anchor has a lower high than the previous candle that was the anchor last time this channel was crossed by a high.
                Checking for a cross and then updating object is the only way i can think of to achieve the below purple channel.

                Click image for larger version

Name:	image.png
Views:	97
Size:	64.2 KB
ID:	1277734​​
                Attached Files

                Comment


                  #9
                  Hello madb123,

                  The screenshot does not appear to match your written rules.

                  This needs to be set to the bar immediately after anchor1BarAgo and its high for anchor2Y, and then updated on each bar close by checking if High[0] is more than trendline, Bar[0] becomes the new anchor2BarAgo ​and its high the new anchor2Y

                  From the very first bar the trend is drawn on, the high has to be greater than the previous bar so the trendline should be an up trend. If the high is not greater than the trendline then the trend line should not be drawn again so should end on that bar, correct?

                  That said, just check if the high is above the y-intercept.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    hi chelsea i appreciate your follow through and patience.

                    "From the very first bar the trend is drawn on, the high has to be greater than the previous bar so the trendline should be an up trend. If the high is not greater than the trendline then the trend line should not be drawn again so should end on that bar, correct?"

                    Well no, the first anchor point i said is calculated with a different logic imbedded in the indicator. Consider it a fixed starting point or user input. So if the channel object is created starting from this bar and then we are deriving the next anchors by anchoring to the each candle that breaks the trend line. the point here is to have 2 touches only, which might be uptrend or downtrend. If price continues to fall, from here for example.. the channel continues to widen downwards but same slope.

                    Comment


                      #11
                      is there a way to check for crossabove() crossbelow() channel trendline?

                      "That said, just check if the high is above the y-intercept."
                      how do i do this? any link where to look? thanks
                      Last edited by madb123; 11-13-2023, 12:40 PM.

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hello madb123,

                        The TrendLine, having been updated on each new bar to the high of the new bar, ends at the high on the last bar correct?

                        So the if the high is greater than the high of the previous bar its also above the trend line, correct?

                        If not, you can always calculate the y-intercept on the current bar and check the high is greater than this.
                        https://ninjatrader.com/support/foru...663#post828663
                        Ahh i just noticed this thanks!

                        Comment


                          #13
                          Hello madb123,

                          For a CrossAbove()/CrossBelow you would need to first calculate the y-intercept. And then yes, you can supply this as a double to the cross method.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi NinjaTrader_ChelseaB thanks a lot for the help yesterday.

                            I moved forward, below is the code which is almost there. .
                            So within the For loop, i am setting the int shiftForward when High[1] > pprice where pprice is projected price.

                            However it does not persist when High[1] < pprice.. the weird thing is that it reverts to the last value not 0.
                            i am not sure why that is happening or the proper way to handle variables within For loop.
                            Any help/ ideas? I included all my code used for this auto trendline here:

                            Code:
                            
                            
                            result: you can see here for some reason projected points in dots shift down to most recent line slope that wasnt broken. they should stay at the max slope that wasnt broken.
                            Click image for larger version  Name:	image.png Views:	0 Size:	55.3 KB ID:	1277862
                            Last edited by madb123; 11-14-2023, 10:12 AM.

                            Comment


                              #15
                              Hello madb123,

                              Below is a publicly available link to a 3rd party educational site on Scope.


                              A variable declared in an if statement block can only be used in the if statement block.
                              A variable declared in a method can only be used in the method block.
                              A variable declared in a class can be used anywhere in the class.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Segwin, 05-07-2018, 02:15 PM
                              14 responses
                              1,789 views
                              0 likes
                              Last Post aligator  
                              Started by Jimmyk, 01-26-2018, 05:19 AM
                              6 responses
                              837 views
                              0 likes
                              Last Post emuns
                              by emuns
                               
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              6 responses
                              3,294 views
                              1 like
                              Last Post jgualdronc  
                              Started by Touch-Ups, Today, 10:36 AM
                              0 responses
                              13 views
                              0 likes
                              Last Post Touch-Ups  
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              11 responses
                              63 views
                              0 likes
                              Last Post halgo_boulder  
                              Working...
                              X