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

HighestBar and LowestBar

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

    HighestBar and LowestBar

    Hi All,

    If I am using HighestBar() or LowestBar() methods, over say a 30 bar window, if there are several bars with the same highest or lowest value, which bar will these methods return...?? The first occurence or the last occurence...?

    Many Thanks.

    #2
    >> which bar will these methods return
    The first one from right to left.

    Comment


      #3
      Thanks Dierk.

      As an aside, another question.
      I have an indicator which returns a value of either 1,-1 or 0. Right now, I'm looking to backest taking a long when it's value is 1, or a short when it's value is -1. With a trailing stop.

      At the moment, I'm checking the value of the indicator within OnBarUpdate() and using this to trigger my trade entry. However, it seems that I get into the position the bar after the indicator turns either 1 or -1. Now, I guess this may be something to do with the CalculateOnBarClose parameter. But I can't quite see why.

      Comment


        #4
        In a backtest, conditions are evaluated per bar which of course is the closing values of the bar. Thus, if a condition is true, an order is filled on the next bar.
        RayNinjaTrader Customer Service

        Comment


          #5
          Thanks Ray.

          So, during a backtest, if an EnterLong() is called, is it filled at the open of the bar??

          Thanks.

          Comment


            #6
            Open of the next bar.
            RayNinjaTrader Customer Service

            Comment


              #7
              So Ray, if were looking at 5 min bars for my signals, but wanted to execute an entry quicker than the open of the next 5 min bar, then I would need to add say, a 1 min bar object, and execute off that object but still generate signals off the 5 min object...?

              Comment


                #8
                Lets sync on what you are after?

                - This discussion is in the context of a backtest
                - You can do as you suggest but for market orders it will not make any difference. The open price of the next 5 minute bar is the same as the open price of the next 1 minute bar (theoreticaly) so you likely get the same fill.
                - For a limit order, this can make a difference, see this reference sample - http://www.ninjatrader-support.com/v...ead.php?t=6652
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Hi Ray,

                  I got some very weird stuff going down right now!!

                  Since I've added a new 1 min series to the default 5 min series, I'm getting some very weird behaviour using the BarsSinceEntry() method....

                  Essentially I was referencing the value of BarsSinceEntry() within OnBarUpdate()... anyway, it seemed to stop OnBarUpdate() being called... I've narrowed it down after some time to the BarsSinceEntry() method.

                  Right now if I perform a backtest on my strategy between 10:00 and 14:00, primary 5 min bars, with a 1 min bar object added too... ALL my code in OnBarUpdate() is commented out except for a Print() statement at the start... this Print() statement prints the current time. So far so good... when I run the strategy it prints ALL 5 min bar times across the backtest to the output window.

                  However, as soon as I add something to the print statement so that now it prints the current time (Time[0]) and also BarsSinceEntry(), now I only get one print in the output window which is the first 5 min bar. It seems calling the BarsSinceEntry() method stops the OnBarUpdate() method being called again....

                  Have you seen this before...?? Weird. any ideas.

                  Many Thanks

                  Comment


                    #10
                    Ray,

                    I just created a blank strategy with the following code and it does exactly as I mentioned in my last post.... the BarsSinceEntry() call seems to stop OnBarUpdate() being called again. If I comment out the BarsSinceEntry() line I get every time print the strategy is run over 95 min bars)... otherwise I only get the first.

                    #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.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 MyCustomStrategy : 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()
                    {
                    Add(PeriodType.Minute,1);
                    CalculateOnBarClose = true;
                    }

                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                    Print("time[0] " + Time[0]);
                    Print("barsinceentry() = " + BarsSinceEntry());

                    }

                    #region Properties
                    [Description("")]
                    [Category("Parameters")]
                    public int MyInput0
                    {
                    get { return myInput0; }
                    set { myInput0 = Math.Max(1, value); }
                    }
                    #endregion
                    }
                    }

                    Comment


                      #11
                      Are there any error messages in the log?
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Yes Ray. Sorry, didn't think to check there.

                        It says,

                        "Error on calling 'OnBarUpdate' method for strategy. You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntry() method in the context of a multi-time frame and instrument strategy."

                        Which is great. What does it mean...?

                        Comment


                          #13
                          See the following link, is explained there.

                          http://www.ninjatrader-support.com/H...inceEntry.html
                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Ray, that link is simply to the on-line support guide front page... Can you point to anywhere slightly more specific...?

                            Thanks again

                            Comment


                              #15
                              Please check again, I corrected the link.
                              RayNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by habeebft, Today, 07:27 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_ChristopherS  
                              Started by AveryFlynn, Today, 04:57 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Max238, Today, 01:28 AM
                              4 responses
                              37 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by r68cervera, Today, 05:29 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by geddyisodin, Today, 05:20 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X