I noticed that when I change the candle bar "up color" on this indicator, it always switches back to the default color after I restart Ninja Trader. Can you fix this perhaps? Again, I really appreciate this.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How do I determine if a bar closes at the top 25% of the bars range?
Collapse
X
-
Hi,
When you have changed the colours to the ones you want right click on the properties window and select save as defualt. You could also do it with code but this is the easiest way. Hope that helps.
Comment
-
@GKonheiser
Thanks but unfortunately that did not work. Would you happen to have the code for the fix?
Comment
-
Help
This is a great indicator, however the color bars always default to the down color as Red and the up color as blank. I always have to choose the up and down colors. Even If I save as default on the indicator, it still reverts back to this.
If anyone can please look at the code real quick and provide a fix I would appreciate it. I tried messing with it for 2 hours and have had no luck, but then again I am no coder. I'm sure it's a quick fix for the experienced.
Comment
-
-
Thanks GKonheiser, here you go:
#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>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
[Description("Color coding a reversal bar to show possible entry point.")]
public class aaScalpBar : Indicator
{
#region Variables
// Wizard generated variables
private double barPercent = 0.75; // default setting for bar range calculation
private Color upColor = Color.Green; // default up color candle
private Color dnColor = Color.Red; // default down color candle
// 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()
{
//
}
/// <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.
if(Close[0] >= Low[0] + barPercent*(High[0]-Low[0]))
{BarColor = UpColor;}
if(Close[0] <= High[0] - barPercent*(High[0]-Low[0]))
{BarColor = DnColor;}
}
#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 Plot0
{
get { return Values[0]; }
}
[Description("Percent range to color bars...a close above X percent will color up, a close below X % of the bar range will paint low.")]
[GridCategory("Parameters")]
public double BarPercent
{
get { return barPercent; }
set { barPercent = Math.Max(0, value); }
}
[Description("Color for up painted bars")]
[GridCategory("Parameters")]
public Color UpColor
{
get { return upColor; }
set { upColor = value; }
}
[XmlIgnore()]
[Description("Color for down painted bars")]
[GridCategory("Parameters")]
public Color DnColor
{
get { return dnColor; }
set { dnColor = 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 aaScalpBar[] cacheaaScalpBar = null;
private static aaScalpBar checkaaScalpBar = new aaScalpBar();
/// <summary>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
/// <returns></returns>
public aaScalpBar aaScalpBar(double barPercent, Color dnColor, Color upColor)
{
return aaScalpBar(Input, barPercent, dnColor, upColor);
}
/// <summary>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
/// <returns></returns>
public aaScalpBar aaScalpBar(Data.IDataSeries input, double barPercent, Color dnColor, Color upColor)
{
if (cacheaaScalpBar != null)
for (int idx = 0; idx < cacheaaScalpBar.Length; idx++)
if (Math.Abs(cacheaaScalpBar[idx].BarPercent - barPercent) <= double.Epsilon && cacheaaScalpBar[idx].DnColor == dnColor && cacheaaScalpBar[idx].UpColor == upColor && cacheaaScalpBar[idx].EqualsInput(input))
return cacheaaScalpBar[idx];
lock (checkaaScalpBar)
{
checkaaScalpBar.BarPercent = barPercent;
barPercent = checkaaScalpBar.BarPercent;
checkaaScalpBar.DnColor = dnColor;
dnColor = checkaaScalpBar.DnColor;
checkaaScalpBar.UpColor = upColor;
upColor = checkaaScalpBar.UpColor;
if (cacheaaScalpBar != null)
for (int idx = 0; idx < cacheaaScalpBar.Length; idx++)
if (Math.Abs(cacheaaScalpBar[idx].BarPercent - barPercent) <= double.Epsilon && cacheaaScalpBar[idx].DnColor == dnColor && cacheaaScalpBar[idx].UpColor == upColor && cacheaaScalpBar[idx].EqualsInput(input))
return cacheaaScalpBar[idx];
aaScalpBar indicator = new aaScalpBar();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.BarPercent = barPercent;
indicator.DnColor = dnColor;
indicator.UpColor = upColor;
Indicators.Add(indicator);
indicator.SetUp();
aaScalpBar[] tmp = new aaScalpBar[cacheaaScalpBar == null ? 1 : cacheaaScalpBar.Length + 1];
if (cacheaaScalpBar != null)
cacheaaScalpBar.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheaaScalpBar = 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>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.aaScalpBar aaScalpBar(double barPercent, Color dnColor, Color upColor)
{
return _indicator.aaScalpBar(Input, barPercent, dnColor, upColor);
}
/// <summary>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
/// <returns></returns>
public Indicator.aaScalpBar aaScalpBar(Data.IDataSeries input, double barPercent, Color dnColor, Color upColor)
{
return _indicator.aaScalpBar(input, barPercent, dnColor, upColor);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.aaScalpBar aaScalpBar(double barPercent, Color dnColor, Color upColor)
{
return _indicator.aaScalpBar(Input, barPercent, dnColor, upColor);
}
/// <summary>
/// Color coding a reversal bar to show possible entry point.
/// </summary>
/// <returns></returns>
public Indicator.aaScalpBar aaScalpBar(Data.IDataSeries input, double barPercent, Color dnColor, Color upColor)
{
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.aaScalpBar(input, barPercent, dnColor, upColor);
}
}
}
#endregion
Comment
-
Color change
In the region variables change :-
Code:private Color upColor = Color.Green; // default up color candle private Color dnColor = Color.Red; // default down color candle
Code:private Color dnColor = Color.Blue; // default down color candle
Let me know if you need more help. ; )
Comment
-
Hi GKonheiser,
So the interesting thing is that the default down bar color works fine, but the up color candle keeps defaulting to empty even though I choose a color from the list. Any ideas?
Comment
-
-
Yep, this is how the code is set but the up color bar still defaults to empty.
#region Variables
// Wizard generated variables
private double barPercent = 0.75; // default setting for bar range calculation
private Color upColor = Color.White; // default up color candle
private Color dnColor = Color.SteelBlue; // default down color candle
// User defined variables (add any user defined variables below)
#endregion
Comment
-
Originally posted by Volcom View PostYep, this is how the code is set but the up color bar still defaults to empty.
#region Variables
// Wizard generated variables
private double barPercent = 0.75; // default setting for bar range calculation
private Color upColor = Color.White; // default up color candle
private Color dnColor = Color.SteelBlue; // default down color candle
// User defined variables (add any user defined variables below)
#endregion
ref: http://ninjatrader.com/support/forum...ad.php?p=25038
Comment
-
It's actually easier than it may sound. Open your code. Scroll down to the section "Properties". Where you see your line of code for the up Color you add (you may have to substitute "public" with "private"):
// Serialize our Color object
[Browsable(false)]
public string upColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upColor); }
set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value);}
}
It should then look something like this:
// colors
[XmlIgnore()]
[Description("Color for Up")]
[GridCategory("Colors")]
public Color UpColor
{
get { return upColor; }
set { upColor = value; }
}
// Serialize our Color object
[Browsable(false)]
public string upColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upColor); }
set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
Then you repeat the same for your dn Color.
sandman
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment