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 09-10-2017, 04:03 AM   #1
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default How hide \ show plot dynamically?

Hello.

I'd like to hide \ show plots dynamically while indicator working.

In NT7 this worked fine:
PHP Code:
if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color Color.Empty;
if( 
SMA1[0] > SMA2[0] ) Plots[0].Pen.Color Color.Black


In NT8 it not work.
And variant below not work too.

PHP Code:
Plots[0].Pen = new PenBrushes.Transparent);
Plots[0].Opacity 0;
Plots[0].Brush Vis.Empty_Brush;

OnRenderTargetChanged()
{
   
Plots[0].BrushDXBrushes.Empty.ToDxBrush();   
   
Plots[2].BrushDX = new DxSolidColorBrushRenderTarget, new Color40000) );



Is there any way to do it?
Last edited by fx.practic; 09-13-2017 at 02:25 PM.
fx.practic is offline  
Reply With Quote
Old 09-10-2017, 01:58 PM   #2
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 7,400
Thanks: 116
Thanked 1,630 times in 1,537 posts
Default

Hello fx.practic,

Set the Plot[index].Brush and then refresh with ForceRefresh().

Attached is an example.
Attached Files
File Type: zip HideShowPlotExample_NT8.zip (1.9 KB, 12 views)
NinjaTrader_ChelseaB is offline  
Reply With Quote
The following user says thank you to NinjaTrader_ChelseaB for this post:
Old 09-12-2017, 03:08 PM   #3
Zeos6
Senior Member
 
Join Date: Jan 2011
Posts: 510
Thanks: 13
Thanked 38 times in 33 posts
Default

Maybe I am missing something here, but can't you simply build your plots dynamicaly?
Just add them in the (State == State.Configure) and you can use variable to turn them on and off. Using InvokeAsync((Action) for this seems a bit of an overkill.
Zeos6 is offline  
Reply With Quote
Old 09-13-2017, 02:29 PM   #4
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default

Thanks a lot, Chelsea! Great example of lucidity.



Zeos6, I am don't quite understand how to do this with manipulations in the (State == State.Configure):
PHP Code:
if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color Color.Empty; 
if( 
SMA1[0] > SMA2[0] ) Plots[0].Pen.Color Color.Black
Also, I have idea to make checkbox, that hide \ show some plots.
Last edited by fx.practic; 09-13-2017 at 03:17 PM.
fx.practic is offline  
Reply With Quote
Old 09-13-2017, 03:22 PM   #5
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default

Need additional clarification: I trying to hide plot, with each dot colored with PlotBrushes[][].
And this method not work.

Is there any way to hide colored plot too?

Now I using SendKey(F5), but this is ugly.
fx.practic is offline  
Reply With Quote
Old 09-13-2017, 03:35 PM   #6
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 7,400
Thanks: 116
Thanked 1,630 times in 1,537 posts
Default

Hello fx.practic,

Yes, a single bar's plot color can be set with PlotBrushes[plot index][bars ago].

Are you setting this to Brushes.Transparent?

Are you getting an error?

Do you have an export of a reduced script to demonstrate?
Last edited by NinjaTrader_ChelseaB; 09-19-2017 at 03:27 PM.
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 09-13-2017, 04:05 PM   #7
Zeos6
Senior Member
 
Join Date: Jan 2011
Posts: 510
Thanks: 13
Thanked 38 times in 33 posts
Default

Hi fx.practic,

If you are trying to dynamically change plot colors on each point, have a look at the following thread:
http://ninjatrader.com/support/forum...ead.php?t=3227

There is a sample multi colored plot indicator from the NT Team, from JoshP. It will probably do what you are looking for.
Zeos6 is offline  
Reply With Quote
Old 09-16-2017, 12:29 AM   #8
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default

Zeos6: I mean not set color of one dot, but how to make transparent all dots of particular plot. Thank You for link.

Chelsea, let me clarify, what I tried.

Transparent color is
PHP Code:
Color.FromArgb0255255255 ); 
Empty color is
PHP Code:
Color.FromArgb000); 
Brushes don't contain Brushes.Empty, so I used
PHP Code:
Brush empty_brush = new SolidColorBrush(  Color.FromArgb000) );
empty_brush.Freeze(); 

No Brushes.Transparent, neither empty_brush work if:
PHP Code:
    Value[0] = Close[0];
    
PlotBrushes[0][0] = Brushes.Red
Can You advice me some new ways?
Attached Files
File Type: cs HideShowPlotExample.cs (5.5 KB, 6 views)
Last edited by fx.practic; 09-16-2017 at 12:32 AM.
fx.practic is offline  
Reply With Quote
Old 09-16-2017, 12:14 PM   #9
Zeos6
Senior Member
 
Join Date: Jan 2011
Posts: 510
Thanks: 13
Thanked 38 times in 33 posts
Default

Hi fx.practic,

I am really not sure what it is you are trying to accomplish. If you are trying to hide/show in real time, as your NT7 code seems to indicate, then the multicolored plot link I provided will work for you. If you are trying to show/hide at the start - during configuration, then my original suggestion will work.

EDIT: Have you tried something along the lines of ....

Code:
if(State == State.SetDefaults)
{
    AddPlot(Brushes.Blue, "SMA1");
    AddPlot(Brushes.Red, "SMA2");
     ...
}

protected override void OnBarUpdate()
{
    // Check that we have enough bars on our chart before processing
    if(CurrentBar < Period) 
        return;
            
     // Set the plots
    Values[0][0]     = SMA(High, Period)[0];     // SMA1
    Values[1][0]    = SMA(Low, Period)[0];       // SMA2

if (Values[0][0] > Values[1][0])
{
    // SMA1 > SMA2 code would set 
    // set SMA1 to lime and the SMA2 to transparent
                PlotBrushes[0][0] = Brushes.Lime;
                PlotBrushes[1][0] = Brushes.Transparent;
}
else if (Values[0][0] < Values[1][0]))
{
    // SMA1 < SMA2 code would set 
    // set SMA1 to transparent and the SMA2 to Purple
                PlotBrushes[0][0] = Brushes.Transparent;
                PlotBrushes[1][0] = Brushes.Purple;
}
else
{
    // SMA1 = SMA2 code would set 
    // set SMA1 to orchid and the SMA2 to green
                PlotBrushes[0][0] = Brushes.Orchid;
                PlotBrushes[1][0] = Brushes.Green;
}
    ...
}
Last edited by Zeos6; 09-16-2017 at 12:53 PM.
Zeos6 is offline  
Reply With Quote
Old 09-16-2017, 02:25 PM   #10
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default

Zeos6, let my explain what I need on this video:
https://monosnap.com/file/M1NByU2N5l...VvkhDeVMXsJouC
fx.practic is offline  
Reply With Quote
Old 09-16-2017, 03:33 PM   #11
Zeos6
Senior Member
 
Join Date: Jan 2011
Posts: 510
Thanks: 13
Thanked 38 times in 33 posts
Default

Oh OK. You want to show/hide your SMA using a button. Is that correct?

By the way, this is not what your NT7 code indicates.
if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color = Color.Empty;
if(
SMA1[0] > SMA2[0] ) Plots[0].Pen.Color = Color.Black;
Zeos6 is offline  
Reply With Quote
Old 09-17-2017, 02:59 PM   #12
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default

Zeos6, that is exactly what I want.
Yes, it work in NT7 in way You provide.
But, it not work in NT8 if:
PHP Code:
if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color Color.Empty; 
if( 
SMA1[0] > SMA2[0] ) Plots[0].Pen.Color Color.Black;

Brushes[0][0] = Brushes[1][0] = Brushes.Pink

And I need to hide multycolored plot in NT8.
Last edited by fx.practic; 09-17-2017 at 03:01 PM.
fx.practic is offline  
Reply With Quote
Old 09-18-2017, 01:47 PM   #13
Zeos6
Senior Member
 
Join Date: Jan 2011
Posts: 510
Thanks: 13
Thanked 38 times in 33 posts
Default

Hi fx.practic,

Attached is a simple skeleton code that does what you indicated you wanted. It's based off of what ChelseaB gave you. It works at my end. I am sure you can adapt it to your needs.
Attached Files
File Type: zip Hide_Show_Test.zip (3.4 KB, 2 views)
Zeos6 is offline  
Reply With Quote
Old 09-19-2017, 12:20 PM   #14
fx.practic
Senior Member
 
Join Date: Dec 2008
Location: Ukraine
Posts: 421
Thanks: 94
Thanked 41 times in 32 posts
Default

I didn't find the key row in Your code:
PHP Code:
PlotBrushes[0][0] = Brushes.Orange
Please, try this.
Attached Files
File Type: cs PB_Test.cs (5.4 KB, 1 views)
fx.practic is offline  
Reply With Quote
Old Yesterday, 06:45 AM   #15
Zeos6
Senior Member
 
Join Date: Jan 2011
Posts: 510
Thanks: 13
Thanked 38 times in 33 posts
Default

Hello fx.practic,

I am trying to help you but now I am confused again. The code I sent you does exactly what you showed in your video. I have no idea what you mean by

PlotBrushes[0][0] = Brushes.Orange;

and how that even comes into this discussion. Is this multi timeframe?
What exactly is it that you want to do? The information you have provided is contradictory.if you can clearly explain what you want I might be able to help you. As it stands now, I have no idea what the issue is.

Zeos6 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
Quickly Hide or Show Indicators traderharley Platform Technical Support 3 10-25-2016 02:41 PM
How do you show and hide properties in optimization? leocrespo Version 8 Beta 13 05-09-2016 02:03 PM
Show and hide a form according to external condition(s). xTrader1 NinjaScript File Sharing Discussion 0 06-18-2013 01:42 AM
Dynamically Hide/Show Indicators Turtle Trader Indicator Development 8 09-11-2011 01:30 PM
Option to show/Hide Indicators saliva Platform Technical Support 11 08-31-2010 03:37 AM


All times are GMT -6. The time now is 04:40 AM.

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.