Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Indicator Development

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

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 08-17-2015, 09:01 PM   #1
dontpanic
Senior Member
 
Join Date: Dec 2010
Location: brisbane, Australia
Posts: 243
Thanks: 18
Thanked 5 times in 5 posts
Default NT8 color to Brush conversion with Opacity

Hi,

in NT7 I have

private Color hldCandleOutlineColour;
private Color hlCandleOutlineColour;
private int hlOpacityOL = 120;

and

hldCandleOutlineColour = Color.FromArgb(HLOpacityOL , hlCandleOutlineColour);

which applies an opacity to the color.

Whats the correct way to do this in NT8? I've seen the solidcolorbrush() example, but that doesn't use opacity and the Brush.Opacity property doesnt seem to exist.

thanks,
will.
dontpanic is offline  
Reply With Quote
Old 08-18-2015, 07:03 AM   #2
koganam
Senior Member
 
Join Date: Feb 2008
Location: omegasigmaindicators.com
Posts: 7,181
Thanks: 56
Thanked 2,989 times in 2,417 posts
Default

Quote:
Originally Posted by dontpanic View Post
Hi,

in NT7 I have

private Color hldCandleOutlineColour;
private Color hlCandleOutlineColour;
private int hlOpacityOL = 120;

and

hldCandleOutlineColour = Color.FromArgb(HLOpacityOL , hlCandleOutlineColour);

which applies an opacity to the color.

Whats the correct way to do this in NT8? I've seen the solidcolorbrush() example, but that doesn't use opacity and the Brush.Opacity property doesnt seem to exist.

thanks,
will.
Brush has an Opacity property, range 0 to 1.

ref: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
https://www.google.com/search?num=10...h.opacity+c%23
Last edited by koganam; 08-18-2015 at 07:06 AM.
koganam is offline  
Reply With Quote
Old 08-18-2015, 10:34 AM   #3
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello dontpanic,

As koganam mentioned brushes have an opacity property.

Try:

CandleOutlineBrush = Brushes.Blue;
CandleOutlineBrush.Opacity = 1;
NinjaTrader_ChelseaB is offline  
Reply With Quote
The following user says thank you to NinjaTrader_ChelseaB for this post:
Old 08-18-2015, 09:31 PM   #4
dontpanic
Senior Member
 
Join Date: Dec 2010
Location: brisbane, Australia
Posts: 243
Thanks: 18
Thanked 5 times in 5 posts
Default

Thanks guys,

I had actually tried that yesterday and was getting compile errors saying that Opacity wasn't a property, maybe I had brush mixed up with brushes or something, but I was also getting other strange errors trying to use Color.FromArbg() saying that there was no overload for 2 parameters, which is rubbish, so I'm not sure what was going on.

Anyway, I rewrote all the code as suggested and its compiling ok now, so thanks.

Will.
dontpanic is offline  
Reply With Quote
Old 01-03-2016, 10:28 AM   #5
schranzi9
Member
 
Join Date: Feb 2013
Posts: 62
Thanks: 0
Thanked 5 times in 5 posts
Default

Hello Trader, I also want to use the opacity for the background color but the opacity want not work in my chart version NT8.0.0.7 beta: (no error in the compiler)

BackBrush = Brushes.Blue;
BackBrush.Opacity = 0.5;

thanks for helping.
schranzi9 is offline  
Reply With Quote
Old 01-21-2016, 11:50 AM   #6
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello schranzi9,

You are probably getting a run time error that the opacity is read only.

Try adding the following to OnBarUpdate()

BackBrush = Brushes.Green;
Brush newBrush = BackBrush.Clone();
newBrush.Opacity = 0.25;
newBrush.Freeze();
BackBrush = newBrush;
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 11-28-2016, 11:55 AM   #7
sbgtrading
Certified NinjaScript Consultant
 
Join Date: Oct 2007
Location: Northern Illinois
Posts: 271
Thanks: 3
Thanked 19 times in 10 posts
Default

Does anyone have a solution for this background opacity issue? I've tried the technique listed in this thread, but it's not working. And this appears to be the most recent thread on the subject.

Any help would be appreciated...I'm not able to change the Opacity of the BackBrush.
sbgtrading is offline  
Reply With Quote
Old 11-28-2016, 04:23 PM   #8
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello sbgtrading,

How do you know this is not working?

Are you getting an error message?

I have tested this exact code by copying and pasting this into a new indicator in the OnBarUpdate method 'as is'.

I am not able reproduce an error and I am showing that for each bar, the back color is being changed to have opacity.
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 11-28-2016, 06:11 PM   #9
eDanny
Vendor
 
eDanny's Avatar
 
Join Date: Jul 2008
Location: East Rochester, NY
Posts: 1,249
Thanks: 15
Thanked 172 times in 141 posts
Default

If you are going to frequently change the background color you may run into the dreaded error from creating too many brushes. Best to create your different colored brushes with opacity in State.Configure and then switch between the brushes in OBU.
eDanny
NinjaTrader Ecosystem Vendor - Integrity Traders
eDanny is offline  
Reply With Quote
The following user says thank you to eDanny for this post:
Old 11-29-2016, 08:20 AM   #10
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello,

eDanny is correct here. The short bit of code I've shared is a quick example of how the back color would be changed.
It is best to declare a Brush variable within the scope of the class instead of within the scope of the method so this variable is reused instead of recreated. The creation of too many brushes will result in an error.
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 12-01-2016, 08:00 PM   #11
sbgtrading
Certified NinjaScript Consultant
 
Join Date: Oct 2007
Location: Northern Illinois
Posts: 271
Thanks: 3
Thanked 19 times in 10 posts
Default

Thanks Chelsea...it appears to be working now.

I had changed the code last week (I'm coloring the background myself in OnRender)...so unfortunately I don't have the exact code I used when I got the error. I think I may have been attempting to change the opacity value of the BackBrush directly, in OnBarUpdate.

I've tested it now, using a secondary custom brush, setting its opacity beforehand in the State==Historical block, and then cloning that brush in an assignment to the BackBrush. That's working now.

It would be a bit more trouble if I had to set the opacity differently on each background stripe. But then that's what OnRender and RenderTarget.FillRectangle() would be for, I assume.

Thanks for your help!
sbgtrading is offline  
Reply With Quote
Old 03-27-2017, 05:15 AM   #12
turbofib
Senior Member
 
Join Date: Sep 2013
Posts: 362
Thanks: 129
Thanked 5 times in 5 posts
Default

hi, i want implement in my indicator...

Quote:

else if (State == State.Configure)
{
alpha = 25 * opacity;

BackBrush = Brushes.Green;
Brush newBrush = BackBrush.Clone();
newBrush.Opacity = alpha;

newBrush.Freeze();

BackBrush = newBrush;

}
but in newBrush.Freeze(); i get an error :

https://gyazo.com/469df58185139bda346689ad6f781faa
turbofib is offline  
Reply With Quote
Old 03-27-2017, 11:31 AM   #13
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello turbofib,

You are attempting to change the color of background of a specific bar before any of the bars have loaded.

This is not going to work until there is a bar to change the background color behind in OnBarUpdate.
http://ninjatrader.com/support/helpG.../backbrush.htm

You may be wanting to set the ChartControl.Properties.ChartBackground.
http://ninjatrader.com/support/helpG...properties.htm

Wait until DataLoaded before doing this.
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 03-27-2017, 11:45 AM   #14
turbofib
Senior Member
 
Join Date: Sep 2013
Posts: 362
Thanks: 129
Thanked 5 times in 5 posts
Default

excuse me...
I made confusion regarding class BackBrush

i want to change opacity of the candle...

i've code :
Quote:

else if (State == State.Configure)
{
alpha = 25 * opacity;

newBrush = BarBrush.Clone();
newBrush.Opacity = alpha;
newBrush.Freeze();

}
but it give me error because in State.Configure BarBrush....it not exist

Can you help me?
turbofib is offline  
Reply With Quote
Old 03-27-2017, 01:17 PM   #15
koganam
Senior Member
 
Join Date: Feb 2008
Location: omegasigmaindicators.com
Posts: 7,181
Thanks: 56
Thanked 2,989 times in 2,417 posts
Default

Quote:
Originally Posted by turbofib View Post
excuse me...
I made confusion regarding class BackBrush

i want to change opacity of the candle...

i've code :


but it give me error because in State.Configure BarBrush....it not exist

Can you help me?
If you need to do anything to bars, you need to do it after bars have been loaded. The earliest stage at which bars are loaded is State.DataLoaded. Your particular situation should work in that state or any state after that.
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
Reply

Tags
brush opacity

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
BUG: Exception raised when dynamically changing plot color (brush) strategesis Version 8 Beta 9 07-21-2016 07:45 PM
SharpDX Brush/Color inconsistency gregid Version 8 Beta 13 07-13-2016 11:29 PM
NT7 to NT8 data conversion error James108 Version 8 Beta 1 07-01-2015 06:56 AM
How to add color input in NT8 JerryWar Version 8 Beta 8 06-17-2015 08:16 AM
NT8.002 How to Change ChartStyle Default Brush Colors? RJay Version 8 Beta 3 05-29-2015 05:19 PM


All times are GMT -6. The time now is 07:20 PM.

Futures, foreign currency and options 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.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.