Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
hide a plot on condition
Updated July 1, 2012
trending_up
4,474 views
thumb_up
2 thanks given
group
2 followers
forum
5 posts
attach_file
0 attachments
hide a plot on condition
June 29th, 2012, 07:01 AM
London, UK
Experience: Intermediate
Platform: ninja,TS,Meta,Tradeguider
Trading: FX,Metals
Posts: 38 since Sep 2011
Thanks Given: 9
Thanks Received: 6
Hi
i want to get the commented out section working ie. only plot if a condition is not met. Ive tried ShortProfitTarget.Reset(); but i cant see how to make the plot transparent , any ideas or an example appreciated
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
LongProfitTarget.Set(Close[0]+ATR (5)[0]);
ShortProfitTarget.Set(Close[0]-ATR(5)[0]);
// if ((SMA (18)[0] >= SMA(18)[1]
// && SMA(9)[0] >= SMA(9)[1])
// && (SMA(18)[1] < SMA(18)[2] ||
// SMA(9)[1] < SMA(9)[2])
// && (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
//// PlotColors[0][0] = Color.Transparent;
//
// if ((SMA(18)[0] <= SMA(18)[1]
// && SMA(9)[0] <= SMA(9)[1])
// && (SMA(18)[1] > SMA(18)[2] ||
// SMA(9)[1] > SMA(9)[2])
// && (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
//// PlotColors[1][0] = Color.Transparent;
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
June 29th, 2012, 07:42 AM
Northern Germany
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824
solondon
Hi
i want to get the commented out section working ie. only plot if a condition is not met. Ive tried ShortProfitTarget.Reset(); but i cant see how to make the plot transparent , any ideas or an example appreciated
Could you perhaps describe what exactly is not working?
Also: please post the complete code, that makes it easier, and wrap code tags around it like:
Code
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
LongProfitTarget.Set(Close[0]+ATR(5)[0]);
ShortProfitTarget.Set(Close[0]-ATR(5)[0]);
// if ((SMA(18)[0] >= SMA(18)[1]
// && SMA(9)[0] >= SMA(9)[1])
// && (SMA(18)[1] < SMA(18)[2] ||
// SMA(9)[1] < SMA(9)[2])
// && (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
//// PlotColors[0][0] = Color.Transparent;
//
// if ((SMA(18)[0] <= SMA(18)[1]
// && SMA(9)[0] <= SMA(9)[1])
// && (SMA(18)[1] > SMA(18)[2] ||
// SMA(9)[1] > SMA(9)[2])
// && (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
//// PlotColors[1][0] = Color.Transparent;
}
vvhg
June 29th, 2012, 08:05 AM
London, UK
Experience: Intermediate
Platform: ninja,TS,Meta,Tradeguider
Trading: FX,Metals
Posts: 38 since Sep 2011
Thanks Given: 9
Thanks Received: 6
Hi
the following plots nothing
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class aaPipMaximizer1ProfitTarget : Indicator
{
#region Variables
// Wizard generated variables
private int aTRperiod = 5; // Default setting for ATRperiod
// User defined variables (add any user defined variables below)
#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.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
LongProfitTarget.Set(Close[0]+ATR(5)[0]);
ShortProfitTarget.Set(Close[0]-ATR(5)[0]);
if ((SMA(18)[0] >= SMA(18)[1]
&& SMA(9)[0] >= SMA(9)[1])
&& (SMA(18)[1] < SMA(18)[2] ||
SMA(9)[1] < SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
PlotColors[0][0] = Color.MediumBlue;
else
// LongProfitTarget.Reset();
PlotColors[0][0] = Color.Transparent;
//
if ((SMA(18)[0] <= SMA(18)[1]
&& SMA(9)[0] <= SMA(9)[1])
&& (SMA(18)[1] > SMA(18)[2] ||
SMA(9)[1] > SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
PlotColors[0][0] = Color.Orange;
else
// ShortProfitTarget.Reset();
PlotColors[1][0] = Color.Transparent;
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries LongProfitTarget
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries ShortProfitTarget
{
get { return Values[1]; }
}
[Description("")]
[GridCategory("Parameters")]
public int ATRperiod
{
get { return aTRperiod; }
set { aTRperiod = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private aaPipMaximizer1ProfitTarget[] cacheaaPipMaximizer1ProfitTarget = null;
private static aaPipMaximizer1ProfitTarget checkaaPipMaximizer1ProfitTarget = new aaPipMaximizer1ProfitTarget();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
{
return aaPipMaximizer1ProfitTarget(Input, aTRperiod);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
{
if (cacheaaPipMaximizer1ProfitTarget != null)
for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
return cacheaaPipMaximizer1ProfitTarget[idx];
lock (checkaaPipMaximizer1ProfitTarget)
{
checkaaPipMaximizer1ProfitTarget.ATRperiod = aTRperiod;
aTRperiod = checkaaPipMaximizer1ProfitTarget.ATRperiod;
if (cacheaaPipMaximizer1ProfitTarget != null)
for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
return cacheaaPipMaximizer1ProfitTarget[idx];
aaPipMaximizer1ProfitTarget indicator = new aaPipMaximizer1ProfitTarget();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.ATRperiod = aTRperiod;
Indicators.Add(indicator);
indicator.SetUp();
aaPipMaximizer1ProfitTarget[] tmp = new aaPipMaximizer1ProfitTarget[cacheaaPipMaximizer1ProfitTarget == null ? 1 : cacheaaPipMaximizer1ProfitTarget.Length + 1];
if (cacheaaPipMaximizer1ProfitTarget != null)
cacheaaPipMaximizer1ProfitTarget.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheaaPipMaximizer1ProfitTarget = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
{
return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
{
return _indicator.aaPipMaximizer1ProfitTarget(input, aTRperiod);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
{
return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.aaPipMaximizer1ProfitTarget(input, aTRperiod);
}
}
}
#endregion
if I remove the conditional attempt to make the plots transparent the code works but i get a plot above and bellow for each bar. ie. this section is causing both plots to hide for every bar
if ((SMA (18)[0] >= SMA(18)[1]
&& SMA(9)[0] >= SMA(9)[1])
&& (SMA(18)[1] < SMA(18)[2] ||
SMA(9)[1] < SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
PlotColors[0][0] = Color.MediumBlue;
else
// LongProfitTarget.Reset();
PlotColors[0][0] = Color.Transparent;
what i want is to only show the plot if the condition is met, i want it to show above my entry condition bar
Sorry the logic doesnt look great but im not a great programmer.
thanks in advance
June 29th, 2012, 08:26 AM
Northern Germany
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824
solondon
Hi
the following plots nothing
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class aaPipMaximizer1ProfitTarget : Indicator
{
#region Variables
// Wizard generated variables
private int aTRperiod = 5; // Default setting for ATRperiod
// User defined variables (add any user defined variables below)
#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.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
LongProfitTarget.Set(Close[0]+ATR(5)[0]);
ShortProfitTarget.Set(Close[0]-ATR(5)[0]);
if ((SMA(18)[0] >= SMA(18)[1]
&& SMA(9)[0] >= SMA(9)[1])
&& (SMA(18)[1] < SMA(18)[2] ||
SMA(9)[1] < SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
PlotColors[0][0] = Color.MediumBlue;
else
// LongProfitTarget.Reset();
PlotColors[0][0] = Color.Transparent;
//
if ((SMA(18)[0] <= SMA(18)[1]
&& SMA(9)[0] <= SMA(9)[1])
&& (SMA(18)[1] > SMA(18)[2] ||
SMA(9)[1] > SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
PlotColors[0][0] = Color.Orange;
else
// ShortProfitTarget.Reset();
PlotColors[1][0] = Color.Transparent;
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries LongProfitTarget
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries ShortProfitTarget
{
get { return Values[1]; }
}
[Description("")]
[GridCategory("Parameters")]
public int ATRperiod
{
get { return aTRperiod; }
set { aTRperiod = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private aaPipMaximizer1ProfitTarget[] cacheaaPipMaximizer1ProfitTarget = null;
private static aaPipMaximizer1ProfitTarget checkaaPipMaximizer1ProfitTarget = new aaPipMaximizer1ProfitTarget();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
{
return aaPipMaximizer1ProfitTarget(Input, aTRperiod);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
{
if (cacheaaPipMaximizer1ProfitTarget != null)
for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
return cacheaaPipMaximizer1ProfitTarget[idx];
lock (checkaaPipMaximizer1ProfitTarget)
{
checkaaPipMaximizer1ProfitTarget.ATRperiod = aTRperiod;
aTRperiod = checkaaPipMaximizer1ProfitTarget.ATRperiod;
if (cacheaaPipMaximizer1ProfitTarget != null)
for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
return cacheaaPipMaximizer1ProfitTarget[idx];
aaPipMaximizer1ProfitTarget indicator = new aaPipMaximizer1ProfitTarget();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.ATRperiod = aTRperiod;
Indicators.Add(indicator);
indicator.SetUp();
aaPipMaximizer1ProfitTarget[] tmp = new aaPipMaximizer1ProfitTarget[cacheaaPipMaximizer1ProfitTarget == null ? 1 : cacheaaPipMaximizer1ProfitTarget.Length + 1];
if (cacheaaPipMaximizer1ProfitTarget != null)
cacheaaPipMaximizer1ProfitTarget.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheaaPipMaximizer1ProfitTarget = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
{
return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
{
return _indicator.aaPipMaximizer1ProfitTarget(input, aTRperiod);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
{
return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.aaPipMaximizer1ProfitTarget(input, aTRperiod);
}
}
}
#endregion
if I remove the conditional attempt to make the plots transparent the code works but i get a plot above and bellow for each bar. ie. this section is causing both plots to hide for every bar
if ((
SMA (18)[0] >= SMA(18)[1]
&& SMA(9)[0] >= SMA(9)[1])
&& (SMA(18)[1] < SMA(18)[2] ||
SMA(9)[1] < SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
PlotColors[0][0] = Color.MediumBlue;
else
// LongProfitTarget.Reset();
PlotColors[0][0] = Color.Transparent;
what i want is to only show the plot if the condition is met, i want it to show above my entry condition bar
Sorry the logic doesnt look great but im not a great programmer.
thanks in advance
OK, that happens because you set the color to transparent when the condition is met, but you don't change it back when the condition doesn't apply anymore. Though i think this will result in the entire plot being either visible or not, and not hiding parts of it (but I'm not sure).
Perhaps you want to have a look at the supertrend indy as that plot might be something similar (in principle) than what you try to achieve, if not, have a look at indicators in the download section for a plot that is similar to what you want and then have a look in the code how it is done...
vvhg
July 1st, 2012, 07:13 AM
London, UK
Experience: Intermediate
Platform: ninja,TS,Meta,Tradeguider
Trading: FX,Metals
Posts: 38 since Sep 2011
Thanks Given: 9
Thanks Received: 6
actually my code want working due to a failure to check for enough bars CurrentBar > 20 , thanks for the help anyway
Last Updated on July 1, 2012