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

Current high/low of specific sessions

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

    Current high/low of specific sessions

    Hi,

    (1) Code(a) plots the high and low of current day according to the session begins and session ends time defined in the chart properties. Code(b) get the first bar of the session.

    (a) if (Bars.SessionBreak)
    {
    currentHigh = High[0];
    currentLow = Low[0];
    }
    currentHigh = Math.Max(currentHigh, High[0]);
    currentLow = Math.Min(currentLow, Low[0]);

    (b) if(Bars.FirstBarOfSession)

    (2) What function should I use if I would like to plot the current high and low as well as to get the the first bar of the following defined sessions(eg. 9:15 to 10:15 ; 10:15 to 11:15 ; 11:15 to 12:15 and so on)? Thanks in advance.

    #2
    Hi K. SATO,

    You can create time filter similar to the one here - http://www.ninjatrader.com/support/f...ead.php?t=3226

    You could then flag (record) the bar at which the time filter begins, then find the MAX over the last bars, back until the bar that the time filter started.
    Last edited by NinjaTrader_Tim; 05-12-2010, 01:16 PM.
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi Tim,

      (1) I mainly look at Range Bar Chart.I think I'm really lost in getting the first bar of the specified session. I try the following code but it seems only to work on time based chart.

      if(ToTime(Time[0]) ==211500 || ToTime(Time[0]) ==221500 || ToTime(Time[0]) ==231500 || ToTime(Time[0]) ==01500)

      {
      h1 = High[0];
      l1 = Low[0];
      }

      p1.Set (h1);
      p2.Set (l1);

      DrawRegion("reg1",CurrentBar, 0, p1, p2, Color.Transparent, Color.DarkGray, 4);

      (2) I try Bars.GetBar ; Bars.SessionBreak ; Bars.FirstBarOfSession . They are all either related to the session begins time defined in chart properties or time stamp is needed.

      (3) I know I've to flat the first bar then apply

      if(ToTime(Time[0]) >211500 && ToTime(Time[0]) <221500 || ToTime(Time[0]) >22150 && ToTime(Time[0]) <231500) and MAX/ MIN which should solve the problem? Any further advice will be much appreciated!

      (4) For the time being,I just have to change the session begins and ends time in chart properties in order to get whant I want temporarily but it's too inconvenient. Attachment refered.
      Attached Files

      Comment


        #4
        Hi K. SATO,

        1. When you use 'ToTime(Time[0]) ==211500" you are trying to satisfy the condition that the single timestamp of the bar equals 211500. With Range bars, the start and end of each bar is determined by when the range of the bar is completed, and not by a round interval, like 1 or 5 minute interval charts. And therefore the timestamp likely won't meet your condition.

        2. The GetBar() is used as in the following page - http://www.ninjatrader-support.com/H...de.html?GetBar

        As for SessionBreak and FirstBarOfSession, that will indeed be determined by the chart settings.

        You could either use an interval that will offer time stamps to meet the condition in 1, or use a much "looser" range for the condition, such as...

        ToTime(Time[0]) >211500 && ToTime(Time[0]) <222000

        which is a condition that is not guaranteed to be met, but is more likely depending on the Range interval you use.
        TimNinjaTrader Customer Service

        Comment


          #5
          Hi Tim,

          So am I right to say based on current NT6.5 or even NT7.0, it won't be able to do what I wanted if Range Bars Chart is preferred? Any possibility to solve this in the near future?

          Comment


            #6
            Hi K. SATO,

            You can do this with the current versions. You will just need to figure out a way to satisfy the condition using range bars.

            For example, if you use...
            Code:
            if(ToTime(Time[0]) > 211500)
            The first range bar that satisfies this will be processed.


            You can then grab the value you want....
            Code:
            if(ToTime(Time[0]) > 211500)
            {
            h1 = High[0];
            l1 = Low[0];
            }

            Then make sure the values are not grabbed again...
            Code:
            if(ToTime(Time[0]) > 211500 && bool = true)
            {
            h1 = High[0];
            l1 = Low[0];
            bool = false
            }
            Then reset the bool before your next time condition.
            TimNinjaTrader Customer Service

            Comment


              #7
              Hi Tim,

              I'm totally new to programming .Furthermore this is the first time I deal with BOOL. I try the following .Code compiled but nothing plotted and shown. Can you kindly point out my mistakes? Thanks again.

              #region Variables
              // Wizard generated variables
              // User defined variables (add any user defined variables below)

              private double h1 ;
              private double l1 ;

              private bool isInit;

              private DataSeries p1;
              private DataSeries p2;

              #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()
              {

              p1 = new DataSeries (this);
              p2 = new DataSeries (this);

              CalculateOnBarClose = true;
              Overlay = true;
              PriceTypeSupported = false;

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

              if(ToTime(Time[0]) >210000 && isInit==true || ToTime(Time[0]) >211500 && isInit==true)

              {
              h1 = High[0];
              l1 = Low[0];
              isInit = false;

              Print("h1:" + h1.ToString());

              p1.Set (h1);
              p2.Set (l1);
              }

              DrawRegion("Reg1", CurrentBar, 0, p1, p2, Color.Transparent, Color.DarkRed,10);
              }

              Comment


                #8
                Hello K.Sato,

                First thing I would look at here is simplifying your condition:

                if(ToTime(Time[0]) >210000 && isInit==true || ToTime(Time[0]) >211500 && isInit==true)

                Maybe try separating these conditions into separate if statements.

                Clarify your intentions a bit here and we may be able to get you on the right track.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hi RyanM,

                  I'm sorry for disturbing your weekend. Actually I would like to plot the current high and low as well as to get the the first bar's High and Low of the following defined sessions on Range Bars Chart (eg. 9:15 to 10:15 ; 10:15 to 11:15 ; 11:15 to 12:15 and so on over the 24 hours market). Now I've the difficulty in getting the first bar values to be used next when I apply MAX/MIN.Your guidance will be much appreciated!

                  Comment


                    #10
                    K. SATO,

                    You will need to use the time filter as Ryan has shown you in the previous post for each of your time ranges. Then inside your if-statement you will want to keep track of your own variable for Highs and Lows. When a new high is reached within that time range, store that value into your variable. Every time you have a bar within that time range you compare its high versus your stored value. If the new bar's high > the stored high then you have a new high and you should store that instead. Then at the end of the time range you will have that range's high/low. Please see here:

                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Javierw.ok  
                    Started by timmbbo, Today, 08:59 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post bltdavid  
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    40 views
                    0 likes
                    Last Post alifarahani  
                    Started by Waxavi, Today, 02:10 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X