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

Donchian Channel Strategy

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

    Donchian Channel Strategy

    Hello!
    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.
    Kennet

    #2
    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

    Comment


      #3
      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:
      Kennet

      Comment


        #4
        Hello,

        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

        Comment


          #5
          I am using external feed and backtesting.
          Kennet

          Comment


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

            Kennet

            Comment


              #7
              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.
              NinjaTrader provides online access to the futures, forex and equities markets through online brokers including NinjaTrader Brokerage.


              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

              Comment


                #8
                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
                Kennet

                Comment


                  #9
                  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

                  Comment


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

                    Comment


                      #11
                      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

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by MarianApalaghiei, Today, 10:49 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by love2code2trade, Yesterday, 01:45 PM
                      4 responses
                      28 views
                      0 likes
                      Last Post love2code2trade  
                      Started by funk10101, Today, 09:43 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post funk10101  
                      Started by pkefal, 04-11-2024, 07:39 AM
                      11 responses
                      37 views
                      0 likes
                      Last Post jeronymite  
                      Started by bill2023, Yesterday, 08:51 AM
                      8 responses
                      45 views
                      0 likes
                      Last Post bill2023  
                      Working...
                      X