• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Donchian Channel Strategy

  • Filter
  • Time
  • Show
Clear All
new posts

    Donchian Channel Strategy

    I would, in general, like to achive the following:
    When we are in a long position and touching the upper DC from below - SELL.
    And when we are in a short position and touching lower DC from upper - BUY.
    I also have an EMA and maybe need to check if we are under or over of the EMA.
    18 or 20 period. Maybe 10 or 11.

    Hello Kennet,

    Is this a script that you are creating yourself, or are you asking a member of the community to build this script for you?

    If you are creating this yourself, what code do you have so far?
    Are you receiving an error message when running the script?
    Are you stuck at a particular point and need assistance with a specific object?

    Attached is a screenshot of how the condition:
    When we are in a long position and touching the upper DC from below - SELL
    would look in the Strategy Builder.
    Attached Files
    Chelsea B.NinjaTrader Customer Service


      Thank you!
      I have started to write the script in the code editor to be more free in structuring the code.
      I don´t get the trade to be done on the right bar.
      The trade seems to com one bar after what I want.
      I use High/Low instead of Close and CalculateOnBarClose=false:



        Could you tell me, how are you testing the strategy currently? Is this is Realtime or in another mode such as Backtesting?

        There are differences between backtests and realtime results which some of which can be explained in this document. http://ninjatrader.com/support/helpG...htsub=backtest

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service


          I am using external feed and backtesting.


            And if (Position.MarketPosition == MarketPosition.Long) or Short
            does not seem to work.



              Hello Kennet,

              The External data feed is meant to be used to connect to a 3rd party application such as TradeStation to receive real-time data only.
              Historical data cannot be received through the External data feed.
              This means you cannot use the External data feed to download historical data to use for backtesting.

              If you would like intra-day data you will need to subscribe to a data provider.
              Below is a link to the help guide on Historical & Real-Time Data. In the section 'Understanding the data provided by your connectivity provider' there is a chart that show the supported connection technologies and the types of data these connections support.

              Also here is a publicly available link to a list of the supported brokers with the NinjaTrader Platform.

              Last, here is a link to our Connections Guide which will have instructions to setup the provider in NinjaTrader (scroll to the bottom).

              When backtesting Calculate on bar close is always True.
              If you do not have intra-bar granularity added to your script, this means that orders will only be submitted as a bar closes.

              When NinjaTrader is running with Calculate on bar close (COBC) as true, orders are placed after the bar closes using logic calculated from that bar.

              Below is a link to the help guide on Calculate on bar close.

              This means that any orders that are triggered from that bar are submitted after the bar closes as the new bar opens. As the order is placed as the new bar opens and the timestamp of the order is within the time of the next bar, the order will show on the next bar.

              If the strategy were running with COBC as false, or if the script has intra-bar granularity and submitted orders on a smaller timeframe, this would cause the timestamp of the order to be within the bar it is triggered on as the order may be submitted intra-bar. This order would show on the same bar as the bar that triggered the order submission.

              This is outlined in the help guide Discrepancies: Real-Time vs Backtest.

              Regarding the Position.MarketPosition property, this will change after the position changes.
              Do you have prints in your script to demonstrate than an order has filled and the value of the Position.MarketPosition has not changed?

              As a tip, the position will not be updated until the order goes through accepted, working, and then filled. This means it will not be updated immediately after the order is placed is OnBarUpdate. You have to wait until OnPositionUpdate has triggered updating the position. The position should be updated by the time the next bar update.
              Chelsea B.NinjaTrader Customer Service


                DonchianChannel and EMA Cross

                Hello again!

                I have come a long way now with Unmanaged code and everything is working very well with the DonchianChannel/EMA-Cross Breakout strategy.
                But I have a situation when I hit the upper DochianChannel and the bar is at the same time crossing the EMA from from above which creates triggers that I don´t want.
                If there is a hit on the upper DC I would like to ignore the EMA crossbelow hit.
                Does anyone understand what I am trying to explain?

                Kind Regards


                  Hello Kennet,

                  You can explicitly add this as a condition to your branching command.

                  For example:

                  if (Close[0] < DonchianChannel(14).Upper[0] && CrossAbove(EMA(7), EMA(14), 1))

                  This would require that the Close be less than the DonchianChannel upper line when the crossabove occurs.
                  Chelsea B.NinjaTrader Customer Service


                    Thank you very much Chelsea!
                    Are there any implications if running OnBarClose or OnTick?
                    Kind Regards


                      Hello Kennet,

                      Yes, in NinjaTrader 7 when running with CalculateOnBarClose as true, the script will update once when the bar closes. You would only be able to detect one cross per bar.

                      When CalculateOnBarClose is false, OnBarUpdate will update on every tick. This means you can get multiple crosses per bar if the series fluctuate and cross and uncross several times in the same bar.

                      Below is a link to the help guide on CalculateOnBarClose.
                      Chelsea B.NinjaTrader Customer Service


                      Latest Posts


                      Topics Statistics Last Post
                      Started by superkolleech, Today, 12:46 AM
                      1 response
                      Last Post MojoJojo  
                      Started by davidwade, Today, 02:51 AM
                      0 responses
                      Last Post davidwade  
                      Started by aviat72, 04-26-2020, 09:41 PM
                      10 responses
                      Last Post kissandfly  
                      Started by healthooa, Today, 01:28 AM
                      0 responses
                      Last Post healthooa  
                      Started by harjinderjit, Yesterday, 08:24 PM
                      0 responses
                      Last Post harjinderjit