/*
Reversal Bar by cunparis
This indicator will color a reversal bar grey.
It is designed to be used on range charts.
If you see a lot of grey bars then it could be consolidation.
If you see a lot of colored bars then price is moving nicely.
20100101 v1.0
First version. No alerts yet, I will add them later.
20100106 v1.1
Fixed problem with saving color parameters.
Added purple bars for consolidation
*/
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
namespace NinjaTrader.Indicator
{
[Description("ReversalBar_V2")] // Jan. 28, 2010, TheWizard added serialization to the colors so they will be saved if you change them & then save your template & re-load it
[Gui.Design.DisplayName("ReversalBar_V2")]
public class ReversalBar_V2 : Indicator // Changed the name to _V2 so as not to conflict with the original indicator posted by Cunparis.
{
private bool useAlerts = false;
private bool paintbar = true;
private Color colorUp = Color.Blue;
private Color colorDown = Color.Red;
private Color colorReversal = Color.Gray;
private Color colorCongestion = Color.Purple;
private int lastSoundBar = 0;
private DataSeries BarColorData;
protected override void Initialize()
{
Overlay = true;
PriceTypeSupported = false;
Panel = 1;
BarColorData = new DataSeries(this);
}
protected void doSetBarColor() {
if(Instrument.MasterInstrument.Compare(Close[1],Open[1]) == 1) {
if(Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 1) {
BarColorData.Set(1);
} else {
BarColorData.Set(0);
}
} else if(Instrument.MasterInstrument.Compare(Close[1],Open[1]) == -1) {
if(Instrument.MasterInstrument.Compare(Close[0], Open[0]) == -1) {
BarColorData.Set(-1);
} else {
BarColorData.Set(0);
}
}
bool overlap = false;
if(MAX(High, 5)[0] - MIN(Low,5)[0] < 2 * Bars.Period.Value * TickSize) {
//Print(Time[0] + " H=" + MAX(High, 5)[0] + " L=" + MIN(Low,5)[0]);
overlap = true;
}
if(MAX(High, 4)[0] - MIN(Low,4)[0] < 1.5 * Bars.Period.Value * TickSize) {
overlap = true;
}
if(BarColorData[0] == 1) {
BarColor = colorUp;
} else if(BarColorData[0] == -1) {
BarColor = colorDown;
} else if(BarColorData[0] == 0) {
if(overlap) {
BarColor = colorCongestion;
} else {
BarColor = colorReversal;
}
}
}
protected bool barOverlap(int i) {
if(Math.Abs(High[i] - High[i-1]) <= 2*TickSize && Math.Abs(Low[0] - Low[i-1]) <= 2*TickSize) {
return true;
} else {
return false;
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < 4) {
return;
}
if(paintbar) {
doSetBarColor();
}
}
// [Description("Use Audio Alerts?")]
// [Category("Parameters")]
// public bool UseAlerts
// {
// get { return useAlerts; }
// set { useAlerts = value; }
// }
[Description("Paint Bars?")]
[Category("Visual")]
[Gui.Design.DisplayName ("1. Paint Bars?")]
public bool Paintbar
{
get { return paintbar; }
set { paintbar = value; }
}
[XmlIgnore()]
[Description("Color Up")]
[Category("Visual")]
[Gui.Design.DisplayName ("2. Color Up")]
public Color ColorUp
{
get { return colorUp; }
set { colorUp = value; }
}
// Serialization of the colors added by TheWizard January 28, 2010
[Browsable(false)]
public string colorUpSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUp); }
set { colorUp = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
[XmlIgnore()]
[Description("Color Down")]
[Category("Visual")]
[Gui.Design.DisplayName ("3. Color Down")]
public Color ColorDown
{
get { return colorDown; }
set { colorDown = value; }
}
// Serialization of the colors added by TheWizard January 28, 2010
[Browsable(false)]
public string colorDownSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorDown); }
set { colorDown = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
[XmlIgnore()]
[Description("Color Reversal")]
[Category("Visual")]
[Gui.Design.DisplayName ("4. Color Reversal")]
public Color ColorReversal
{
get { return colorReversal; }
set { colorReversal = value; }
}
// Serialization of the colors added by TheWizard January 28, 2010
[Browsable(false)]
public string colorReversalSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorReversal); }
set { colorReversal = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
[XmlIgnore()]
[Description("Color Congestion")]
[Category("Visual")]
[Gui.Design.DisplayName ("5. Color Congestion")]
public Color ColorCongestion
{
get { return colorCongestion; }
set { colorCongestion = value; }
}
// Serialization of the colors added by TheWizard January 28, 2010
[Browsable(false)]
public string colorCongestionSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorCongestion); }
set { colorCongestion = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
}
}
#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 ReversalBar_V2[] cacheReversalBar_V2 = null;
private static ReversalBar_V2 checkReversalBar_V2 = new ReversalBar_V2();
/// <summary>
/// ReversalBar_V2
/// </summary>
/// <returns></returns>
public ReversalBar_V2 ReversalBar_V2()
{
return ReversalBar_V2(Input);
}
/// <summary>
/// ReversalBar_V2
/// </summary>
/// <returns></returns>
public ReversalBar_V2 ReversalBar_V2(Data.IDataSeries input)
{
if (cacheReversalBar_V2 != null)
for (int idx = 0; idx < cacheReversalBar_V2.Length; idx++)
if (cacheReversalBar_V2[idx].EqualsInput(input))
return cacheReversalBar_V2[idx];
lock (checkReversalBar_V2)
{
if (cacheReversalBar_V2 != null)
for (int idx = 0; idx < cacheReversalBar_V2.Length; idx++)
if (cacheReversalBar_V2[idx].EqualsInput(input))
return cacheReversalBar_V2[idx];
ReversalBar_V2 indicator = new ReversalBar_V2();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();
ReversalBar_V2[] tmp = new ReversalBar_V2[cacheReversalBar_V2 == null ? 1 : cacheReversalBar_V2.Length + 1];
if (cacheReversalBar_V2 != null)
cacheReversalBar_V2.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheReversalBar_V2 = 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>
/// ReversalBar_V2
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ReversalBar_V2 ReversalBar_V2()
{
return _indicator.ReversalBar_V2(Input);
}
/// <summary>
/// ReversalBar_V2
/// </summary>
/// <returns></returns>
public Indicator.ReversalBar_V2 ReversalBar_V2(Data.IDataSeries input)
{
return _indicator.ReversalBar_V2(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// ReversalBar_V2
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ReversalBar_V2 ReversalBar_V2()
{
return _indicator.ReversalBar_V2(Input);
}
/// <summary>
/// ReversalBar_V2
/// </summary>
/// <returns></returns>
public Indicator.ReversalBar_V2 ReversalBar_V2(Data.IDataSeries input)
{
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.ReversalBar_V2(input);
}
}
}
#endregion
Comment