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

draw vertical line

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

    draw vertical line

    hi ,
    can some one help me write code to draw vertical line on 9:30 am and another vertical line on 10:30 am, i want to use this indicator to draw automatically every day 1st hour start and end vertical line

    Thanks in advance

    #2
    Hi pulla,

    you can for example use this code snippet to draw a vertical blue line at 9:30 am -

    Code:
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (ToTime(Time[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]]) == [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]93000[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2])
    DrawVerticalLine([/SIZE][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"myTime"[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] + CurrentBar, [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], Color.Blue);[/SIZE][/SIZE]
    [SIZE=2][SIZE=2][/SIZE][/SIZE]


    Please also check this link - http://www.ninjatrader-support.com/H...ticalLine.html

    For our custom indicator coding tutorials, follow this one please -



    BertrandNinjaTrader Customer Service

    Comment


      #3
      Betrand, thanks for the super concise reply to Pulla's question. I'm making good use of it, too.

      One question for you or anyone else who's figured this out... how can I make a line that's drawn via ninjascript non-editable?

      I'm finding that it's easy to click and drag drawn objects by mistake. And since there's no Undo on charts, it becomes awkward. But if you can draw locked lines... then it's solved.

      Thanks for any help (I searched the forums but didn't find anything on this... I can only imagine i'm using the wrong search terms)

      Comment


        #4
        NEVERMIND! I just found a couple mentions in the search. I see now that it's not possible but may become possible in version 7.

        Here's to hoping...

        Comment


          #5
          Correct, NinjaTrader 7 allows you to 'lock' drawn objects - http://www.ninjatrader.com/webnew/NT7/NinjaTrader7.html

          New Draw Object Locking and Attaching
          1) Draw objects can now be locked via the UI and through NinjaScript. Locked objects can't be moved.
          2) Draw objects can be attached to any Data Series or Indicator on a chart.
          Attaching them to an indicator will associate the draw object to the same scale.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Does it draw vertical line on range chart automatically?

            Comment


              #7
              when i tried the code,
              it draws line to connect the candle.

              How come it does draw vertical line?
              Code:
                          if (ToTime(Time[0]) == timeInput)
                              DrawVerticalLine("myTime" + CurrentBar, 0, Color.Blue);

              Comment


                #8
                Sorry I don't follow you - DrawVertical() is indeed used to draw a vertical line on the chart, for a regular non vertical one, please try the generalized DrawLine() method in NinjaScript.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  MoreYummy probably means, that he/she tried to create an indicator with the Wizard, and pasted the VerticalLine code into it, compiled, added the new indicator to the chart, and candles were connected with lines instead of vertical lines being present.

                  At least this is what happened to me.

                  I've pasted the code here:

                  protectedoverridevoid OnBarUpdate()
                  {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  Plot0.Set(Close[0]);


                  if (ToTime(Time[0]) == 93000)
                  DrawVerticalLine(
                  "myTime" + CurrentBar, 0, Color.Blue);

                  }

                  After commenting the Plot0 line (to //Plot0.Set....), candle-connecting lines are removed but no vertical lines at 09:30 are present.

                  Can somebody direct me towards fixing this please? Thanks

                  Comment


                    #10
                    Hello,

                    Sure, Make sure Plot0 is commented out as this will draw the lines at the close for each close of each bar.


                    Also, try this as a quick test:

                    if (ToTime(Time[0]) >= 93000)
                    DrawVerticalLine(
                    "myTime" + CurrentBar, 0
                    , Color.Blue);

                    Ths will draw a line for every time above 9:30. Do you see any see a bunch of lines drawn now or still no lines?

                    I look forward to assisting you further.



                    Comment


                      #11
                      Greetings Brett,

                      yes, that made the vertical lines be present on each candle down til midnight, then from 9:30 the next day til midnight, etc. - thanks so much.

                      The information that I'm using this code on a 30-min chart might be useful.

                      Amending the code to:

                      if (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 100000)
                      DrawVerticalLine(
                      "myTime" + CurrentBar, 0, Color.Blue);

                      made what I wanted to see - one vertical line at 9:30 only.

                      My next question is, can this code be altered to something more universal? I mean something that tells the following: "plot a vertical line on the first bar that reaches, or 'contains' the initial time (e.g. 9:30 in this example), and plot no other vertical lines after that bar, regardless of the timeframe"?

                      Comment


                        #12
                        gandalf33, yes this would be possible - you would need to customize the condition for the timeframes of interest and which timestamps they would produce (NinjaTrader stamps the bars with the close time). If you just want a bar on the 9:30 you could also setup a custom session starting at this time and then drawing the vertical line on the first bar of the session, this could be accessed programmatically as well.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Hi Bert,
                          Would it be possible for the vertical line indicator to draw the line on all charts of the same instrument by means of global attributes?
                          Last edited by superarrow; 01-14-2011, 10:30 AM.

                          Comment


                            #14
                            Unfortunately not if done programmatically by a NinjaScript study - this is on our list of feedback already to look into for the future.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Greetings Bertrando,

                              thanks for the information below. I have no idea how to do it but customizing the vertical line condition manually per my timeframes does it for the time being.

                              I've played with custom sessions before, but it seemed to me, custom sessions cut out the premarket price movement - a solution not viable for me, unless I've missed some switch "Also show premarket data prior custom session settings".

                              Thanks again.

                              Originally posted by NinjaTrader_Bertrand View Post
                              gandalf33, yes this would be possible - you would need to customize the condition for the timeframes of interest and which timestamps they would produce (NinjaTrader stamps the bars with the close time). If you just want a bar on the 9:30 you could also setup a custom session starting at this time and then drawing the vertical line on the first bar of the session, this could be accessed programmatically as well.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,413 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X