Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a line from a certain time to current

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

    Drawing a line from a certain time to current

    Can you please tell me how to draw a line starting at 9:30 AM, startY=OpenOfFirstBar, endTime=4:15 PM, endY=sameAsStartY,
    and unique for each day. I see the format but I'm not sure of what goes where.

    DrawLine(string tag, bool autoScale, DateTime startTime, double startY, DateTime endTime, double endY, Color color, DashStyle dashStyle, int width)

    Thanks

    #2
    Hello kenb2004,
    Please try the below code

    Code:
    DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0), Close[0], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 15, 0), Close[0], Color.Blue, DashStyle.Dash, 2);

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks Joydeep

      I put this code in but the startY and endY can't be Close[0]. I needs to be the Open Price of the first bar for both. How would you do that?

      Thanks

      Comment


        #4
        Hello kenb2004,
        Please use this modified code

        Code:
        DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0), Open[Bars.BarsSinceSession], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 15, 0), Open[Bars.BarsSinceSession], Color.Blue, DashStyle.Dash, 2);

        Please let me know if i can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thank you, Joydeep, but unfortunately
          Open[Bars.BarsSinceSession]
          is NOT the same as the Open of the first bar at 9:30 AM. This bar usually represents the beginnig of 24 hour trading usually starting in the afternoon of the previous day.

          The bar I'm looking for has to be the Open of the first bar at 9:30 AM, regardless of bar type, for Intraday trading.

          Thanks

          Comment


            #6
            Hi kenb2004,

            You can use GetBar() to get the bars ago value from a defined time. The following reference sample can help you further with this:
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Ryan

              I looked at that Sample and it's explains how to get a value from 9:30 AM the previous day excluding the ES, in which case the code would need to be modified. All I need is the Opening Price of the current day, at 9:30 AM. Isn't there a simpler way to capture this Opening price at 9:30 AM?

              I've looked at your CurrentDayOHL, but this uses the default session time which is not 9:30 AM.
              Last edited by kenb2004; 06-28-2012, 01:32 PM.

              Comment


                #8
                What time series chart are you going to be running this on? There is one other method to do this but depends on what type of chart you will be running on.

                Comment


                  #9
                  KenB
                  Can I assume you are trying to draw a line at today's opening price.

                  If so the easiest way to go about it is to set up your own session template in the session manager - Start sunday at 6pm to Monday 9.30 then monday 930 to 415 then monday 430 to Tuesday 930 then Tuesday 930 to Tuesday 415 then Tuesday 430 to wednesday 930 etc.

                  Once you have done this go to the data series and change the session template to the one you have just created.
                  You can then use

                  TodaysOpen.Set(Open[Bars.BarsSinceSession]);

                  Hope this is helpful.

                  Ben

                  Comment


                    #10
                    stocktraderbmp

                    Thank you for your input, I do believe that would be a simple workaround for a session open, but I am trying to use the DateTime property that NinjaTrader has as a format in the Help Guide for DrawLine and I would like to know the best way to use this particular property. There is no example in the user guide so that is why I am on this forum trying to get some help.

                    Bret

                    I am presently using a 55 Tick Chart for the ES, not a Time Series.

                    Comment


                      #11
                      I was trying to do the same thing using a volume derived bar - as I understand it - the data is time stamped so any reference to time has to be derived from that time stamp. If tick 1 (a new bar) happens to start at 092955 then that is the open of that bar - if the 55th tick is at 093001 then that is the time of the close - both points / values / times can be referenced but there is NO recording of 093000. If you are using tick derived bars your line will have to be drawn from a tick derived datum point. (ie tick number 1 would be the bar open - tick 55 the bar close value etc). Obviously you will have the same problem as I did and possibly hundreds before us - namely, how many ticks are there going to be between the session start (Globex @ 1630) and your required datum point of 093000? obviously we don't know. It is easy to 'get the bar' but then you will only be able to reference the OHLC, typical etc and these points are unlikely to be at exactly 0930 !!!
                      Because you require the line at precisely 0930 the bar being formed at that time may only be 23 ticks in size - how does your bar stop and start a new one? It can't as you have specified that each bar has to be 55 ticks, so you have to use an external datum and the easiest way is to use the session template. This overides the 55 tick per bar requirement and terminates the bar at the '23rd' tick, or whatever tick it is; so that a new session can start at exactly 0930 and the tick is # 1 or the 'open' and can be referenced elsewhere by your code / strategy etc. In effect you are synchronising your tick bars to time rather than trying to synchronise the rest of the trading world to your bar !!
                      I thought this was going to be inconvenient as well but it has turned out to work fine and I get a bar starting at exactly 0930 everyday.
                      The other bonus is that most indicators are designed around a time as well as value eg pivots; so little if any adaptation of the code is required plus you can then utilize indicators such as Initial balance prior ohlc etc. Also if you are writing a strategy you can then easily reference key times of the day ,open, close etc without having to 'get bar' every time and then having an approximation.
                      I have these indicators adapted for use on charts that are NOT time derived - I trade using volume derived bars - if they would be of help or use to you I would be happy to forward them to you but again the session template has to be set up as I have described. Rather inconveniently the CBOT still insists on opening the pit everyday at 0930 (EST) instead of on the 4327th tick !!
                      The only viable work around you have is to draw a line derived from the bar before 0930 and a line from the bar after 0930 and then plot a mid point - alternatively you could script if open is less than 0930 and close is greater than 0930 plot a line at the (typical, open, median etc). This will not give you the accurate open value every time but you are using such a small tick size (sorry - assuming again that you are trading a liquid instrument) that it will be pretty close.
                      If it has to be dead accurate though - I am afraid your options, at least as far as I am aware and without advanced coding, are limited because of the way the data is processed when it is supplied to the NT platform.
                      If you want to go down the coding route then Kooganam is a veritable genius and seems to be able to solve almost anything here. He was a great help to me. But again I think that this will be far more complicated than it sounds and probably needs to be.
                      Let me know if you want the IB (1st hr range and open) and the prior ohlc indicators that I have adapted and good luck with your trading.

                      Ben

                      Comment


                        #12
                        Hello kenb2004,
                        Please try the below code

                        Code:
                        int open = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0)) - 1;
                        if (CurrentBar > open)
                        		this.DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0), Open[open], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 15, 0), Open[open], Color.Blue, DashStyle.Dash, 2);
                        Please let me know if I can assist you any further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          stocktraderbmp

                          Thank you very much for a very thorough explanation. I have come to a similar conclusion.


                          joydeep

                          Thank you for getting back, I'll give this a try.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Joydeep View Post
                            Hello kenb2004,
                            Please try the below code

                            Code:
                            int open = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0)) - 1;
                            if (CurrentBar > open)
                                    this.DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0), Open[open], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 15, 0), Open[open], Color.Blue, DashStyle.Dash, 2);
                            Please let me know if I can assist you any further.
                            Hello Joydeep,
                            this is what I was looking for a long time. I would ask if it would be possible to adjust it a bit. I would like to draw a line at the close of the previous day on the daily chart, for ex. S&P500.

                            Comment


                              #15
                              Hello emuns,

                              You can use this same setup but in the DrawLine() method you want to use the Close[] instead of Open[].

                              JCNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              61 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              18 views
                              0 likes
                              Last Post traderqz  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              5 responses
                              48 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X