![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
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 |
|
|
|
|
|
#2 | |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,183
Thanks: 178
Thanked 300 times in 258 posts
|
http://www.ninjatrader.com/support/f...ckground+color
Quote:
|
|
|
|
|
|
The following user says thank you to sledge for this post: |
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
OK let me experiment with this a bit and then report back.
thanks for the link |
|
|
|
|
The following user says thank you to outstretchedarm for this post: |
|
|
|
#5 |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
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
}
}
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
Sorry for the slow reply. Much thanks for this. I will experiment with it and if I learn anything, I will report back.
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: May 2011
Posts: 13
Thanks: 0
Thanked 1 time in 1 post
|
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?
|
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
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; 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. |
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
|
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;
}
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
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? |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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.
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.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Joydeep for this post: |
|
|
|
#14 | |
|
Senior Member
Join Date: Jun 2011
Posts: 118
Thanks: 10
Thanked 3 times in 3 posts
|
wow, you guys are awesome. Increasing the days to load did the trick.
Regarding the other posters comment: Quote:
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. |
|
|
|
|
|
|
#15 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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;
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |