PDA

View Full Version : draw vertical line


pulla
02-23-2009, 12:58 PM
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

NinjaTrader_Bertrand
02-23-2009, 01:32 PM
Hi pulla,

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


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


Please also check this link - http://www.ninjatrader-support.com/HelpGuideV6/DrawVerticalLine.html

For our custom indicator coding tutorials, follow this one please -
http://www.ninjatrader-support.com/HelpGuideV6/Overview18.html

noevictorian
09-24-2009, 05:09 PM
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)

noevictorian
09-24-2009, 05:11 PM
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...

NinjaTrader_Bertrand
09-25-2009, 01:47 AM
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.

MoreYummy
04-06-2010, 05:31 PM
Does it draw vertical line on range chart automatically?

MoreYummy
04-06-2010, 06:36 PM
when i tried the code,
it draws line to connect the candle.

How come it does draw vertical line?

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

NinjaTrader_Bertrand
04-07-2010, 03:57 AM
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.

gandalf33
01-09-2011, 08:00 AM
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:

protected override void 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

NinjaTrader_Brett
01-09-2011, 01:59 PM
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.

gandalf33
01-10-2011, 12:41 AM
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"?

NinjaTrader_Bertrand
01-10-2011, 03:10 AM
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.

superarrow
01-14-2011, 09:27 AM
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?

NinjaTrader_Bertrand
01-14-2011, 09:30 AM
Unfortunately not if done programmatically by a NinjaScript study - this is on our list of feedback already to look into for the future.

gandalf33
01-14-2011, 09:57 AM
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.

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.