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

Creating Donchian Channel Crossover Strategy

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

    Creating Donchian Channel Crossover Strategy

    Hey Guys,I am working on a strategy that goes short when the price closes under the lower donchian channel and long when it closes above the upper band. I have the look back period set to 1. I have created this strategy in the strategy wizard, but it does not seem to enter any trades. Can someone take a look at the code here and tell me what I am doing wrong?
    thanks in advance
    {
    // Condition set 1
    if (CrossAbove(Close, DonchianChannel(Period).Upper, 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(Close, DonchianChannel(Period).Lower, 1))
    {
    EnterShort(DefaultQuantity, "");
    }

    // Condition set 3
    if (CrossBelow(Close, DonchianChannel(Period).Lower, 1))
    {
    ExitLong("", "");
    }

    // Condition set 4
    if (CrossAbove(Close, DonchianChannel(Period).Upper, 1))
    {
    ExitShort("", "");
    }
    }

    #2
    Price may rarely cross outside the Donchian's depending on your settings - please include a drawing in your conditions to visually check when the signals you setup can be expected to trigger -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Since price rarely crosses the Donchian Channel could we make the lookback period a few bars ago so that it reads the price of the donchian channel high/low from a few bars back?

      Is this how I would look for the Donchian Value 3 bars back since the current bars donchian channel is always at or above current price.

      && CrossAbove(Close, DonchianChannel(20).Upper[3],1

      Comment


        #4
        Hello brucelevy,

        The code you provided would indeed let you know whether a crossover condition occurred between the 3rd and 4th bars back on the upper channel band. Please let us know if there are any other ways we can help.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by brucelevy View Post
          Since price rarely crosses the Donchian Channel could we make the lookback period a few bars ago so that it reads the price of the donchian channel high/low from a few bars back?

          Is this how I would look for the Donchian Value 3 bars back since the current bars donchian channel is always at or above current price.

          && CrossAbove(Close, DonchianChannel(20).Upper[3],1
          You need to look back exactly one bar for the channel break.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, 04-19-2024, 09:40 AM
          10 responses
          74 views
          0 likes
          Last Post alifarahani  
          Started by Zeezee, Today, 12:45 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by tomasak, Today, 12:54 PM
          0 responses
          1 view
          0 likes
          Last Post tomasak
          by tomasak
           
          Started by swjake, Today, 12:04 PM
          2 responses
          9 views
          0 likes
          Last Post swjake
          by swjake
           
          Started by Richozzy38, Yesterday, 01:06 PM
          5 responses
          25 views
          0 likes
          Last Post Richozzy38  
          Working...
          X