Add support for opening ranges defined in terms of volume conducted
This commit is contained in:
parent
a4cfe65a4e
commit
e6b54e392b
@ -21,11 +21,12 @@ using NinjaTrader.Core.FloatingPoint;
|
||||
using NinjaTrader.NinjaScript.DrawingTools;
|
||||
#endregion
|
||||
|
||||
public enum TimeFrame
|
||||
public enum OpeningRangeBarType
|
||||
{
|
||||
Seconds,
|
||||
Minutes,
|
||||
Hours
|
||||
Hours,
|
||||
Volume
|
||||
}
|
||||
|
||||
//This namespace holds Indicators in this folder and is required. Do not change it.
|
||||
@ -63,8 +64,8 @@ namespace NinjaTrader.NinjaScript.Indicators
|
||||
//See Help Guide for additional information.
|
||||
IsSuspendedWhileInactive = true;
|
||||
ArePlotsConfigurable = false;
|
||||
OpeningRangeLength = 30;
|
||||
OpeningRangeTimeFrame = TimeFrame.Minutes;
|
||||
OpeningRangePeriod = 30;
|
||||
OpeningRangeType = OpeningRangeBarType.Minutes;
|
||||
OpeningRangeHighStroke = new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 3);
|
||||
OpeningRangeLowStroke = new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 3);
|
||||
OpeningRangeMidStroke = new Stroke(Brushes.Gray, DashStyleHelper.Dash, 3);
|
||||
@ -80,20 +81,25 @@ namespace NinjaTrader.NinjaScript.Indicators
|
||||
OpeningRangeDate = DateTime.MinValue;
|
||||
OpeningRangeStartTime = DateTime.MinValue;
|
||||
|
||||
if (OpeningRangeTimeFrame == TimeFrame.Seconds)
|
||||
if (OpeningRangeType == OpeningRangeBarType.Volume)
|
||||
{
|
||||
AddDataSeries(Instrument.FullName, new BarsPeriod {
|
||||
BarsPeriodType = BarsPeriodType.Second, Value = OpeningRangeLength }, REGULAR_TRADING_HOURS);
|
||||
AddDataSeries(Instrument.FullName, new BarsPeriod {
|
||||
BarsPeriodType = BarsPeriodType.Volume, Value = OpeningRangePeriod }, REGULAR_TRADING_HOURS);
|
||||
}
|
||||
else if (OpeningRangeTimeFrame == TimeFrame.Hours)
|
||||
else if (OpeningRangeType == OpeningRangeBarType.Seconds)
|
||||
{
|
||||
AddDataSeries(Instrument.FullName, new BarsPeriod {
|
||||
BarsPeriodType = BarsPeriodType.Minute, Value = OpeningRangeLength * MINUTES_IN_HOUR }, REGULAR_TRADING_HOURS);
|
||||
BarsPeriodType = BarsPeriodType.Second, Value = OpeningRangePeriod }, REGULAR_TRADING_HOURS);
|
||||
}
|
||||
else if (OpeningRangeType == OpeningRangeBarType.Hours)
|
||||
{
|
||||
AddDataSeries(Instrument.FullName, new BarsPeriod {
|
||||
BarsPeriodType = BarsPeriodType.Minute, Value = OpeningRangePeriod * MINUTES_IN_HOUR }, REGULAR_TRADING_HOURS);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddDataSeries(Instrument.FullName, new BarsPeriod {
|
||||
BarsPeriodType = BarsPeriodType.Minute, Value = OpeningRangeLength }, REGULAR_TRADING_HOURS);
|
||||
BarsPeriodType = BarsPeriodType.Minute, Value = OpeningRangePeriod }, REGULAR_TRADING_HOURS);
|
||||
}
|
||||
}
|
||||
else if (State == State.DataLoaded)
|
||||
@ -162,13 +168,13 @@ namespace NinjaTrader.NinjaScript.Indicators
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Range(1, int.MaxValue)]
|
||||
[Display(Name = "Length", Description = "Length of opening range", Order = 1, GroupName = "Parameters")]
|
||||
public int OpeningRangeLength
|
||||
[Display(Name = "Period", Description = "Opening range period", Order = 1, GroupName = "Parameters")]
|
||||
public int OpeningRangePeriod
|
||||
{ get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Time Frame", Description = "Time frame on which opening range is being calculated", Order = 2, GroupName = "Parameters")]
|
||||
public TimeFrame OpeningRangeTimeFrame
|
||||
[Display(Name = "Type", Description = "Type of opening range being calculated", Order = 2, GroupName = "Parameters")]
|
||||
public OpeningRangeBarType OpeningRangeType
|
||||
{ get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
@ -216,18 +222,18 @@ namespace NinjaTrader.NinjaScript.Indicators
|
||||
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
|
||||
{
|
||||
private OpeningRange[] cacheOpeningRange;
|
||||
public OpeningRange OpeningRange(int openingRangeLength, TimeFrame openingRangeTimeFrame, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
public OpeningRange OpeningRange(int openingRangePeriod, OpeningRangeBarType openingRangeType, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
{
|
||||
return OpeningRange(Input, openingRangeLength, openingRangeTimeFrame, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
return OpeningRange(Input, openingRangePeriod, openingRangeType, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
}
|
||||
|
||||
public OpeningRange OpeningRange(ISeries<double> input, int openingRangeLength, TimeFrame openingRangeTimeFrame, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
public OpeningRange OpeningRange(ISeries<double> input, int openingRangePeriod, OpeningRangeBarType openingRangeType, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
{
|
||||
if (cacheOpeningRange != null)
|
||||
for (int idx = 0; idx < cacheOpeningRange.Length; idx++)
|
||||
if (cacheOpeningRange[idx] != null && cacheOpeningRange[idx].OpeningRangeLength == openingRangeLength && cacheOpeningRange[idx].OpeningRangeTimeFrame == openingRangeTimeFrame && cacheOpeningRange[idx].OpeningRangeHighStroke == openingRangeHighStroke && cacheOpeningRange[idx].OpeningRangeLowStroke == openingRangeLowStroke && cacheOpeningRange[idx].OpeningRangeMidStroke == openingRangeMidStroke && cacheOpeningRange[idx].EqualsInput(input))
|
||||
if (cacheOpeningRange[idx] != null && cacheOpeningRange[idx].OpeningRangePeriod == openingRangePeriod && cacheOpeningRange[idx].OpeningRangeType == openingRangeType && cacheOpeningRange[idx].OpeningRangeHighStroke == openingRangeHighStroke && cacheOpeningRange[idx].OpeningRangeLowStroke == openingRangeLowStroke && cacheOpeningRange[idx].OpeningRangeMidStroke == openingRangeMidStroke && cacheOpeningRange[idx].EqualsInput(input))
|
||||
return cacheOpeningRange[idx];
|
||||
return CacheIndicator<OpeningRange>(new OpeningRange(){ OpeningRangeLength = openingRangeLength, OpeningRangeTimeFrame = openingRangeTimeFrame, OpeningRangeHighStroke = openingRangeHighStroke, OpeningRangeLowStroke = openingRangeLowStroke, OpeningRangeMidStroke = openingRangeMidStroke }, input, ref cacheOpeningRange);
|
||||
return CacheIndicator<OpeningRange>(new OpeningRange(){ OpeningRangePeriod = openingRangePeriod, OpeningRangeType = openingRangeType, OpeningRangeHighStroke = openingRangeHighStroke, OpeningRangeLowStroke = openingRangeLowStroke, OpeningRangeMidStroke = openingRangeMidStroke }, input, ref cacheOpeningRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -236,14 +242,14 @@ namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
||||
{
|
||||
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
||||
{
|
||||
public Indicators.OpeningRange OpeningRange(int openingRangeLength, TimeFrame openingRangeTimeFrame, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
public Indicators.OpeningRange OpeningRange(int openingRangePeriod, OpeningRangeBarType openingRangeType, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
{
|
||||
return indicator.OpeningRange(Input, openingRangeLength, openingRangeTimeFrame, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
return indicator.OpeningRange(Input, openingRangePeriod, openingRangeType, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
}
|
||||
|
||||
public Indicators.OpeningRange OpeningRange(ISeries<double> input , int openingRangeLength, TimeFrame openingRangeTimeFrame, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
public Indicators.OpeningRange OpeningRange(ISeries<double> input , int openingRangePeriod, OpeningRangeBarType openingRangeType, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
{
|
||||
return indicator.OpeningRange(input, openingRangeLength, openingRangeTimeFrame, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
return indicator.OpeningRange(input, openingRangePeriod, openingRangeType, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -252,14 +258,14 @@ namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
||||
{
|
||||
public Indicators.OpeningRange OpeningRange(int openingRangeLength, TimeFrame openingRangeTimeFrame, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
public Indicators.OpeningRange OpeningRange(int openingRangePeriod, OpeningRangeBarType openingRangeType, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
{
|
||||
return indicator.OpeningRange(Input, openingRangeLength, openingRangeTimeFrame, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
return indicator.OpeningRange(Input, openingRangePeriod, openingRangeType, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
}
|
||||
|
||||
public Indicators.OpeningRange OpeningRange(ISeries<double> input , int openingRangeLength, TimeFrame openingRangeTimeFrame, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
public Indicators.OpeningRange OpeningRange(ISeries<double> input , int openingRangePeriod, OpeningRangeBarType openingRangeType, Stroke openingRangeHighStroke, Stroke openingRangeLowStroke, Stroke openingRangeMidStroke)
|
||||
{
|
||||
return indicator.OpeningRange(input, openingRangeLength, openingRangeTimeFrame, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
return indicator.OpeningRange(input, openingRangePeriod, openingRangeType, openingRangeHighStroke, openingRangeLowStroke, openingRangeMidStroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user