NexusFi: Find Your Edge


Home Menu

 





opacity


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one SamirOfSalem with 7 posts (1 thanks)
    2. looks_two KySt with 6 posts (1 thanks)
    3. looks_3 forrestang with 1 posts (0 thanks)
    4. looks_4 Bullywig with 1 posts (0 thanks)
    1. trending_up 3,660 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 14 posts
    2. attach_file 4 attachments




 
Search this Thread

opacity

  #1 (permalink)
 
Bullywig's Avatar
 Bullywig 
Chicago
 
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader Brokerage
Trading: FDAX, NQ, HG, SI, CL
Posts: 68 since Oct 2015
Thanks Given: 42
Thanks Received: 22

I would like to add opacity control to this simple indicator. Can someone point me in the right direction. What do I need to add?

public class StochFilter : Indicator
{
private StochasticsFast StochasticsFast1;
private StochasticsFast StochasticsFast2;
private StochasticsFast StochasticsFast3;

protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "StochFilter";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
StochasticsFast1 = StochasticsFast(Close, 6, 13);
StochasticsFast2 = StochasticsFast(Close, 13, 25);
StochasticsFast3 = StochasticsFast(Close, 13, 25);
}
}

protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;

if (CurrentBars[0] < 0)
return;

// Set 1
if ((StochasticsFast1.D[0] > StochasticsFast2.D[0])
&& (StochasticsFast3.D[0] < 80)
&& (StochasticsFast3.D[0] > 20))
{
BackBrush = Brushes.Green;
}

// Set 2
if (StochasticsFast3.D[0] > 80)
{
BackBrush = Brushes.Green;
}

// Set 3
if ((StochasticsFast1.D[0] < StochasticsFast2.D[0])
&& (StochasticsFast3.D[0] < 80)
&& (StochasticsFast3.D[0] > 20))
{
BackBrush = Brushes.Maroon;
}

// Set 4
if (StochasticsFast3.D[0] < 20)
{
BackBrush = Brushes.Maroon;
}
}
}
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private StochFilter[] cacheStochFilter;
public StochFilter StochFilter()
{
return StochFilter(Input);
}

public StochFilter StochFilter(ISeries<double> input)
{
if (cacheStochFilter != null)
for (int idx = 0; idx < cacheStochFilter.Length; idx++)
if (cacheStochFilter[idx] != null && cacheStochFilter[idx].EqualsInput(input))
return cacheStochFilter[idx];
return CacheIndicator<StochFilter>(new StochFilter(), input, ref cacheStochFilter);
}
}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.StochFilter StochFilter()
{
return indicator.StochFilter(Input);
}

public Indicators.StochFilter StochFilter(ISeries<double> input )
{
return indicator.StochFilter(input);
}
}
}

namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.StochFilter StochFilter()
{
return indicator.StochFilter(Input);
}

public Indicators.StochFilter StochFilter(ISeries<double> input )
{
return indicator.StochFilter(input);
}
}
}

#endregion

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
Cheap historycal L1 data for stocks
Stocks and ETFs
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
Quant vue
Trading Reviews and Vendors
 
  #2 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44

Hi Bullywig.

See if using Color.FromArgb() works.

for example:

 
Code
Brush Red33percent = new SolidColorBrush(Color.FromArgb(33, 255, 0, 0));
Red33percent.Freeze();

BackBrush = Red33percent;


Brush Blue44percent = new SolidColorBrush(Color.FromArgb(44, 0, 0, 255));
Blue44percent.Freeze();

BackBrush = Blue44percent;
You might need to dispose() the brushess upon termination.

Reply With Quote
  #3 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24



SamirOfSalem View Post
Hi Bullywig.

See if using Color.FromArgb() works.

for example:

 
Code
Brush Red33percent = new SolidColorBrush(Color.FromArgb(33, 255, 0, 0));
Red33percent.Freeze();

BackBrush = Red33percent;


Brush Blue44percent = new SolidColorBrush(Color.FromArgb(44, 0, 0, 255));
Blue44percent.Freeze();

BackBrush = Blue44percent;
You might need to dispose() the brushess upon termination.

Good day Samir,
I don't code at all, but am trying to follow the logical here. I wish to add a line to an existing script and I want the line to have opacity values.

This works fine, but there's no opacity
AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);

I tried adding you input, but receive an error
AddLine(SolidColorBrushes(Color.FromArgb(33, 255, 0, 0)) 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);

Can you correct what ever I am doing incorrectly?

Thank you, Ky

Reply With Quote
  #4 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44


KySt View Post
Good day Samir,
I don't code at all, but am trying to follow the logical here. I wish to add a line to an existing script and I want the line to have opacity values.

This works fine, but there's no opacity
AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);

I tried adding you input, but receive an error
AddLine(SolidColorBrushes(Color.FromArgb(33, 255, 0, 0)) 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);

Can you correct what ever I am doing incorrectly?

Thank you, Ky

Hi Ky.

From what I can tell, you're missing:
- "new" before SolidColorBrushes, it should be AddLine( new SolidColorBrushes(Color.FromArgb(33, 255, 0, 0))
- a comma before the 0 you're using for a value: AddLine( new SolidColorBrushes(Color.FromArgb(33, 255, 0, 0)) , 0, ....)

See if that helps.

P.S. You probably already know this, but NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine is just a label. You can use any name you want for the line. So just to make it easier to follow the logic, replace it with "My Line" or "Ky's Line" etc. keeping the " " quotes.

Reply With Quote
  #5 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24


SamirOfSalem View Post
Hi Ky.

From what I can tell, you're missing:
- "new" before SolidColorBrushes, it should be AddLine( new SolidColorBrushes(Color.FromArgb(33, 255, 0, 0))
- a comma before the 0 you're using for a value: AddLine( new SolidColorBrushes(Color.FromArgb(33, 255, 0, 0)) , 0, ....)

See if that helps.

P.S. You probably already know this, but NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine is just a label. You can use any name you want for the line. So just to make it easier to follow the logic, replace it with "My Line" or "Ky's Line" etc. keeping the " " quotes.

Samir, thank you for replying.
I tried the syntax and get the following error:



Reply With Quote
  #6 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44


KySt View Post
Samir, thank you for replying.
I tried the syntax and get the following error:



LOL See what you made me do! I copy-pasted from your code

It's not SolidColorBrushes, just SolidColorBrush.

Try this:
 
Code
                AddLine(new SolidColorBrush(Color.FromArgb(33, 255, 0, 0)), 10, "Myline");
This should work, but just a couple of notes. I made the line value "10" because 0 would generate the line too close to a border, so you'll hardly see it. And also the colour choice above 33% of Red is hardly visible if you're using the default colours of NT. Once that line compiles okay for you, and you still can't see it, maybe try setting the chart's background to white or gray, etc.

Reply With Quote
  #7 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24


SamirOfSalem View Post
LOL See what you made me do! I copy-pasted from your code

It's not SolidColorBrushes, just SolidColorBrush.

Try this:
 
Code
                AddLine(new SolidColorBrush(Color.FromArgb(33, 255, 0, 0)), 10, "Myline");
This should work, but just a couple of notes. I made the line value "10" because 0 would generate the line too close to a border, so you'll hardly see it. And also the colour choice above 33% of Red is hardly visible if you're using the default colours of NT. Once that line compiles okay for you, and you still can't see it, maybe try setting the chart's background to white or gray, etc.

Thank you Samir.
This plots. One question, how do I change the opacity of the line? It is really a zone, so I enlarge the size of the line.



Reply With Quote
  #8 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44

Not sure "AddLine" is the best way to go for marking zones.

But if you must, and if this is the first line applied by your indicator, then add this next statement:

 
Code
Lines[0].Width = 5; //for a width of 5
second line would be [1],
third line would be [2],
and so on.

Reply With Quote
  #9 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24


SamirOfSalem View Post
Not sure "AddLine" is the best way to go for marking zones.

But if you must, and if this is the first line applied by your indicator, then add this next statement:

 
Code
Lines[0].Width = 5; //for a width of 5
second line would be [1],
third line would be [2],
and so on.

My apologies Samir
I was not clear. I wish to change the opacity of the line (something like LineColorOpacity = 40

Reply With Quote
  #10 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047



KySt View Post
My apologies Samir
I was not clear. I wish to change the opacity of the line (something like LineColorOpacity = 40

I dunno how to modify the opacity of a line... but you could draw a box with a height of 1 tic, and you could then have opacity control over it. Would that suit your needs?

Reply With Quote




Last Updated on November 22, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts