Support Board
Date/Time: Wed, 05 Feb 2025 22:57:49 +0000
[Programming Help] - Convert Ninja indicator to Sierra Charts.
View Count: 1548
[2020-03-26 01:55:12] |
User701453 - Posts: 176 |
Any dual coding experts able to convert this ninja indicator to SC? using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.Design; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; namespace NinjaTrader.Indicator { public class GT3LineBreak : GTIndicatorBase { private int period = 3; private string mAlertFileName = string.Empty; private string mTmpAlertFile = string.Empty; private int lineColorTransparency = 50; private Color lineDownColor = Color.Red; private Color lineUpColor = Color.Green; private SolidBrush lineUpBrush = new SolidBrush(Color.Green); private SolidBrush lineDownBrush = new SolidBrush(Color.Red); private bool showTriggerLines = true; private bool showBars = true; private Color triggerLineDownColor = Color.Red; private Color triggerLineUpColor = Color.Green; private int triggerLineWidth = 2; private double nBrickHigh = -999999.0; private double nBrickLow = 999999.0; private Color longBarColor = Color.Transparent; private Color shortBarColor = Color.Transparent; private readonly List<GT3LineBreak.BrickListRow> brickList = new List<GT3LineBreak.BrickListRow>(); private int nBrickHighBarsNum; private int nBrickLowBarsNum; private double triggerValue; private int triggerBarsNum; private int barCount; private DataSeries brickOpen; private DataSeries brickClose; private BoolSeries brickNew; private IntSeries brickOpenBarsNum; private DataSeries open; private DataSeries high; private DataSeries low; private DataSeries close; protected override void Initialize() { base.Initialize(); this.set_Name("GT Precision 3 Line Break"); try { this.Add(new Plot(Color.FromKnownColor(KnownColor.Blue), (PlotStyle) 6, "NLBPlot")); this.Add(new Plot(new Pen(Color.DarkGreen, 5f), (PlotStyle) 11, "Long")); this.Add(new Plot(new Pen(Color.Red, 5f), (PlotStyle) 8, "Short")); this.brickOpen = new DataSeries((IndicatorBase) this); this.brickClose = new DataSeries((IndicatorBase) this); this.brickNew = new BoolSeries((IndicatorBase) this); this.brickOpenBarsNum = new IntSeries((IndicatorBase) this); this.open = new DataSeries((IndicatorBase) this); this.high = new DataSeries((IndicatorBase) this); this.low = new DataSeries((IndicatorBase) this); this.close = new DataSeries((IndicatorBase) this); this.mTmpAlertFile = this.mAlertFileName; this.set_CalculateOnBarClose(true); this.set_Overlay(true); this.set_PriceTypeSupported(false); } catch (Exception ex) { } } protected virtual void OnBarUpdate() { try { this.open.Set(this.get_Open().get_Item(0)); this.high.Set(this.get_High().get_Item(0)); this.low.Set(this.get_Low().get_Item(0)); this.close.Set(this.get_Close().get_Item(0)); if (this.barCount != 0 && this.ToDay(this.get_Time().get_Item(0)) == this.ToDay(this.get_Time().get_Item(1))) { int trendDir = -1; if (this.brickClose.get_Item(1) >= this.brickOpen.get_Item(1)) trendDir = 1; if (trendDir == 1 && this.close.get_Item(0) > this.brickClose.get_Item(1) || trendDir == -1 && this.close.get_Item(0) < this.brickClose.get_Item(1)) { this.brickClose.set_Item(0, this.close.get_Item(0)); this.brickOpen.set_Item(0, this.brickClose.get_Item(1)); this.brickOpenBarsNum.set_Item(0, this.get_CurrentBar()); this.brickNew.set_Item(0, true); this.brickList.Add(new GT3LineBreak.BrickListRow(this.get_CurrentBar(), Math.Max(this.brickClose.get_Item(0), this.brickOpen.get_Item(0)), Math.Min(this.brickClose.get_Item(0), this.brickOpen.get_Item(0)))); this.GetNBrickHighLow(); this.DrawDynamicTriggerLines(trendDir); } else if (this.close.get_Item(0) >= this.brickOpen.get_Item(1) && this.close.get_Item(0) <= this.brickClose.get_Item(1) || this.close.get_Item(0) <= this.brickOpen.get_Item(1) && this.close.get_Item(0) >= this.brickClose.get_Item(1)) { this.brickOpen.set_Item(0, this.brickOpen.get_Item(1)); this.brickOpenBarsNum.set_Item(0, this.brickOpenBarsNum.get_Item(1)); this.brickClose.set_Item(0, this.brickClose.get_Item(1)); this.brickNew.set_Item(0, false); } else { this.GetNBrickHighLow(); if (trendDir == 1 && this.close.get_Item(0) < this.nBrickLow || trendDir == -1 && this.close.get_Item(0) > this.nBrickHigh) { this.DrawStaticTriggerLines(trendDir); if (trendDir == -1) { this.SignalLong.Set(this.get_Low().get_Item(0) - 5.0 * this.get_TickSize()); if (this.longBarColor != Color.Transparent) this.set_BackColor(this.longBarColor); if (this.get_Historical()) this.Alert(this.get_Bars().get_Instrument().get_FullName(), (Priority) 0, string.Format("GT 3 Line Break Buy at price {0}", (object) this.FormatPrice(this.get_Close().get_Item(0))), this.SoundAlertFileName, 60, Color.Black, Color.Yellow); } else { this.SignalShort.Set(this.get_High().get_Item(0) + 5.0 * this.get_TickSize()); if (this.shortBarColor != Color.Transparent) this.set_BackColor(this.shortBarColor); if (this.get_Historical()) this.Alert(this.get_Bars().get_Instrument().get_FullName(), (Priority) 0, string.Format("GT 3 Line Break Buy at price {0}", (object) this.FormatPrice(this.get_Close().get_Item(0))), this.SoundAlertFileName, 60, Color.Black, Color.Yellow); } this.brickOpen.set_Item(0, this.brickOpen.get_Item(1)); this.brickOpenBarsNum.set_Item(0, this.brickOpenBarsNum.get_Item(1)); this.brickClose.set_Item(0, this.close.get_Item(0)); this.brickNew.set_Item(0, true); this.brickList.Add(new GT3LineBreak.BrickListRow(this.get_CurrentBar(), Math.Max(this.brickClose.get_Item(0), this.brickOpen.get_Item(0)), Math.Min(this.brickClose.get_Item(0), this.brickOpen.get_Item(0)))); this.GetNBrickHighLow(); this.DrawDynamicTriggerLines(-trendDir); } else { this.brickOpen.set_Item(0, this.brickOpen.get_Item(1)); this.brickOpenBarsNum.set_Item(0, this.brickOpenBarsNum.get_Item(1)); this.brickClose.set_Item(0, this.brickClose.get_Item(1)); this.brickNew.set_Item(0, false); } } ++this.barCount; } else { this.brickOpen.set_Item(0, this.open.get_Item(0)); this.brickClose.set_Item(0, this.close.get_Item(0)); this.brickNew.set_Item(0, true); ++this.barCount; } } catch (Exception ex) { } } private void DrawDynamicTriggerLines(int trendDir) { if (!this.showTriggerLines) return; this.RemoveDrawObject("NBrickTriggerUpRay"); this.RemoveDrawObject("NBrickTriggerDnRay"); if (trendDir == 1) { this.triggerValue = this.nBrickLow; this.triggerBarsNum = this.nBrickLowBarsNum; this.DrawRay("NBrickTriggerUpRay", true, this.get_CurrentBar() - this.triggerBarsNum, this.triggerValue, 0, this.triggerValue, this.TriggerLineDownColor, DashStyle.Dot, this.TriggerLineWidth); } else { if (trendDir != -1) return; this.triggerValue = this.nBrickHigh; this.triggerBarsNum = this.nBrickHighBarsNum; this.DrawRay("NBrickTriggerDnRay", true, this.get_CurrentBar() - this.triggerBarsNum, this.triggerValue, 0, this.triggerValue, this.TriggerLineUpColor, DashStyle.Dot, this.TriggerLineWidth); } } private void DrawStaticTriggerLines(int trendDir) { if (!this.showTriggerLines) return; if (trendDir == 1) { this.triggerValue = this.nBrickLow; this.triggerBarsNum = this.nBrickLowBarsNum; this.DrawLine("NBrickTriggerUpLine" + (object) this.triggerBarsNum, true, this.get_CurrentBar() - this.triggerBarsNum, this.triggerValue, 0, this.triggerValue, this.TriggerLineDownColor, DashStyle.Dot, this.TriggerLineWidth); } else { if (trendDir != -1) return; this.triggerValue = this.nBrickHigh; this.triggerBarsNum = this.nBrickHighBarsNum; this.DrawLine("NBrickTriggerDnLine" + (object) this.triggerBarsNum, true, this.get_CurrentBar() - this.triggerBarsNum, this.triggerValue, 0, this.triggerValue, this.TriggerLineUpColor, DashStyle.Dot, this.TriggerLineWidth); } } private void GetNBrickHighLow() { this.nBrickHigh = -999999.0; this.nBrickLow = 999999.0; this.nBrickHighBarsNum = 0; this.nBrickLowBarsNum = 0; int count = this.brickList.Count; if (this.brickList.Count < this.Period) return; for (int index1 = 0; index1 < this.Period; ++index1) { int index2 = count - index1 - 1; if (this.brickList[index2].BrickHigh >= this.nBrickHigh) { this.nBrickHigh = this.brickList[index2].BrickHigh; this.nBrickHighBarsNum = this.brickList[index2].BrickBarsNum; } if (this.brickList[index2].BrickLow <= this.nBrickLow) { this.nBrickLow = this.brickList[index2].BrickLow; this.nBrickLowBarsNum = this.brickList[index2].BrickBarsNum; } } } public virtual void Plot(Graphics e, Rectangle bounds, double min, double max) { base.Plot(e, bounds, min, max); if (!this.showBars) return; int barPaintWidth = this.get_ChartControl().get_ChartStyle().GetBarPaintWidth(this.get_ChartControl().get_BarWidth()); for (int barsPainted = this.get_ChartControl().get_BarsPainted(); barsPainted >= 0; --barsPainted) { try { int num1 = this.get_ChartControl().get_LastBarPainted() - this.get_ChartControl().get_BarsPainted() + 1 + barsPainted; double num2 = Math.Max(this.brickOpen.Get(num1), this.brickClose.Get(num1)); double num3 = Math.Min(this.brickOpen.Get(num1), this.brickClose.Get(num1)); int num4 = this.get_ChartControl().get_CanvasRight() - this.get_ChartControl().get_BarMarginRight() - barPaintWidth / 2 - (this.get_ChartControl().get_BarsPainted() - 1) * this.get_ChartControl().get_BarSpace() + barsPainted * this.get_ChartControl().get_BarSpace(); int y = bounds.Y + bounds.Height - (int) ((num2 - min) / ChartControl.MaxMinusMin(max, min) * (double) bounds.Height); int num5 = bounds.Y + bounds.Height - (int) ((num3 - min) / ChartControl.MaxMinusMin(max, min) * (double) bounds.Height); e.FillRectangle(this.brickOpen.Get(num1) > this.brickClose.Get(num1) ? (Brush) this.lineDownBrush : (Brush) this.lineUpBrush, num4 - barPaintWidth / 2, y, barPaintWidth, num5 - y); } catch (Exception ex) { } } } private void RecalculateColors() { int alpha = (int) ((double) byte.MaxValue * ((100.0 - (double) this.LineColorTransparency) / 100.0)); this.lineUpBrush = new SolidBrush(Color.FromArgb(alpha, (int) this.lineUpColor.R, (int) this.lineUpColor.G, (int) this.lineUpColor.B)); this.lineDownBrush = new SolidBrush(Color.FromArgb(alpha, (int) this.lineDownColor.R, (int) this.lineDownColor.G, (int) this.lineDownColor.B)); } [Browsable(false)] [XmlIgnore] public DataSeries Plot0 { get { return this.get_Values()[0]; } } [XmlIgnore] [Browsable(false)] public DataSeries SignalLong { get { return this.get_Values()[1]; } } [Browsable(false)] [XmlIgnore] public DataSeries SignalShort { get { return this.get_Values()[2]; } } [Category("Parameters")] [Description("Period")] public int Period { get { return this.period; } set { this.period = Math.Max(1, value); } } [Description("Full name of the sound file used for Alert")] [DisplayName("Alert File Name")] [Category("Audio")] public string SoundAlertFileName { get { return this.mAlertFileName; } set { this.mAlertFileName = value; } } [DisplayName("Line Color Transparency")] [Category("Display")] [Description("Line Color Transparency (0 to 90)")] public int LineColorTransparency { get { return this.lineColorTransparency; } set { this.lineColorTransparency = Math.Max(0, value); this.lineColorTransparency = Math.Min(90, value); } } [VisualizationOnly] [DisplayName("Line Down Color")] [Description("Color for Down Line")] [Category("Display")] [XmlIgnore] public Color LineDownColor { get { return this.lineDownColor; } set { this.lineDownColor = value; this.RecalculateColors(); } } [Browsable(false)] public string LineDownColorSerialize { get { return SerializableColor.ToString(this.lineDownColor); } set { this.lineDownColor = SerializableColor.FromString(value); } } [DisplayName("Line Up Color")] [XmlIgnore] [Description("Color for Up Line")] [Category("Display")] [VisualizationOnly] public Color LineUpColor { get { return this.lineUpColor; } set { this.lineUpColor = value; this.RecalculateColors(); } } [Browsable(false)] public string LineUpColorSerialize { get { return SerializableColor.ToString(this.lineUpColor); } set { this.lineUpColor = SerializableColor.FromString(value); } } [Description("Show Trigger Lines")] [Category("Display")] [DisplayName("Show Trigger Lines")] public bool ShowTriggerLines { get { return this.showTriggerLines; } set { this.showTriggerLines = value; } } [DisplayName("Show Bars")] [Category("Display")] [Description("Show Bars")] public bool ShowBars { get { return this.showBars; } set { this.showBars = value; } } [DisplayName("Trigger Line Up Color")] [XmlIgnore] [VisualizationOnly] [Category("Display")] [Description("TriggerLineUpColor")] public Color TriggerLineUpColor { get { return this.triggerLineUpColor; } set { this.triggerLineUpColor = value; } } [Category("Display")] [XmlIgnore] [DisplayName("Trigger Line Down Color")] [Description("TriggerLineDownColor")] [VisualizationOnly] public Color TriggerLineDownColor { get { return this.triggerLineDownColor; } set { this.triggerLineDownColor = value; } } [Category("Display")] [DisplayName("Trigger Line Width (0 to 8)")] [Description("TriggerLineWidth")] public int TriggerLineWidth { get { return this.triggerLineWidth; } set { this.triggerLineWidth = Math.Max(1, value); this.triggerLineWidth = Math.Min(8, value); } } [DisplayName("Signal Color - Buy Background")] [Category("Display")] [Description("Select color for Long Bar chart background")] public Color LongBarColor { get { return this.longBarColor; } set { this.longBarColor = value; } } [Browsable(false)] public string LongBarColorSerialize { get { return SerializableColor.ToString(this.longBarColor); } set { this.longBarColor = SerializableColor.FromString(value); } } [DisplayName("Signal Color - Sell Background")] [Category("Display")] [Description("Select color for Short Bar Color chart background")] public Color ShortBarColor { get { return this.shortBarColor; } set { this.shortBarColor = value; } } [Browsable(false)] public string ShortBarColorSerialize { get { return SerializableColor.ToString(this.shortBarColor); } set { this.shortBarColor = SerializableColor.FromString(value); } } private class BrickListRow { public readonly int BrickBarsNum; public readonly double BrickHigh; public readonly double BrickLow; public BrickListRow(int brickBarsNum, double brickHigh, double brickLow) { this.BrickBarsNum = brickBarsNum; this.BrickHigh = brickHigh; this.BrickLow = brickLow; } } } } |
[2020-03-28 16:17:20] |
User701453 - Posts: 176 |
28 views and no assistance. Guess no one here has C#/ninja script and SC coding abilities. Date Time Of Last Edit: 2020-03-28 16:18:43
|
[2020-03-30 23:56:17] |
ForgivingComputers.com - Posts: 994 |
Guess no one here has C#/ninja script and SC coding abilities.
I sent you a direct message request. Brad Houser |
[2020-04-05 15:29:04] |
User701453 - Posts: 176 |
Direct message request accepted.
|
[2020-04-05 15:40:16] |
ForgivingComputers.com - Posts: 994 |
Direct message request accepted.
I am not seeing it. You need to accept it in the Direct Messages window.
|
[2020-04-05 23:38:17] |
User701453 - Posts: 176 |
done
|
To post a message in this thread, you need to log in with your Sierra Chart account: