![]() |
|
|
#1 |
|
Junior Member
Join Date: Feb 2008
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
|
I'm trying to change the color of the bars using a couple of simple rules. When I load it up the bars don't change color. Can you help me?
--------START CODE -------- #region Using declarations using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; 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> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> [Description("Gives brighter green when going up for sure, gives brighter red when going down the tube")] public class MoreDepthBars : Indicator { #region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 // 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() { double barClosePrice = Close[0]; double barOpenPrice = Open[0]; double barHighPrice = High[0]; double barLowPrice = Low[0]; Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0")); CalculateOnBarClose = true; Overlay = false; PriceTypeSupported = false; } /// <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 (Open[0] < Close[0]) {BarColor = Color.Green;} if (Open[0] < Close[0] && Close[0] > High[0]) {BarColor = Color.Lime;} if (Open[0] > Close[0]) {BarColor = Color.Maroon;} if (Open[0] > Close[0] && Close[0] < Low[0]) {BarColor = Color.Red;} if (Open[0] == Close[0]) {BarColor = Color.White;} Plot0.Set(Close[0]); } #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("")] [Category("Parameters")] public int MyInput0 { get { return myInput0; } set { myInput0 = 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 MoreDepthBars[] cacheMoreDepthBars = null; private static MoreDepthBars checkMoreDepthBars = new MoreDepthBars(); /// <summary> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> /// <returns></returns> public MoreDepthBars MoreDepthBars(int myInput0) { return MoreDepthBars(Input, myInput0); } /// <summary> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> /// <returns></returns> public MoreDepthBars MoreDepthBars(Data.IDataSeries input, int myInput0) { checkMoreDepthBars.MyInput0 = myInput0; myInput0 = checkMoreDepthBars.MyInput0; if (cacheMoreDepthBars != null) for (int idx = 0; idx < cacheMoreDepthBars.Length; idx++) if (cacheMoreDepthBars[idx].MyInput0 == myInput0 && cacheMoreDepthBars[idx].EqualsInput(input)) return cacheMoreDepthBars[idx]; MoreDepthBars indicator = new MoreDepthBars(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.Input = input; indicator.MyInput0 = myInput0; indicator.SetUp(); MoreDepthBars[] tmp = new MoreDepthBars[cacheMoreDepthBars == null ? 1 : cacheMoreDepthBars.Length + 1]; if (cacheMoreDepthBars != null) cacheMoreDepthBars.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheMoreDepthBars = tmp; Indicators.Add(indicator); 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> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.MoreDepthBars MoreDepthBars(int myInput0) { return _indicator.MoreDepthBars(Input, myInput0); } /// <summary> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> /// <returns></returns> public Indicator.MoreDepthBars MoreDepthBars(Data.IDataSeries input, int myInput0) { return _indicator.MoreDepthBars(input, myInput0); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.MoreDepthBars MoreDepthBars(int myInput0) { return _indicator.MoreDepthBars(Input, myInput0); } /// <summary> /// Gives brighter green when going up for sure, gives brighter red when going down the tube /// </summary> /// <returns></returns> public Indicator.MoreDepthBars MoreDepthBars(Data.IDataSeries input, int myInput0) { 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.MoreDepthBars(input, myInput0); } } } #endregion --------END CODE -------- |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Hi Infinity,
You will need to debug your code as per this tip here: http://www.ninjatrader-support.com/v...ead.php?t=3418 Also, generally you shouldn't declare these variables in the Initialize() method: Code:
protected override void Initialize()
{
double barClosePrice = Close[0];
double barOpenPrice = Open[0];
double barHighPrice = High[0];
double barLowPrice = Low[0];
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Feb 2008
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
|
Hey Josh,
it's been so long since I programmed anything I've forgotten all the basics! Where do you declare the variables? Basically the code is meant to change the color of the bar depending on the relationship between the current bar and previous bar's open, close, high and low. if (Open[0] < Close[0]) {BarColor = Color.Green;} if (Open[0] < Close[0] && Close[0] > High[0]) {BarColor = Color.Lime;} if (Open[0] > Close[0]) {BarColor = Color.Maroon;} if (Open[0] > Close[0] && Close[0] < Low[0]) {BarColor = Color.Red;} if (Open[0] == Close[0]) {BarColor = Color.White;} |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Generally you would just declare them as privates inside the "Variables" section which is above the Initialize() method.
Code:
private double var1 = 2.5;
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using BarColor, candles lose outline color | JangoFolly | Indicator Development | 9 | 02-15-2008 08:59 AM |
| NT6 BarColor | guym | Indicator Development | 2 | 11-27-2006 09:51 AM |