NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-12-2012, 10:03 PM   #1
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default Coloring Chart Background Based on CrossOver

hi all, thanks in advance.

can anyone guide me on what code would look like coloring the background of a chart based on a simple average cross over? For example, when the 4 period SMA crosses above the 15 period SMA, the background turns green, and when it crosses under, the background turns red.

thanks

-osa
outstretchedarm is offline  
Reply With Quote
Old 06-12-2012, 10:19 PM   #2
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,183
Thanks: 178
Thanked 300 times in 258 posts
Default

http://www.ninjatrader.com/support/f...ckground+color


Quote:
Originally Posted by outstretchedarm View Post
hi all, thanks in advance.

can anyone guide me on what code would look like coloring the background of a chart based on a simple average cross over? For example, when the 4 period SMA crosses above the 15 period SMA, the background turns green, and when it crosses under, the background turns red.

thanks

-osa
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 06-13-2012, 04:46 AM   #3
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello osa,
Please use the BackColor property to color the chart background.
http://www.ninjatrader.com/support/h...?backcolor.htm

@sledge - Thanks for you input.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-13-2012, 10:58 AM   #4
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default

OK let me experiment with this a bit and then report back.

thanks for the link
outstretchedarm is offline  
Reply With Quote
The following user says thank you to outstretchedarm for this post:
Old 06-13-2012, 11:23 AM   #5
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default

Hmmm, not being a proficient coder by any means, I am running into tons of errors with the following code I put together:

Code:
		#region Variables
		private int					period	= 14;
		#endregion

		/// <summary>
		/// This method is used to configure the indicator and is called once before any bar data is loaded.
		/// </summary>
		protected override void Initialize()
		{
			Add(new Plot(Color.Orange, "BackColor1"));
		}

		/// <summary>
		/// Called on each bar update event (incoming tick)
		/// </summary>
		protected override void OnBarUpdate()
		{
			if (SMA(5)[0] > SMA(15)[0])
			{
			BackColor = Color.Green;
			}
		}
#region Properties
		/// <summary>
		/// </summary>
		[Description("Numbers of bars used for calculations")]
		[GridCategory("Parameters")]
		public int Period
		{
			get { return period; }
			set { period = Math.Max(2, value); }
		}
		#endregion
	}
}
Any advice?
outstretchedarm is offline  
Reply With Quote
Old 06-13-2012, 11:31 AM   #6
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello outstretchedarm,
Please refer to the attached code which paints the background green, when SMA 5 is greater than SMA 15.

Please let me know if I can assist you any further.
Attached Files
File Type: zip TestCode.zip (3.2 KB, 40 views)
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-20-2012, 07:47 PM   #7
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default

Sorry for the slow reply. Much thanks for this. I will experiment with it and if I learn anything, I will report back.
outstretchedarm is offline  
Reply With Quote
Old 07-05-2012, 11:20 PM   #8
zoom zoom 126
Junior Member
 
Join Date: May 2011
Posts: 13
Thanks: 0
Thanked 1 time in 1 post
Default

this test code works one the price panel, but what do i change to get it to print on panel 2 if i put an indicator there?
zoom zoom 126 is offline  
Reply With Quote
Old 07-06-2012, 04:04 AM   #9
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello zoom zoom 126,
You can use BackColorAll to color all the panes. Please refer to our help guided to know more about it.
http://www.ninjatrader.com/support/h...ckcolorall.htm
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 11-03-2012, 05:24 PM   #10
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default

I finally got around to experimenting with this, and I got the code that you provided to work. Thanks!

I thought I would get fancy and add an additional condition. I coded:

Code:
	if ((SMA(300)[0] > SMA(900)[0])
				& (SMA(1950)[0] > SMA(5850)[0]))
				BackColor = Color.Green;
However, it doesn't backcolor at all (I tried it on quite a few different instruments; one of them should have had a data history that met these two conditions).

Furthermore, I tried it with both the & and the && operators, and neither backcolored.

Any idea why?

Thanks in advance for any input. You guys are the greatest at customer service.
outstretchedarm is offline  
Reply With Quote
Old 11-03-2012, 05:53 PM   #11
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

Are you sure that condition is true? You might want to add some Print() statements to that block to see if that is returned to the Tools--> Output window


Also is that the exact code you're using? There are some syntax issues with it which I've corrected below:



Code:
			 	if (SMA(300)[0] > SMA(900)[0] && SMA(1950)[0] > SMA(5850)[0])
				{
				Print("Condition is true");
				BackColor = Color.Green;
				}
NinjaTrader_Matthew is offline  
Reply With Quote
Old 11-05-2012, 04:01 PM   #12
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default

Is there something about the SMA indicator that it won't work about a certain value?

I'm running:

if (SMA(1950)[0] > SMA(5850)[0])
BackColor = Color.Green;

and am never getting results. it is that parameters of over 1,000 are too high, and don't give results? Or perhaps there isn't enough historical data onhand to give the proper results? if so, how do you load up more historical data that goes back even further?
outstretchedarm is offline  
Reply With Quote
Old 11-06-2012, 04:00 AM   #13
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello outstretchedarm,
The SMA word work fine. Since you are using a very high number 5K+ to calculate the SMA, you must load more than 5K+ bars to get the correct SMA value.
  • Right click on the chart
  • In the context menu click on Data Series..
  • In the Data Series dialog set and appropriate value for the option "Days to load"

Please note, your connectivity provider/broker must provide historical data for such periods.

To assist you further may I know what periodicity chart you are applying the SMA indicator and how many days of data you are loading.
Attached Images
File Type: png Data Series Days to Load.png (52.1 KB, 13 views)
NinjaTrader_Joydeep is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Joydeep for this post:
Old 12-02-2012, 05:01 PM   #14
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
Default

wow, you guys are awesome. Increasing the days to load did the trick.

Regarding the other posters comment:

Quote:
this test code works one the price panel, but what do i change to get it to print on panel 2 if i put an indicator there?
I think he raises a good question. Let's say I wanted to have, in the lower graph, where I chart ADX, for example; could I have the lower graph background turn green when ADX is above 60?

This would be a nice development, in fact, if this were possible, I would eventually code everything such that once the background on each of my indicators turned green (because it met my conditions) I would simply pull the trigger on a trade.

Thanks in advance for any help.
outstretchedarm is offline  
Reply With Quote
Old 12-03-2012, 04:41 AM   #15
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello outstretchedarm,
You cannot do it via an Indicator. However if you have have added the ADX via a strategy then you can use the below code to set the background color of the ADX.

Code:
//In Initialze 
Add(ADX(14));

//in OnBarUpdate
if (ADX(14)[0] > 60)
{
	ADX(14).BackColor = Color.Green;
}
NinjaTrader_Joydeep 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
Coloring Based on Price Action matkiefer Indicator Development 5 02-07-2012 10:30 AM
Indicator-based chart background color? nescio Indicator Development 5 05-14-2009 07:16 AM
Condition Based Bar Coloring Elliott Wave Suggestions And Feedback 1 05-06-2009 05:23 PM
Coloring an indie panel background? 5iver Indicator Development 3 10-11-2008 07:40 AM
Coloring region based on time frame Huilin Indicator Development 4 09-04-2008 05:12 AM


All times are GMT -6. The time now is 01:16 AM.