Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 02-23-2009, 01:58 PM   #1
pulla
Junior Member
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Arrow 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
pulla is offline  
Reply With Quote
Old 02-23-2009, 02:32 PM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,408
Thanks: 416
Thanked 1,591 times in 1,557 posts
Default

Hi pulla,

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

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


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

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


NinjaTrader_Bertrand is offline  
Reply With Quote
Old 09-24-2009, 05:09 PM   #3
noevictorian
Member
 
Join Date: Aug 2009
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

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 is offline  
Reply With Quote
Old 09-24-2009, 05:11 PM   #4
noevictorian
Member
 
Join Date: Aug 2009
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

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...
noevictorian is offline  
Reply With Quote
Old 09-25-2009, 01:47 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,408
Thanks: 416
Thanked 1,591 times in 1,557 posts
Default

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.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-06-2010, 05:31 PM   #6
MoreYummy
Senior Member
 
Join Date: Aug 2008
Posts: 325
Thanks: 0
Thanked 0 times in 0 posts
Default

Does it draw vertical line on range chart automatically?
MoreYummy is offline  
Reply With Quote
Old 04-06-2010, 06:36 PM   #7
MoreYummy
Senior Member
 
Join Date: Aug 2008
Posts: 325
Thanks: 0
Thanked 0 times in 0 posts
Default

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);
MoreYummy is offline  
Reply With Quote
Old 04-07-2010, 03:57 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,408
Thanks: 416
Thanked 1,591 times in 1,557 posts
Default

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.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-09-2011, 09:00 AM   #9
gandalf33
Junior Member
 
Join Date: Mar 2009
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

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
gandalf33 is offline  
Reply With Quote
Old 01-09-2011, 02:59 PM   #10
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,568
Thanks: 111
Thanked 314 times in 299 posts
Default

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.



NinjaTrader_Brett is offline  
Reply With Quote
Old 01-10-2011, 01:41 AM   #11
gandalf33
Junior Member
 
Join Date: Mar 2009
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

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"?
gandalf33 is offline  
Reply With Quote
Old 01-10-2011, 04:10 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,408
Thanks: 416
Thanked 1,591 times in 1,557 posts
Default

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.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-14-2011, 10:27 AM   #13
superarrow
Senior Member
 
Join Date: Dec 2007
Posts: 128
Thanks: 0
Thanked 0 times in 0 posts
Default

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 at 10:30 AM.
superarrow is offline  
Reply With Quote
Old 01-14-2011, 10:30 AM   #14
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,408
Thanks: 416
Thanked 1,591 times in 1,557 posts
Default

Unfortunately not if done programmatically by a NinjaScript study - this is on our list of feedback already to look into for the future.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-14-2011, 10:57 AM   #15
gandalf33
Junior Member
 
Join Date: Mar 2009
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

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.

Quote:
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.
gandalf33 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Draw Vertical Line not in Price Panel mason Indicator Development 3 12-01-2009 10:50 AM
draw a vertical line at certain time of the day MoreYummy Charting 1 11-12-2008 08:51 AM
draw a simple vertical line at specified time of day duck_CA Indicator Development 5 07-25-2008 11:17 AM
Draw Vertical Line jjthetrader General Programming 13 01-30-2008 11:12 AM
how to draw a parallel line to a trend line? tradewiz Charting 4 12-19-2007 05:42 AM


All times are GMT -6. The time now is 08:00 PM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.