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

Directional.

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

    Directional.

    Hey Everyone,

    I was wondering if anyone knew how to only have one buy or sell indicator drawing per direction.

    I have about seven buy signals but I don't want them to keep firing-off all the way up, it's useless for them to do that. I want a buy signal then no other buy signals until after a sell signal(of which I have six) and also the other way around. Anyone know how to program this?

    There's a small hitch though. Some indicators signal at the same time. So I want it to be ok with doing that(counting them both as one signal so as not to cancel any) and then following with the rules asked for above.
    Last edited by Drakmyre; 10-23-2008, 08:49 PM.

    #2
    Hi Drakmyre,

    I am not sure what signal you are referring to? Are you mentioning the NinjaTrader's visual for plotting trades? If you are referring to those unfortunately there is no way to limit it down to the last one only. It is either all of them or none of them.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      I'll include a picture in this post. I just want one sell or buy symbol per direction. If it's sell, I don't want any other sell signals until after a buy signal and vice versa.

      Comment


        #4
        You would have to include a variable in your programming logic, something like:

        private doNotDrawLong = false;


        in OnBarUpdate()

        Code:
        if (longCondition == true)
        {
            if (doNotDrawLong == false)
            {        
                //Signal marker here
                doNotDrawLong == true;
            }
        }
         
        if (Position.MarketPosition == MarketPosition.Short)
            doNotDrawLong = false;
        RayNinjaTrader Customer Service

        Comment


          #5
          Code so far.

          Hey Josh and Ray,

          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class ADXMix : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int 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>
          protected override void Initialize()
          {

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Rising(ZeroLagMACD(12, 26, 9)) == true
          && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
          && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
          {
          DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
          }

          // Condition set 2
          if (CrossAbove(RSI(14, 3).Avg, RSI(14, 3), 1)
          && Falling(ZeroLagMACD(12, 26, 9).Avg) == true
          && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
          {
          DrawDot("My dot" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Magenta);
          }

          // Condition set 3
          if (CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3), 1)
          && CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3).Avg, 1)
          && Leader(12, 26)[0] > ZeroLagMACD(12, 26, 9)[0]
          && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Teeth[0])
          {
          DrawDiamond("My diamond" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
          }

          // Condition set 4
          if (CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3), 1)
          && CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3).Avg, 1)
          && ZeroLagMACD(12, 26, 8).Avg[0] >= Leader(12, 26)[0]
          && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
          {
          DrawDiamond("My diamond" + CurrentBar, false, 2, High[0] + 1 * TickSize, Color.Magenta);
          }

          // Condition set 5
          if (CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3), 1)
          && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Teeth[0])
          {
          DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
          }

          // Condition set 6



          if (CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3), 1)
          && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
          {{{
          DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Magenta);
          }}}}}}



          if (longCondition == true)
          {
          if (doNotDrawLong == false)
          {
          //Signal marker here
          doNotDrawLong == true;
          }
          }

          if (Position.MarketPosition == MarketPosition.Short)
          doNotDrawLong = false;
          }

          That's the code so far.

          Ray and Josh: the two errors are Namespace member declaration expected and a namespace does not contain members such as fields or methods.
          Last edited by Drakmyre; 10-26-2008, 01:39 AM.

          Comment


            #6
            Drakmyre,

            The code Ray suggested is suppose to be placed inside your condition sets and not as a separate set. So for instance:

            You have:
            Code:
            // Condition set 1
            if (Rising(ZeroLagMACD(12, 26, 9)) == true
                && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
               && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
            {
                 DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
            }
            Should be:
            Code:
            // Condition set 1
            if (Rising(ZeroLagMACD(12, 26, 9)) == true
                && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
                && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
            {
                 if (doNotDrawLong == false)
                 {
                      doNotDrawLong = true;
                      DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
                 }
            }
            
            // This resets the limiting bool of doNotDrawLong.
            if (Position.MarketPosition == MarketPosition.Short)
                  doNotDrawLong = false;
            You need to do this for every corresponding set. You don't have to copy the resetting part over and over though, just the if (doNotDrawlong...) part.

            Do not forget you need to first create this variable in the Variables section of the code too.
            Code:
            private bool doNotDrawLong = false;
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh,

              Awesome! I got it to compile but when it charts there are signals firing-off every bar. Is there something I did not do?

              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
              /// <summary>
              /// Enter the description of your strategy here
              /// </summary>
              [Description("Enter the description of your strategy here")]
              public class ADXMix : Strategy
              {
              #region Variables
              // Wizard generated variables
              private int myInput0 = 1; // Default setting for MyInput0
              private bool doNotDrawLong = false;
              // 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>
              protected override void Initialize()
              {

              CalculateOnBarClose = true;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()

              {
              // Condition set 1
              if (Rising(ZeroLagMACD(12, 26, 9)) == true
              && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
              && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
              {
              if (doNotDrawLong == false)
              {
              doNotDrawLong = true;
              DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
              }
              }

              // Condition set 2
              if (CrossAbove(RSI(14, 3).Avg, RSI(14, 3), 1)
              && Falling(ZeroLagMACD(12, 26, 9).Avg) == true
              && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
              {
              if (Position.MarketPosition == MarketPosition.Short)
              doNotDrawLong = false;
              DrawDot("My dot" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Magenta);
              }
              // Condition set 3
              if (CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3), 1)
              && CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3).Avg, 1)
              && Leader(12, 26)[0] > ZeroLagMACD(12, 26, 9)[0]
              && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Teeth[0])
              {
              if (doNotDrawLong == false)
              {
              doNotDrawLong = true;}

              DrawDiamond("My diamond" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
              }

              // Condition set 4
              if (CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3), 1)
              && CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3).Avg, 1)
              && ZeroLagMACD(12, 26, 8).Avg[0] >= Leader(12, 26)[0]
              && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])

              if (Position.MarketPosition == MarketPosition.Short)
              doNotDrawLong = false;

              {
              DrawDiamond("My diamond" + CurrentBar, false, 2, High[0] + 1 * TickSize, Color.Magenta);
              }

              // Condition set 5
              if (CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3), 1)
              && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Teeth[0])
              if (doNotDrawLong == false)
              {
              doNotDrawLong = true;}

              {
              DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
              }

              // Condition set 6



              if (CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3), 1)
              && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
              if (Position.MarketPosition == MarketPosition.Short)
              doNotDrawLong = false;

              {{{
              DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Magenta);
              }}}}}}
              Last edited by Drakmyre; 10-28-2008, 02:01 PM. Reason: Additonal information

              Comment


                #8
                If it is drawing every bar then your condition is evaluating to true every bar. You will need to reevaluate your conditions and see what is happening. Try printing out all the values and running the comparisons by hand for several bars. Then you can make the changes you need.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Almost there!

                  Josh and Ray,

                  Here is the code. It works, compiles and does not fill the graph. Now there's one last correction. I combined the codes from three files: the ADX Mix file from before and one buy signal set and one sell with four indicators in each. Grand total, fourteen. Yeah, I like a challenge. .

                  So would I just do what I did last time and copy and paste the code you gave before. The reason for all the rules is sometimes one set works and sometimes another.

                  #region Using declarations
                  using System;
                  using System.ComponentModel;
                  using System.Diagnostics;
                  using System.Drawing;
                  using System.Drawing.Drawing2D;
                  using System.Xml.Serialization;
                  using NinjaTrader.Cbi;
                  using NinjaTrader.Data;
                  using NinjaTrader.Indicator;
                  using NinjaTrader.Gui.Chart;
                  using NinjaTrader.Strategy;
                  #endregion
                  // This namespace holds all strategies and is required. Do not change it.
                  namespace NinjaTrader.Strategy
                  {
                  /// <summary>
                  /// Enter the description of your strategy here
                  /// </summary>
                  [Description("Enter the description of your strategy here")]
                  public class ADXMix : Strategy
                  {
                  #region Variables
                  // Wizard generated variables
                  private int myInput0 = 1; // Default setting for MyInput0
                  private bool doNotDrawLong = false;
                  // 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>
                  protected override void Initialize()
                  {

                  CalculateOnBarClose = true;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()

                  {
                  // Condition set 1
                  if (Rising(ZeroLagMACD(12, 26, 9)) == true
                  && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
                  && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
                  { DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
                  doNotDrawLong = true;
                  if (doNotDrawLong == false)
                  {


                  }
                  }

                  // Condition set 2
                  if (CrossAbove(RSI(14, 3).Avg, RSI(14, 3), 1)
                  && Falling(ZeroLagMACD(12, 26, 9).Avg) == true
                  && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
                  {DrawDot("My dot" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Magenta);
                  doNotDrawLong = false;
                  if (doNotDrawLong == false);


                  }
                  // Condition set 3
                  if (CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3), 1)
                  && CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3).Avg, 1)
                  && Leader(12, 26)[0] > ZeroLagMACD(12, 26, 9)[0]
                  && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Teeth[0])
                  {DrawDiamond("My diamond" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
                  doNotDrawLong = true;}
                  if (doNotDrawLong == false)
                  {



                  }

                  // Condition set 4
                  if (CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3), 1)
                  && CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3).Avg, 1)
                  && ZeroLagMACD(12, 26, 8).Avg[0] >= Leader(12, 26)[0]
                  && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
                  DrawDiamond("My diamond" + CurrentBar, false, 2, High[0] + 1 * TickSize, Color.Magenta);
                  doNotDrawLong = false;
                  if (doNotDrawLong == false)


                  {
                  ;
                  }

                  // Condition set 5
                  if (CrossAbove(ARSI(14).ARSIPlot, RSI(14, 3), 1)
                  && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Teeth[0])
                  DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
                  {doNotDrawLong = true;}

                  if (doNotDrawLong == false)


                  {

                  }

                  // Condition set 6



                  if (CrossBelow(ARSI(14).ARSIPlot, RSI(14, 3), 1)
                  && ZeroLagTEMA(14).ZeroTEMA[0] <= Alligator().Jaw[0])
                  DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Magenta);
                  doNotDrawLong = false;
                  if (doNotDrawLong == false);

                  // Condition set 7
                  if (CrossAbove(ZeroLagEMA(5).ZLEMA, ZeroLagEMA(8).ZLEMA, 1)
                  && CrossAbove(DM(3).DiPlus, DM(3).DiMinus, 1)
                  && ZeroLagTEMA(8).ZeroTEMA[0] > Alligator().Jaw[0])
                  DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Lime);
                  { doNotDrawLong = true;
                  if (doNotDrawLong == false);







                  }

                  // Condition set 8
                  if (Rising(ARSI(21).ARSIPlot) == true
                  && CrossAbove(ZeroLagMACD(12, 26, 9), ZeroLagMACD(12, 26, 9).Avg, 1)
                  && ZeroLagTEMA(8).ZeroTEMA[0] > Alligator().Teeth[0])

                  DrawDiamond("My diamond" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Lime);
                  { doNotDrawLong = true;
                  if (doNotDrawLong == false);
                  }

                  // Condition set 9
                  if (Rising(AC().ACValue) == true
                  && Rising(ZeroLagEMA(21).ZLEMA) == true
                  && CrossBelow(PremierStochastic(25, 8).Positive, 0.2, 1)
                  && ZeroLagTEMA(8).ZeroTEMA[0] > Alligator().Teeth[0])
                  DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Lime);
                  { doNotDrawLong = true;
                  if (doNotDrawLong == false);

                  }

                  // Condition set 10
                  if (Rising(Leader(12, 26)) == true
                  && Rising(ZeroLagMACD(12, 26, 9).Avg) == true
                  && Rising(ARSI(14).ARSIPlot) == true
                  && Leader(12, 26)[0] > ZeroLagMACD(12, 26, 9).Avg[0]
                  && CrossAbove(ZeroLagTEMA(14).ZeroTEMA, Alligator().Teeth, 1))
                  DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Lime);
                  { doNotDrawLong = true;
                  if (doNotDrawLong == false);

                  }
                  // Condition set 11
                  if (Falling(ZeroLagEMA(21).ZLEMA) == true
                  && Falling(AC().ACValue) == true
                  && CrossAbove(PremierStochastic(25, 8).Positive, 0.2, 1)
                  && Low[0] < Alligator().Lips[0])
                  DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
                  {
                  doNotDrawLong = true;
                  if (doNotDrawLong == false);



                  }

                  // Condition set 12
                  if (CrossBelow(ZeroLagEMA(5).ZLEMA, ZeroLagEMA(8).ZLEMA, 1)
                  && CrossAbove(DM(3).DiMinus, DM(3).DiPlus, 1)
                  && Low[0] < Alligator().Lips[0])
                  { DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
                  doNotDrawLong = true;
                  if (doNotDrawLong == false);

                  }

                  // Condition set 13
                  if (CrossBelow(ZeroLagMACD(12, 26, 9), ZeroLagMACD(12, 26, 9).Avg, 1)
                  && Falling(ARSI(21).ARSIPlot) == true
                  && Low[0] < Alligator().Lips[0])
                  DrawDiamond("My diamond" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
                  { doNotDrawLong = true;
                  if (doNotDrawLong == false);

                  }

                  // Condition set 14
                  if (Falling(ADX(14)) == true
                  && Close[0] > Bollinger(2, 14).Middle[0] + 8 * TickSize
                  && KeyReversalDown(1)[0] == 1)
                  DrawDot("My dot" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
                  { doNotDrawLong = true;
                  if (doNotDrawLong == false);


                  }




                  {{{

                  }}}}}}

                  Included is a picture. Red and Magenta are sell colors.

                  By the way, thanks so much for the help! I really am starting to get what you're talking about. It took me a few hours to get this far but it would have been worse without your help!

                  Comment


                    #10
                    Drakmyre,

                    You're welcome. If you are copy pasting just make sure you are copy pasting the right sections into the right places. It is generally better to just copy what is inside the various Initialize() and OnBarUpdate() methods instead of selecting the whole thing.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Josh,

                      From what it looks like indicators 1-6 are working fine. 7-14 seem to be working separately but correctly from 1-6. Any idea what's happening?

                      Comment


                        #12
                        Unfortunately not Drakmyre. You already have the general gist of it. All you need to do now is slowly debug out your code. Please check out this tip on a methodical way to do so: http://www.ninjatrader-support.com/v...ead.php?t=3418
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hey Josh,

                          I noticed something. It does what we talked about but kinda differently. It only displays buy on upward prices or upward changes in price and vice-versa. So, in effect, we're most of the way there. Just thought I'd bring that up.

                          Comment


                            #14
                            Drakmyre,

                            Your code is maybe wrong.

                            This is what you have:
                            Code:
                            // Condition set 1
                            if (Rising(ZeroLagMACD(12, 26, 9)) == true
                                && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
                                && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
                            {
                                  DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);
                                  doNotDrawLong = true;
                                  if (doNotDrawLong == false)
                                  {
                            
                            
                                  }
                            }
                            Your doNotDrawLong should be set to true after you are inside the if-statement for doNotDrawLong. You also have no logic inside that if-statement so it is essentially not doing anything for you.
                            Please see the difference here:
                            Code:
                            // Condition set 1
                            if (Rising(ZeroLagMACD(12, 26, 9)) == true
                                && CrossAbove(RSI(14, 3), RSI(14, 3).Avg, 1)
                                && ZeroLagTEMA(3).ZeroTEMA[0] >= Alligator().Jaw[0])
                            {
                                  if (doNotDrawLong == false)
                                  {
                                       [B][COLOR=Red]doNotDrawLong = true;
                                       DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Green);[/COLOR][/B]
                                  }
                            }
                            This applies to all of your conditions.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Range.

                              Josh,

                              I found something strange. The code seems to work extremely well and accurately when prices are in a range and not moving much.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              26 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              2 responses
                              49 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Kensonprib, 04-28-2021, 10:11 AM
                              5 responses
                              192 views
                              0 likes
                              Last Post Hasadafa  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,234 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X