View Full Version : How to set a bar color intra-day
Spartacus
02-11-2010, 11:27 AM
Hi,
Can anyone tell me how to change the color of the current and subsequent bars midstream via Ninja Script. What I'm trying to do is write something that would allow the price bars to change shade or color as it passes a particular time of the day. So if the price bars are originally green during regular market hours their color would change to another designated color once time has reached, let say, 4:15PM. Then the bars would change back to their original colors when it becomes 9:30AM, to show regular and non-regular market hours.
I've been fooling around writing some indicators in ninja script but can't figure out how to do this.
Regards,
Johnny
NinjaTrader_RyanM
02-11-2010, 12:51 PM
Hello Spartacus,
Thank you for your post.
You can filter for time conditions. The reference samples below is used to limit trading during certain hours, but you might be able to modify the concepts to paint a bar at certain hours:
http://www.ninjatrader-support2.com/vb/showthread.php?t=3226
You change BarColor using the barcolor property:
http://www.ninjatrader-support.com/HelpGuideV6/BarColor.html
You can add a check to only run on real-time data. Add this in the OnBarUpdate() section:
if (Historical)
return;
Spartacus
02-11-2010, 05:25 PM
Hi Ryan,
Thank you and it worked.
I assumed that working for bar type would also work for candle. Please see attached and can you comment on how to get it to work for candle as well as bar types. The stems seem uncolored. I mean that's good enough, but to distinquish between up & down candles, and the stems, do you have further suggestions? thanks!
Regards,
Spartacus
NinjaTrader_RyanM
02-11-2010, 05:46 PM
Hi Jonny,
Which version of NinjaTrader are you using? There's a change to the BarColor property in version 7.
Taken from:
http://www.ninjatrader-support2.com/vb/showthread.php?t=21016
BarColor no longer colors the entire bar. It will color the bar body only. To color the bar outline please use CandleOutlineColor.
If you want Up/Down Colors you would have to add two extra conditions to evaluate and then paint the bars different colors. Something like:
if (Close[0] > Open[0] && yourTimeFilter)
setYourUpColorHere;
if (Close[0] <= Open[0] && yourTimeFilter)
setYourDownColorHere;
You might also consider changing the BackColor instead of the BarColor.
http://www.ninjatrader-support.com/HelpGuideV6/BackColor.html
Spartacus
02-16-2010, 07:05 PM
Hi Ryan,
Thanks for the information, very helpful. I am using NT7b9.
In the NT7 documentation I didn't come across anything like the member variable CandleOutlineColor that you pointed out in in the previous message, would you know what sources I can look at to find out such information?
I would like to make all the components (UP bar, DOWN bar, candle OUTLINE, "TO TIME", "FROM TIME) parameter driven. I have a good idea how to do it for integers (time components) when making the time parameters configurable, but for colors I simply don't know how to offset into the "plot" object to access the color so that I can store it into a local variable. Do I use the Ninja script wizard to plot the color? If so how would I reference that color from within the onBarUpdate method?
Your suggestion about changing the background color instead sounds just as good, however I'd like to get used to manipulating price bars as well.
Ryan, Thanks for your assistance.
NinjaTrader_RyanM
02-17-2010, 08:10 AM
Hi Spartacus,
Thanks for your comments. Below are a couple more links that should help.
NinjaTrader 7 Code Breaking Changes. (http://www.ninjatrader-support2.com/vb/showthread.php?t=21016)
Creating User Definable Color Inputs. (http://www.ninjatrader-support2.com/vb/showthread.php?t=4977)