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

Trailing Indicator

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

    Trailing Indicator

    I wanted to create an indicator showing the 3 day highest high and lowest low, which is similar to Donchain Channel. Something like what I've attached. I was wondering how should I programme it.
    Attached Files

    #2
    Hello,
    Hello,
    Use DrawHorizontalLine() to draw lines representing your 3 day high and 3 day low values. I have included an example below of how to accomplish this.


    Code:
    [COLOR=#000000][FONT=Tahoma]protected override void Initialize()
            {      Add(PeriodType.Day, 1);
            }[/FONT][/COLOR]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF] protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]        {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                stopPricehigh = High[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]];    [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]
    [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](High[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] <= HighestBar(Highs[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]             ExitLongStop(stopPricehigh);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            }     [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                stopPrice = Low[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]];    [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]
    [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Low[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] <= LowestBar(Lows[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]             ExitLongStop(stopPrice);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            }     [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  DrawHorizontalLine([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"HighLine"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] , stopPricehigh, Color.Black);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  DrawHorizontalLine([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"LowLine"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] , stopPrice, Color.Black);[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR]
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      What you have attached is a Donchian Channel displaced by one bar.

      Simply take the standard Donchian Channel and set the Displacement to +1.

      Attached is a screenshot showing a displaced Donchian Channel for the section of the ES chart that you have posted.

      It is my own version of the Donchian Channel, which has a trend filter added.
      Attached Files

      Comment


        #4
        May I know what does the () and [] mean in DonchianChannel? For example: DonchianChannel(1).Lower[10]

        And can someone tell me whats the difference between period n bar? Thx
        Last edited by JT1230; 11-11-2015, 10:07 AM.

        Comment


          #5
          Originally posted by JT1230 View Post
          May I know what does the () and [] mean in DonchianChannel? For example: DonchianChannel(1).Lower[10]

          And can someone tell me whats the difference between period n bar? Thx
          (1) is the lookback period. To implement your idea you would need to set the lookback period to 3.

          [10] indicates the bar which is used to perform calculations. A value of 10 indicates that the last bar used for calculations was 10 bars ago. 0 designs the current bar.

          For example DonchianChannel(1).Lower[10] means the lower channel of a 1-period Donchian Channel (this would be just the low) calculated 10 bars ago. Therefore it will return the low of the bar 10 bars ago.

          Comment


            #6
            Hello JT1230,
            Harry is correct. The () holds a value for the period or number of bars used in the calculation. The [] holds a int value specifying the number of bars ago.
            I have included the Donchian Channel Help Guide to assist you further.
            Shawn B.NinjaTrader Customer Service

            Comment


              #7
              Sorry I'm a newbie, please bear with me. I didn't get what you meant. Are you saying that both Periods and Bars ago are for calculation? It would be easier for me to comprehend if you can attach a picture for me to compare.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              17 views
              0 likes
              Last Post RookieTrader  
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              2 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              38 views
              0 likes
              Last Post love2code2trade  
              Started by alifarahani, Today, 09:40 AM
              2 responses
              14 views
              0 likes
              Last Post alifarahani  
              Started by junkone, Today, 11:37 AM
              3 responses
              21 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X