Created
June 8, 2015 13:30
-
-
Save bboyle1234/48bf29f908d9eef31707 to your computer and use it in GitHub Desktop.
BarStyleSettings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NinjaTrader.Gui.Design; | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Diagnostics; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.Xml.Serialization; | |
using DisplayName = NinjaTrader.Gui.Design.DisplayNameAttribute; | |
namespace NinjaTrader.Indicator { | |
public enum TrailingShadowMode { | |
Off = 0, | |
AutomaticSize = 1, | |
ManualSize = 2, | |
} | |
public enum BarStyle { | |
Candle = 0, | |
OHLC = 1, | |
} | |
/// <summary> | |
/// This indicator is added automatically to charts by the object responsible for actually painting | |
/// diagnostic bars on the chart. It is used to provide the user with extra display settings. | |
/// </summary> | |
public class BarStyleSettings : SolidIndicator, ICustomTypeDescriptor { | |
const string category_StyleAndColor = " 02. Style and color"; | |
const string category_TrailingShadows = " 03. Trailing shadows"; | |
public BarStyleSettings() { | |
BarStyle = NinjaTrader.Indicator.BarStyle.Candle; | |
Candle_UpColor = Color.Green; | |
Candle_DownColor = Color.Red; | |
Candle_UpWickColor = Color.Black; | |
Candle_DownWickColor = Color.Black; | |
OHLC_NoShadow_UpColor = Color.Green; | |
OHLC_NoShadow_DownColor = Color.Red; | |
OHLC_Shadow_UpShadowColor = Color.Green; | |
OHLC_Shadow_DownShadowColor = Color.Red; | |
OHLC_Shadow_UpBarColor = Color.Black; | |
OHLC_Shadow_DownBarColor = Color.Black; | |
TrailingShadowMode = NinjaTrader.Indicator.TrailingShadowMode.AutomaticSize; | |
TrailingShadowSizeTicks = 12; | |
TrailingShadowSizeMultiplier = 1; | |
} | |
#region Settings | |
#region 02. Style and color | |
#region Style | |
/// <summary> | |
/// Gets a value indicating whether the bars should be drawn with candles or OHLC | |
/// </summary> | |
[RefreshProperties(RefreshProperties.All)] | |
[Category(category_StyleAndColor)] | |
[NinjaTrader.Gui.Design.DisplayName("01. Style")] | |
[Description("Selects the style used for drawing the price bars")] | |
public BarStyle BarStyle { get; set; } | |
#endregion | |
#region Candle bar style properties | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("02. Up color")] | |
[Description("Color for the interior body of up candles")] | |
public Color Candle_UpColor { get; set; } | |
[Browsable(false)] | |
public int Candle_UpColor_Serializable { get { return Candle_UpColor.ToArgb(); } set { Candle_UpColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("03. Down color")] | |
[Description("Color for the interior body of down candles")] | |
public Color Candle_DownColor { get; set; } | |
[Browsable(false)] | |
public int Candle_DownColor_Serializable { get { return Candle_DownColor.ToArgb(); } set { Candle_DownColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("04. Up wick color")] | |
[Description("Color for the wick and outline of up candles")] | |
public Color Candle_UpWickColor { get; set; } | |
[Browsable(false)] | |
public int Candle_UpWickColor_Serializable { get { return Candle_UpWickColor.ToArgb(); } set { Candle_UpWickColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("05. Down wick color")] | |
[Description("Color for the wick and outline of down candles")] | |
public Color Candle_DownWickColor { get; set; } | |
[Browsable(false)] | |
public int Candle_DownWickColor_Serializable { get { return Candle_DownWickColor.ToArgb(); } set { Candle_DownWickColor = Color.FromArgb(value); } } | |
#endregion | |
#region OHLC bar style properties | |
#region These properties are used when there is no shadow | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("02. Up color")] | |
[Description("Color for OHLC up bars")] | |
public Color OHLC_NoShadow_UpColor { get; set; } | |
[Browsable(false)] | |
public int OHLC_NoShadow_UpColor_Serializable { get { return OHLC_NoShadow_UpColor.ToArgb(); } set { OHLC_NoShadow_UpColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("03. Down color")] | |
[Description("Color for OHLC down bars")] | |
public Color OHLC_NoShadow_DownColor { get; set; } | |
[Browsable(false)] | |
public int OHLC_NoShadow_DownColor_Serializable { get { return OHLC_NoShadow_DownColor.ToArgb(); } set { OHLC_NoShadow_DownColor = Color.FromArgb(value); } } | |
#endregion | |
#region These properties are used when there is shadow | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("02. Up shadow color")] | |
[Description("Sets the shadow color for up bars")] | |
public Color OHLC_Shadow_UpShadowColor { get; set; } | |
[Browsable(false)] | |
public int OHLC_Shadow_UpShadowColor_Serializable { get { return OHLC_Shadow_UpShadowColor.ToArgb(); } set { OHLC_Shadow_UpShadowColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("03. Down shadow color")] | |
[Description("Sets the shadow color for down bars")] | |
public Color OHLC_Shadow_DownShadowColor { get; set; } | |
[Browsable(false)] | |
public int OHLC_Shadow_DownShadowColor_Serializable { get { return OHLC_Shadow_DownShadowColor.ToArgb(); } set { OHLC_Shadow_DownShadowColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("04. Up bar color")] | |
[Description("Sets the bar color for up bars with a shadow")] | |
public Color OHLC_Shadow_UpBarColor { get; set; } | |
[Browsable(false)] | |
public int OHLC_Shadow_UpBarColor_Serializable { get { return OHLC_Shadow_UpBarColor.ToArgb(); } set { OHLC_Shadow_UpBarColor = Color.FromArgb(value); } } | |
[XmlIgnore] | |
[Category(category_StyleAndColor)] | |
[DisplayName("05. Down bar color")] | |
[Description("Sets the bar color for down bars with a shadow")] | |
public Color OHLC_Shadow_DownBarColor { get; set; } | |
[Browsable(false)] | |
public int OHLC_Shadow_DownBarColor_Serializable { get { return OHLC_Shadow_DownBarColor.ToArgb(); } set { OHLC_Shadow_DownBarColor = Color.FromArgb(value); } } | |
#endregion | |
#endregion | |
#endregion | |
#region 03. Trailing Shadows | |
// trailing shadows are used by the object drawing diagnostic bars (v2, continuum, etc) to add a shadow | |
// to make them look and feel like the first version of diagnostic bars that we ever produced. | |
#region TrailingShadowMode | |
[RefreshProperties(RefreshProperties.All)] | |
[Category(category_TrailingShadows)] | |
[NinjaTrader.Gui.Design.DisplayName("01. Mode")] | |
[Description("Selects the mode used for determining Trailing Shadow size.\r\n'Off' removes the shadows.\r\n'Automatic' draws shadows in proportion to the bar size.\r\n'Manual' lets you set the shadow size in ticks")] | |
public TrailingShadowMode TrailingShadowMode { get; set; } | |
#endregion | |
#region TrailingShadowSizeTicks | |
int trailingShadowSizeTicks; | |
[Category(category_TrailingShadows)] | |
[NinjaTrader.Gui.Design.DisplayName("02. Manual shadow size (ticks)")] | |
[Description("Trailing shadow size in ticks. Requires ManualSize mode.\r\nLarger value results in a larger shadow size.")] | |
public int TrailingShadowSizeTicks { | |
get { return trailingShadowSizeTicks; } | |
set { trailingShadowSizeTicks = Math.Max(1, value); } | |
} | |
#endregion | |
#region TrailingShadowSizeMultiplier | |
double trailingShadowSizeMultiplier; | |
[Category(category_TrailingShadows)] | |
[NinjaTrader.Gui.Design.DisplayName("02. Automatic shadow size multiplier")] | |
[Description("Automatic shadow size in proportion to bar size. Requires AutomaticSize mode.\r\nEnter a value between 0.0 and 2.0\r\nLarger value results in a larger shadow size.")] | |
public double TrailingShadowSizeMultiplier { | |
get { return trailingShadowSizeMultiplier; } | |
set { trailingShadowSizeMultiplier = Math.Min(2, Math.Max(0, value)); } | |
} | |
#endregion | |
#endregion | |
#endregion | |
#region Miscellaneous overrides | |
[XmlIgnore, Browsable(false)] | |
public override string ApexName { | |
get { return "Bar Style Settings"; } | |
} | |
[XmlIgnore, Browsable(false)] | |
public override int Version { | |
get { return 1; } | |
} | |
[XmlIgnore, Browsable(false)] | |
public override bool CanAddToChart { | |
get { return false; } | |
} | |
[XmlIgnore, Browsable(false)] | |
public override bool IsFeatureEnabled { | |
get { return true; } | |
} | |
protected override void ApexInitialize() { | |
Overlay = true; | |
BarsRequired = 0; | |
} | |
protected override string[] ApexGetDismissibleMessageIds() { | |
return new string[0]; | |
} | |
protected override Dictionary<int, ApexSolid.ISolidBars> ApexCreateAndMapSolidBars() { | |
return new Dictionary<int, ApexSolid.ISolidBars>(); | |
} | |
protected override ApexSolid.SolidEngineBase[] ApexCreateSolidEngines() { | |
return new ApexSolid.SolidEngineBase[0]; | |
} | |
protected override void ApexOnStartUp() { } | |
protected override void ApexOnSwitchToLive() { } | |
protected override void ApexOnBarUpdate() { } | |
protected override void ApexOnMarketData(Data.MarketDataEventArgs args) { } | |
protected override void ApexPlot(System.Drawing.Graphics graphics, System.Drawing.Rectangle bounds, double min, double max) { } | |
public override void ApexGetMinMaxValues(Gui.Chart.ChartControl chartControl, ref double min, ref double max) { } | |
#endregion | |
protected override void ApexOnTermination() { } | |
public override string ToString() { | |
// allow the indicator to display itself in the indicator editing list | |
if (null == ChartControl) { | |
return base.ToString(); | |
} | |
// prevent the indicator from displaying its name on the chart | |
return string.Empty; | |
} | |
#region ICustomTypeDescriptor | |
#region Miscellaneous | |
public AttributeCollection GetAttributes() { | |
return TypeDescriptor.GetAttributes(GetType()); | |
} | |
public string GetClassName() { | |
return TypeDescriptor.GetClassName(GetType()); | |
} | |
public string GetComponentName() { | |
return TypeDescriptor.GetComponentName(GetType()); | |
} | |
public TypeConverter GetConverter() { | |
return TypeDescriptor.GetConverter(GetType()); | |
} | |
public EventDescriptor GetDefaultEvent() { | |
return TypeDescriptor.GetDefaultEvent(GetType()); | |
} | |
public PropertyDescriptor GetDefaultProperty() { | |
return TypeDescriptor.GetDefaultProperty(GetType()); | |
} | |
public object GetEditor(Type editorBaseType) { | |
return TypeDescriptor.GetEditor(GetType(), editorBaseType); | |
} | |
public EventDescriptorCollection GetEvents(Attribute[] attributes) { | |
return TypeDescriptor.GetEvents(GetType(), attributes); | |
} | |
public EventDescriptorCollection GetEvents() { | |
return TypeDescriptor.GetEvents(GetType()); | |
} | |
public PropertyDescriptorCollection GetProperties() { | |
return TypeDescriptor.GetProperties(GetType()); | |
} | |
public object GetPropertyOwner(PropertyDescriptor pd) { | |
return this; | |
} | |
#endregion | |
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { | |
var properties = TypeDescriptor.GetProperties(GetType(), attributes); | |
var result = new PropertyDescriptorCollection(new PropertyDescriptor[0]); | |
foreach (var propertyDescriptor in properties.Cast<PropertyDescriptor>()) { | |
if (IsPropertyVisible(propertyDescriptor.Name)) | |
result.Add(propertyDescriptor); | |
} | |
return result; | |
} | |
bool IsPropertyVisible(string propertyName) { | |
// hide all of the standard ninjatrader indicator properties | |
var propertyInfo = GetType().GetProperty(propertyName); | |
if (!typeof(SolidIndicator).IsAssignableFrom(propertyInfo.DeclaringType)) | |
return false; | |
switch (propertyName) { | |
case "TrailingShadowSizeMultiplier": | |
return TrailingShadowMode == NinjaTrader.Indicator.TrailingShadowMode.AutomaticSize; | |
case "TrailingShadowSizeTicks": | |
return TrailingShadowMode == NinjaTrader.Indicator.TrailingShadowMode.ManualSize; | |
case "Candle_UpColor": | |
case "Candle_DownColor": | |
case "Candle_UpWickColor": | |
case "Candle_DownWickColor": | |
return BarStyle == NinjaTrader.Indicator.BarStyle.Candle; | |
case "OHLC_NoShadow_UpColor": | |
case "OHLC_NoShadow_DownColor": | |
return BarStyle == NinjaTrader.Indicator.BarStyle.OHLC | |
&& TrailingShadowMode == NinjaTrader.Indicator.TrailingShadowMode.Off; | |
case "OHLC_Shadow_UpShadowColor": | |
case "OHLC_Shadow_DownShadowColor": | |
case "OHLC_Shadow_UpBarColor": | |
case "OHLC_Shadow_DownBarColor": | |
return BarStyle == NinjaTrader.Indicator.BarStyle.OHLC | |
&& TrailingShadowMode != NinjaTrader.Indicator.TrailingShadowMode.Off; | |
} | |
return true; | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment