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

Basic Donchian Channel Breakout

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

    Basic Donchian Channel Breakout

    I have read the thread on May 2011 about a basic Donchian Channel Breakout to create in the Strategy Wizard... I see the code that you wrote but all I am trying to do is set an alarm when the price goes above or below a certain number of ticks of previous bar... seems simple but I have spent several weeks on this now and might be close but can't get it to work... I have setup a Ninjascript strategy and it looks good on chart but no alert... any help will be appreciated... thanks


    #2
    Hello,

    Thanks for the forum post.

    Can you please post the script you have tried to create to make this work and then I will offer advice to point you in right direction to get this done.

    I look forward to assisting you further.

    Comment


      #3
      thanks...I had to delete some
      thanks...I had to delete some
      ///<summary>
      /// Donchian channel alert
      ///</summary>
      [Description("Donchian channel alert")]
      publicclass Donchianchannelalert : Strategy
      {
      #region Variables
      // Wizard generated variables
      privateint myInput0 = 1; // Default setting for MyInput0
      // User defined variables (add any user defined variables below)
      #endregion
      ///<summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      ///</summary>
      protectedoverridevoid Initialize()
      {
      Add(DonchianChannel(1));
      Add(DonchianChannel(1));
      CalculateOnBarClose = false;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (CrossBelow(DonchianChannel(1).Upper, DonchianChannel(1).Lower, 1))
      {
      Alert("MyAlert0", Priority.High, "Donchian Channel Alert", @"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert1.wav", 10, Color.White, Color.Black);
      }
      }
      #region Properties
      [Description("")]
      [GridCategory("Parameters")]
      publicint MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(0, value); }
      }
      #endregion

      Comment


        #4
        Hello,

        It is not possible for a doncian channel lower line to cross a doncian channel upper line is it? Expecially with a period of 1?

        I look forward to assisting you further.

        Comment


          #5
          You have this as your evaluation condition.

          if (CrossBelow(DonchianChannel(1).Upper, DonchianChannel(1).Lower, 1))
          1. By the definition of a channel of any kind, the channel lower line can never cross the channel upper line.
          2. Your channel length of 1 is equivalent to price, so in effect you are actually asking for when the High of the bar crosses below the Low of the bar.


          What it means is that your condition can never be triggered.

          Maybe if you stated in words what you are trying to code, we might be able to supply a snippet?

          Comment


            #6
            Thanks... I will try and fix that and see what happens... what I am trying to accomplish is that if the price goes 5 ticks above the previous bar... or goes 5 ticks below the previous bar... it will set off an alert... seems the Donchian Channel is the best indicator showing the high and low of the previous bar.

            Comment


              #7
              Originally posted by chuckmorman3 View Post
              Thanks... I will try and fix that and see what happens... what I am trying to accomplish is that if the price goes 5 ticks above the previous bar... or goes 5 ticks below the previous bar... it will set off an alert... seems the Donchian Channel is the best indicator showing the high and low of the previous bar.
              5 ticks above the previous bar:

              Code:
              if (High[0] >= High[1] + (5 * TickSize))
              {
              // do something
              }
              5 ticks below previous bar

              Code:
              if (Low[0] <= Low[1] - (5 * TickSize))
              {
              // do something
              }
              Using the Donchian Channel to get the High and Low of a bar, when you can reference the same directly is kind of doing unecessary calculations, and not very efficient. Technically, it is not wrong. It just seems like a lot of extra work that may not be needed.

              Comment


                #8
                This is the first time I have tried using NinjaScript... I am now watching the chart and placing orders accordingly... and alert would be very helpful so if there is an easier way please inform me... thank you for your help

                This is the code I have tried without an offset

                #regionUsingdeclarations
                usingSystem;
                usingSystem.ComponentModel;
                usingSystem.Diagnostics;
                usingSystem.Drawing;
                usingSystem.Drawing.Drawing2D;
                usingSystem.Xml.Serialization;
                usingNinjaTrader.Cbi;
                usingNinjaTrader.Data;
                usingNinjaTrader.Indicator;
                usingNinjaTrader.Gui.Chart;
                usingNinjaTrader.Strategy;
                #endregion

                //Thisnamespaceholdsallstrategiesandisrequired.Donot changeit.
                namespaceNinjaTrader.Strategy
                {
                ///<summary>
                ///abovepreviousbar
                ///</summary>
                [Description("abovepreviousbar")]
                publicclassAbovepreviousbar:Strategy
                {
                #regionVariables
                //Wizardgeneratedvariables
                privateintmyInput0=1;//DefaultsettingforMyInput0
                //Userdefinedvariables(addanyuserdefinedvariablesbel ow)
                #endregion

                ///<summary>
                ///Thismethodisusedtoconfigurethestrategyandiscalledo ncebeforeanystrategymethodiscalled.
                ///</summary>
                protectedoverridevoidInitialize()
                {
                CalculateOnBarClose=false;
                }

                ///<summary>
                ///Calledoneachbarupdateevent(incomingtick)
                ///</summary>
                protectedoverridevoidOnBarUpdate()
                {
                //Conditionset1
                if(GetCurrentAsk()>=HighestBar(DefaultInput,1)
                &&GetCurrentAsk()<=LowestBar(DefaultInput,1))
                {
                Alert("MyAlert2",Priority.High,"hilowalert",@"C:\P rogramFiles(x86)\NinjaTrader7\sounds\Alert1.wav",1 0,Color.White,Color.Black);
                }
                }

                #regionProperties
                [Description("")]
                [GridCategory("Parameters")]
                publicintMyInput0
                {
                get{returnmyInput0;}
                set{myInput0=Math.Max(1,value);}
                }
                #endregion
                }
                }

                #regionWizardsettings,neitherchangenorremove

                Last edited by chuckmorman3; 07-22-2011, 02:45 PM.

                Comment


                  #9
                  chuckmorman, that is how an alert is placed. There isn't any easier way to do it. Are you having troubles with the code you posted? If so, what sort of trouble?
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    It really has little to do with NinjaScript, and everything to do with your code logic. No matter the language, if your conditions never trigger, then your alert will not trigger either.

                    I am not sure that I know what you are seeking now. The response to which you replied translated your conditions into NinjaScript for you. Are you posting this other code because you want to use the Ask price rather than the historical prices of the last bar that closed?

                    If you breakdown the logic of your code, you will see that you have specified an impossible condition. Nothing can both be greater than the high and simultaneously less than the low; which is what you have coded. The dual equality condition means that your alert can only be triggered if the last bar is a doji and the Ask price hits the closing price of said doji.
                    Last edited by koganam; 07-25-2011, 06:46 PM.

                    Comment


                      #11
                      Could you please send your alert to me - I see the value in this but am very new to Ninja and don't understand the coding yet.

                      Thanks,
                      Neil

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by ghoul, Today, 06:02 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post ghoul
                      by ghoul
                       
                      Started by Barry Milan, Yesterday, 10:35 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post Barry Milan  
                      Started by DanielSanMartin, Yesterday, 02:37 PM
                      2 responses
                      13 views
                      0 likes
                      Last Post DanielSanMartin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      4 responses
                      13 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by terofs, Today, 04:18 PM
                      0 responses
                      12 views
                      0 likes
                      Last Post terofs
                      by terofs
                       
                      Working...
                      X