I have tried both Draw.Line() and Draw.HorizontalLine(), neither providing an line output. For emphasis, I am trying to just plot a "threshold level", in a separate chart Pane, not on Price (which I was advised somewhere that I needed to use Draw.Line() when in a Pane, but uncertain if that was correct advice).
Intent was to be able to have an "Indicator" to add threshold levels to another Indicator (i.e. think RSI, Stochastic levels, etc.).
Any clues as to how to fix this would be much appreciated.
[Is there a better/preferred way to insert Code into these posts?]
region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class tst_LevelLine_V1 : Indicator
{
region Properties
[NinjaScriptProperty]
[Browsable(true)]
[Range(-10, 10)]
[Display(Name = "Zero Value Override", Order = 1, GroupName = "Level Values")]
public double ZeroValue { get; set; } = 0; // Set to Zero
[NinjaScriptProperty]
[Browsable(true)]
[Range(0, double.MaxValue)]
[Display(Name = "Level 1", Order = 2, GroupName = "Level Values")]
public double Level1Value { get; set; } = 10; // Set to 10
#endregion
[NinjaScriptProperty]
[Display(Name = "Zero Line Dash Style", Order = 1, GroupName = "Line Styles")]
public DashStyleHelper ZeroLineDashStyle { get; set; } = DashStyleHelper.Dot;
[NinjaScriptProperty]
[Display(Name = "Threshold Line Dash Style", Order = 2, GroupName = "Line Styles")]
public DashStyleHelper ThresholdLineDashStyle { get; set; } = DashStyleHelper.Dash;
private DashStyle ConvertToDashStyle(DashStyleHelper dashStyleHelper)
{
switch (dashStyleHelper)
{
case DashStyleHelper.Dash:
return DashStyles.Dash;
case DashStyleHelper.Dot:
return DashStyles.Dot;
case DashStyleHelper.Solid:
return DashStyles.Solid;
case DashStyleHelper.DashDot:
return DashStyles.DashDot;
case DashStyleHelper.DashDotDot:
return DashStyles.DashDotDot;
default:
return DashStyles.Solid;
}
}
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Horizontal Line Level in Pane";
Name = "tst_LevelLine_V1";
Calculate = NinjaTrader.NinjaScript.Calculate.OnEachTick;
IsOverlay = false; // Do not plot on price chart
IsAutoScale = true;
AddPlot(Brushes.Transparent, "ForcePanelScale");
}
else if (State == State.DataLoaded)
{
// Draw.Line(this, "ZeroLine", ZeroValue, Brushes.Silver)
// .Stroke.DashStyleHelper = ZeroLineDashStyle;
// Draw.Line(this, "Level1Line", Level1Value, Brushes.Lime)
// .Stroke.DashStyleHelper = ThresholdLineDashStyle;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Count - 1)
return;
int barsBack = 100; // How far back to draw the line
// Draw Zero Line
Draw.Line(this, "ZeroLine",
false,
barsBack, ZeroValue,
0, ZeroValue,
Brushes.Silver,
DashStyleHelper.Dot,
1);
// Draw Level 1 Line
Draw.Line(this, "Level1Line",
false,
barsBack, Level1Value,
0, Level1Value,
Brushes.Lime,
DashStyleHelper.Dash,
1);
Values[0][0] = ZeroValue; // or Just to keep the pane scaled
}
}
}

Comment