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

Hma rising and falling arrows

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

    #16
    DJ, yes the strategy would cover you normally against those issues (BarsRequired 'pause' unitl OnBarUpdate() is called) - for indicators you want to add the check Ryan outlined at the OnBarUpdate() start to ensure you don't try to access bars that are not available right at the start of the chart.
    BertrandNinjaTrader Customer Service

    Comment


      #17
      Strategy to Indicator Transfer issues

      Hi Bertrand, I tried this piece and put it at onbarupdate but still doesn't work as follows (bolded the attached piece although compiles ok). What should happen is arrows should show up in the right places same as the strategy. I have also attached the entire code. This works on a strategy so I was wondering if there is something in the code when transferred from a strategy to an indicator causes it not to work. I also copied all the wizard bits at the bottom of the strategy so not sure if that is needed or not. I have about 10 different strategies that I'd like to make indicators so I don't have to start them up each time so once I know how to do one all should work ok. Thanks. DJ

      // <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      {if (CurrentBar < 1)
      return;
      }

      // Condition set 1
      if (HMA(H1)[0] < HMA(H1)[1]
      && HMA(H1)[1] > HMA(H1)[2]
      && EMA(EMA1)[0] < EMA(EMA2)[0]
      && EMA(EMA2)[0] < EMA(EMA3)[0])
      {
      DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 15 * TickSize, Color.Yellow);
      }
      Attached Files
      Last edited by djkiwi; 09-15-2010, 02:40 PM. Reason: error

      Comment


        #18
        Hello djkiwi,

        Sorry for not catching this initially, but it looks like you are accessing index values 2 bars back, so the 1 bar check isn't sufficient. Strategy logic uses a default value of 20 (MinimumBarsRequired).

        You can probably use a value of 20 and not notice any difference. It just means there won't be indicator processing for the first 20 bars.

        if (CurrentBar < 20)
        return;

        Let us know if you're still having issues with this.
        Ryan M.NinjaTrader Customer Service

        Comment


          #19
          Thanks for the help guys that worked well perfectly. I have another one I'm grappling with as well I'd be grateful if you could provide some pointers. What I am doing is triggering a sound alert once the tick hits 800 or 900 or 1000 etc. Example is below so it gives a sound alert each time the tick exceeds the value. I did it this way because that's all I could figure out how to do it with limited knowledge.

          What I'd really like to do though is trigger the alert every time the tick increases 100 or decreases 100 from a base of 100. So if the tick is 600 and it hits say 740 then it should alert, alternatively if it then hits 800 it should alert again because it has increased over the threshold of 100. I'd like to do it this way because I'd like to apply this to other instruments as well by just changing the 100 threshold and without have to specify the value triggers each time which is proving to be very time consuming. Any help on this one would be appreciated. Thanks. DJ


          // Condition set 7
          if (CrossAbove(Close, 1000, 1))
          {
          Alert("MyAlert1134", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick 1000.wav", 10, Color.White, Color.Black);
          }

          // Condition set 8
          if (CrossBelow(Close, -1000, 1))
          {
          Alert("MyAlert1132", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick -1000.wav", 5, Color.White, Color.Black);
          }

          // Condition set 9
          if (CrossAbove(Close, 900, 1))

          {
          Alert("MyAlert49", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick 900.wav", 10, Color.White, Color.Black);
          }

          // Condition set 10
          if (CrossBelow(Close, -900, 1))

          {
          Alert("MyAlert49", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick -900.wav", 10, Color.White, Color.Black);
          }

          Comment


            #20
            djkiwi,

            To clarify, when you say tick you mean the latest price? When you say 800, 900, etc. you mean price becomes that?

            So you are trading an instrument where it is possible to move 100 pts. fairly easily?

            What you need to do is define out a starting point for the value you are at. Perhaps the opening price of the day. Then you can just add 100 on top of that for your alert price. When the alert is triggered, change the alert price to reflect the new price afterwards.

            Untested code to give you some hints
            Code:
            if (FirstTickOfBar && Bars.FirstBarOfSession)
            {
                 alertPriceUp = Close[0] + 100;
                 alertPriceDown = Close[0] - 100;
            }
            
            if (CrossAbove(Close, alertPriceUp, 1))
            {
                 Alert(...);
                 alertPriceUp = Close[0] + 100;
            }
            
            if (CrossBelow(Close, alertPriceDown, 1))
            {
                 Alert(...);
                 alertPriceDown = Close[0] - 100;
            }
            Josh P.NinjaTrader Customer Service

            Comment


              #21
              Price change

              Thaks Josh, well I tried this one and get an error that te alertpriceup does not exist in the current context. I then tried to define it in variables using private int = alert price up and got another error. Have I put something in the wrong place? Thanks. DJ

              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              [Description("Enter the description of your new custom indicator here")]
              public class djpricechange : Indicator
              {
              #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 indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
              Overlay = false;
              }
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              if (FirstTickOfBar && Bars.FirstBarOfSession)
              {
              alertPriceUp = Close[0] + 100;
              alertPriceDown = Close[0] - 100;
              }
              if (CrossAbove(Close, alertPriceUp, 1))
              {
              Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick 1300.wav", 10, Color.White, Color.Black);
              alertPriceUp = Close[0] + 100;
              }
              if (CrossBelow(Close, alertPriceDown, 1))
              {
              Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick -1300.wav", 10, Color.White, Color.Black);
              alertPriceDown = Close[0] - 100;
              }
              }

              Comment


                #22
                Hello,

                You need to add a variable declartion for both alertPriceUp and alertPriceDown. In the #region Variables.

                Best to use doubles here since your dealing with price.

                double alertPriceUp = 0;
                double alertPriceDown =0;

                Let me know if I can be of further assistance.

                Comment


                  #23
                  Indicator nearly works

                  Hi Brett, thanks for that input. It got rid of the compile error and this is working but not entirely correctly. I have enclosed a chart so you can see what I'm trying to achieve. I can see the problem now. So if you look at the chart you can see the signals (via partially obscured arrow heads) in the first half hour trading as it fell the required 100. Then at 7.14 am another signal as it fell another 100 to -817 then another at 10.40 am as it ht -917. Then another signal was triggered at 11.36 am. This triggered because it was above the very first one of the day.

                  So what I'm trying to achieve is that the 100 is triggered when it moves up OR down from the last signal. So in this case at 7.10 am when there was a trigger at 6.42 am of about -707 there should have been a signal at 6.46 am as it rose 100.

                  So I'm guessing the first issue is the first line of the code:

                  if (FirstTickOfBar && Bars.FirstBarOfSession).

                  Do you see the problem now? Thanks. DJ

                  PS: I just thought the fact this Symbol has negative numbers which maybe causing some issue.

                  Code attached:

                  /// <summary>
                  /// Enter the description of your new custom indicator here
                  /// </summary>
                  [Description("Enter the description of your new custom indicator here")]
                  public class djpricechange : Indicator
                  {
                  #region Variables
                  // Wizard generated variables
                  private int myInput0 = 1; // Default setting for MyInput0
                  // User defined variables (add any user defined variables below)
                  double alertPriceUp = 0;
                  double alertPriceDown =0;


                  #endregion

                  /// <summary>
                  /// This method is used to configure the indicator and is called once before any bar data is loaded.
                  /// </summary>
                  protected override void Initialize()
                  {
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                  Overlay = false;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  if (FirstTickOfBar && Bars.FirstBarOfSession)
                  {
                  alertPriceUp = Close[0] + 100;
                  alertPriceDown = Close[0] - 100;
                  }

                  if (CrossAbove(Close, alertPriceUp, 1))
                  {
                  Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick 1300.wav", 10, Color.White, Color.Black);
                  DrawArrowDown("My down arrow" + CurrentBar, false, 0, Close[0] + 20 * TickSize, Color.Red);
                  alertPriceUp = Close[0] + 100;
                  }

                  if (CrossBelow(Close, alertPriceDown, 1))
                  {
                  Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick -1300.wav", 10, Color.White, Color.Black);
                  alertPriceDown = Close[0] - 100;
                  DrawArrowDown("My down arrow" + CurrentBar, false, 0, Close[0] + 20 * TickSize, Color.Red);
                  }
                  }

                  #region Properties
                  [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                  public DataSeries Plot0
                  {
                  get { return Values[0]; }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int MyInput0
                  {
                  get { return myInput0; }
                  set { myInput0 = Math.Max(1, value); }
                  }
                  #endregion
                  }
                  }
                  Attached Files
                  Last edited by djkiwi; 09-21-2010, 05:41 PM.

                  Comment


                    #24
                    DJ, I suggest you add prints throughout your code to check what values are calculated by your indicator so you can compare and deduct where it does not return as you would expect - the FirstTickOfBar would only be of value if running in realtime or Market Replay with CalculateOnBarClose = false.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #25
                      Hi Bertrand, still struggling with this one. I am trying to add the print command although am getting an error. I assume this prints an "up" or "down" on the chart when the condition is met? Please correct me if I'm wrong. Anyway the problem is it says the 'printwithtimestamp' does not exist in the current context. I copied this in from code produced by the strategy wizard and seems to work ok in the wizard but when I copy it to unlocked program shows an error. Please see code below. Thanks. DJ

                      PrintWithTimeStamp("UP");
                      PrintWithTimeStamp("DOWN");

                      [Description("Enter the description of your new custom indicator here")]
                      public class djpricechange : Indicator
                      {
                      #region Variables
                      // Wizard generated variables
                      private int myInput0 = 1; // Default setting for MyInput0
                      // User defined variables (add any user defined variables below)
                      double alertPriceUp = 0;
                      double alertPriceDown =0;


                      #endregion

                      /// <summary>
                      /// This method is used to configure the indicator and is called once before any bar data is loaded.
                      /// </summary>
                      protected override void Initialize()
                      {
                      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                      Overlay = false;
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      if (FirstTickOfBar && Bars.FirstBarOfSession)
                      {
                      alertPriceUp = Close[0] + 100;
                      alertPriceDown = Close[0] - 100;
                      }

                      if (CrossAbove(Close, alertPriceUp, 1))
                      {
                      Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick 1300.wav", 10, Color.White, Color.Black);
                      DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -15 * TickSize, Color.Yellow);
                      alertPriceUp = Close[0] + 100;
                      PrintWithTimeStamp("UP");
                      }

                      if (CrossBelow(Close, alertPriceDown, 1))
                      {
                      Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick -1300.wav", 10, Color.White, Color.Black);
                      DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 15 * TickSize, Color.Yellow);
                      alertPriceDown = Close[0] - 100;
                      PrintWithTimeStamp("DOWN");

                      }

                      Comment


                        #26
                        DJ, the Print() command prints to the output window (Tools -> Output Window), not to the chart. What is the error you are receiving?
                        AustinNinjaTrader Customer Service

                        Comment


                          #27
                          Error

                          Hi Austin, the error is CS0103 and says:

                          PrintWithTimeStamp("UP") does not exist in the current context.

                          What I'm try to show is the actual value. It's hard to explain at this point. So instead of UP what would I put in something like:

                          PrintWithTimeStamp(Close[0]);

                          That had same error.

                          So not really sure how to use this print command. So what happens here is when the the price increases by 100 then it should give an alert and then when it decreases by 100 it should give another alert. It seems to work sometimes but there is a problem. Bertrand suggested putting in this print command to test the values coming through. So help with this print command would be appreciated. Thanks. DJ

                          Comment


                            #28
                            DJ, please just use Print() to print out all the information, like this:
                            Code:
                            // this will print out the bar's timestamp, close price, and some text at the end
                            Print(Time[0].ToString() + " " + Close[0] + " " + "some text here at the end");
                            AustinNinjaTrader Customer Service

                            Comment


                              #29
                              Results

                              Thanks Austin, that worked well. Ok, so what this code should do is give an alert each time the amount moves +100 or -100 using the last amount as the base. So what it is actually doing is moving up ok (as per this example) BUT will not alert when it moves down 100. It only alerts the -100 (See-924 below) when the the amount down exceeds the lowest amount posted in this case it was at the open (around -820). See attached graph. Also the next -100 recorded was at 7.48 am. I have posted the code below as well so you can see what is going on. Any ideas on this one would be appreciated. Thanks. DJ

                              10/4/2010 6:34:00 AM -592 some text here at the end
                              10/4/2010 6:36:00 AM -467 some text here at the end
                              10/4/2010 6:40:00 AM -352 some text here at the end
                              10/4/2010 6:40:00 AM -240 some text here at the end
                              10/4/2010 6:41:00 AM -136 some text here at the end
                              10/4/2010 6:45:00 AM -21 some text here at the end
                              10/4/2010 6:45:00 AM 110 some text here at the end
                              10/4/2010 6:47:00 AM 214 some text here at the end
                              10/4/2010 7:02:00 AM -924 some text here at the end
                              10/4/2010 7:48:00 AM -1045 some text here at the end

                              Code:

                              protected override void OnBarUpdate()
                              {
                              if (FirstTickOfBar && Bars.FirstBarOfSession)
                              {
                              alertPriceUp = Close[0] + 100;
                              alertPriceDown = Close[0] - 100;
                              }

                              if (CrossAbove(Close, alertPriceUp, 1))
                              {
                              Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick 1300.wav", 10, Color.White, Color.Black);
                              DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -15 * TickSize, Color.Yellow);
                              alertPriceUp = Close[0] + 100;
                              Print(Time[0].ToString() + " " + Close[0] + " " + "some text here at the end");

                              }

                              if (CrossBelow(Close, alertPriceDown, 1))
                              {
                              Alert("MyAlert1137", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\tick -1300.wav", 10, Color.White, Color.Black);
                              DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 15 * TickSize, Color.Yellow);
                              alertPriceDown = Close[0] - 100;
                              Print(Time[0].ToString() + " " + Close[0] + " " + "some text here at the end");


                              }
                              }
                              Attached Files

                              Comment


                                #30
                                DJ, the outcome you see would mean you fail to update the new amount base then as needed as it still takes the old one as reference for the calculations.
                                BertrandNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by i019945nj, 12-14-2023, 06:41 AM
                                5 responses
                                64 views
                                0 likes
                                Last Post i019945nj  
                                Started by ruudawakening, Today, 12:58 AM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by thread, Yesterday, 11:58 PM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by stafe, Yesterday, 08:34 PM
                                1 response
                                16 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by jclose, Yesterday, 09:37 PM
                                1 response
                                11 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X