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

range of selected 15 minute bars

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

    range of selected 15 minute bars

    Hi support (or anyone)

    I am going to try to get some historical data today.

    When it comes one thing I want to see is:

    The average range of the 15 minute bars from 9:30 AM to
    4:00 PM on trading days {M-F} of the ES (and maybe YM) going
    back X days. Perhaps 15, let's say. This would be a program
    that would be run every weekend if there was real-time data.

    The code subjects below seem to be a good start. (If this
    code/question has been recorded on the forum that would
    be fine. I don't need to re-invent the wheel.)

    The statement 'ToDay' would work but it would require the
    changing of the program each week, which doesn't seem to
    be the way to go.

    Any suggestions on any of this matter in general would be helpful.


    >>>>>>>>>>>>ToTime stuff page 614

    // Only trade between 7:45 AM and 1:45 PM
    if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
    {
    // Strategy logic goes here
    }

    >>>>>>>>>>>ToDay stuff page 611
    // Compare the date of the current bar to September 15, 2006
    if (ToDay(Time[0]) > 20060915)
    // Do something

    >>>>>>>>>>>>Range stuff page 709

    Print("The current bar's range is " + value.ToString());
    // Prints the 20 period simple moving average of range
    double value = SMA(Range(), 20)[0];
    Print("The 20 period average of range is " + value.ToString());

    #2
    stephenszpak,

    I am not entirely following your reasoning to check the dates at all. If you just wanted to check it against being Monday - Friday you can try using DayOfWeek instead: http://www.ninjatrader-support.com/H...DayOfWeek.html
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      stephenszpak,

      I am not entirely following your reasoning to check the dates at all. If you just wanted to check it against being Monday - Friday you can try using DayOfWeek instead: http://www.ninjatrader-support.com/H...DayOfWeek.html

      I forgot this existed, thanks:

      {
      // If its Monday...do not trade
      if (Time[0].DayOfWeek == DayOfWeek.Monday)
      return;
      }

      But still, are you sure the NT software would know to look back to the 2nd Monday and 2nd
      Tuesday etc. etc. then 3rd Monday and 3rd Tuesday etc.etc.

      This would be 3 (or perhaps 4) trading weeks as I stated below.
      At the very least, 10 trading days.

      Comment


        #4
        stephenszpak,

        You would need to come up with your own logic to make such checks. You could use ToDay(DateTime.Now) to get the date of today and run checks off of that if you need.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          stephenszpak,

          You would need to come up with your own logic to make such checks. You could use ToDay(DateTime.Now) to get the date of today and run checks off of that if you need.
          'run checks off of that' = doesn't mean anything to me

          Regardless, if I use this as the code (see below), will it work for one day?
          If I could get it to work for one day I'll use a hand calculator to add 10
          days together (as the days pass) and then divide that by 10 to get a average.



          if (ToTime(Time[0]) >= 73000 && ToTime(Time[0]) <= 140000)
          double value = SMA(Range(), 26)[0];
          Print("The 26 period average of range is " + value.ToString());

          Comment


            #6
            stephenszpak,

            Unfortunately I cannot evaluate your code for you. You will need to see if it does what you want it to do through debugging. From the looks of it your code will get you the SMA value while you are withing a certain time range. When outside the time range it stops giving you the SMA value. Not sure if that is what you wanted to do or not.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              stephenszpak,

              Unfortunately I cannot evaluate your code for you. You will need to see if it does what you want it to do through debugging. From the looks of it your code will get you the SMA value while you are withing a certain time range. When outside the time range it stops giving you the SMA value. Not sure if that is what you wanted to do or not.
              Yes, as I wrote below "When it comes one thing I want to see is:

              The average range of the 15 minute bars from 9:30 AM to
              4:00 PM..."

              Comment


                #8
                What I am saying is you will receive output from that code snippet multiple times for each bar within that time range. Not sure if that is what you want or not.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  What I am saying is you will receive output from that code snippet multiple times for each bar within that time range. Not sure if that is what you want or not.
                  Apparently my code doesn't work. I just want the average range of a 15 minute
                  bar over an extended time (several trading days). If this value increases then
                  the stop loss of a strategy would have to change, etc.
                  I think I'll end up using a hand calculator in the short term.

                  Comment


                    #10
                    I worked on this some more and have an indicator that
                    successfully compiled. Unfortunately it doesn't work.

                    I checked the output window and it is empty.

                    The code is below. It could be done better, but I thought
                    it would take the average range of the 13 last bars. If this
                    was run at the end of a trading day on 30 minute bars I
                    thought it would give the average range. (Of course this could be
                    changed to 26 for 15 minute bars if it ever actually works.)

                    I think the OnBarUpdate area is the only place I added/changed code.

                    Back in a few days.
                    ================================================== ================

                    protected override void Initialize()
                    {
                    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                    CalculateOnBarClose = true;
                    Overlay = false;
                    PriceTypeSupported = false;
                    }

                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                    double average = ((High[1]-Low[1])+(High[2]-Low[2])+(High[3]-Low[3])+(High[4]-Low[4])+(High[5]-Low[5])+(High[6]-Low[6])+(High[7]-Low[7])+(High[8]-Low[8])+(High[9]-Low[9])+(High[10]-Low[10])+(High[11]-Low[11])+(High[12]-Low[12])+(High[13]-Low[13]))/13;
                    Print("The current 30 minute average range is " + average.ToString());
                    }

                    Comment


                      #11
                      You would need to add a check at the start of your OnBarUpdate() to make sure the dataseries you're trying to access has enough bars present, if you apply your indicator now, you'll most likely see an error in the Log tab of the Control Center listed....more can be found in this tip - http://www.ninjatrader-support2.com/...ead.php?t=3170
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        You would need to add a check at the start of your OnBarUpdate() to make sure the dataseries you're trying to access has enough bars present, if you apply your indicator now, you'll most likely see an error in the Log tab of the Control Center listed....more can be found in this tip - http://www.ninjatrader-support2.com/...ead.php?t=3170
                        Yes there was an error as you said. There was more than 13 bars on the
                        chart however.

                        I added this

                        if (CurrentBar < 13)
                        return;

                        It works.
                        Last edited by stephenszpak; 06-28-2009, 02:51 AM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        43 views
                        0 likes
                        Last Post jeronymite  
                        Started by frankthearm, Today, 09:08 AM
                        4 responses
                        10 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by yertle, Today, 08:38 AM
                        5 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by adeelshahzad, Today, 03:54 AM
                        3 responses
                        18 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by bill2023, Yesterday, 08:51 AM
                        6 responses
                        27 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Working...
                        X