I am trying to learn how to access high low open close values based on time not candles number, not sure if nt8 does that newly created candle is [0] and history candles are more zero >=0.
Does anyone have some examples? Or can explain to me how it could be possible done?
For example Midnight candle open, so if candles == 00:00 get its values.
Or how do I access series from 4pm, to 6pm, and get highest high and lowest low from between.
Last thing would be get indicator limited to 3 days in the past, not from how many candlesticks are loaded as it will make NT laggy.
Could you advise?
Thanks everyone.
Here is the code:
//
// Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#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.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
{
/// <summary>
/// </summary>
public class OpeningRangeIndicator : Indicator
{
double highestPrice = 0.0;
double lowestPrice = 0.0;
bool bFirst = true;
double d30minbar = 0.0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Opening Range Indicator";
Name = "Opening Range Indicator";
IsOverlay = true;
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Red, "Opening Range High");
AddPlot(Brushes.Red, "Opening Range Low");
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Minute, 30); //historical data load as when indicator is loaded. In this case 30 min candles.
}
}
protected override void OnBarUpdate()
{
if (BarsPeriod.BarsPeriodType == BarsPeriodType.Minute ) // if chart is set type minutes
{
if (bFirst) // check if its first bar
{
d30minbar = (30/BarsPeriod.Value)-1; // checks if its first 30 min candle created, if it isnt then sets bFirstvalue to false.
bFirst = false;
}
if (CurrentBar < 20) // check is currentbar is less than 20 ? why? as if its 30 min range to show then CurrentBar should be check if its less than 30 candles. not 20
{
return; //if first 20 candles are loaded return nothing.
}
if( BarsPeriod.Value == 30) // check if BarsPeriod Value of it is 30 what is it checks for 30m timeframe or something else
{
if( Bars.BarsSinceNewTradingDay == 0) // if new bars are equal to 0 then it sets highstPrice value to Highs[1][0] so series is previous value of whatever is in [0] candle?
{
highestPrice = Highs[1][0]; // puts highest high price value from highs of candle [1] to highersPrice value
lowestPrice = Lows[1][0]; // same as above but for lows
}
}
if (Bars.BarsSinceNewTradingDay > d30minbar)
{
HighOfRange[0] = highestPrice; //sets hP values of the range
LowOfRange[0] = lowestPrice; //sets hP values to lowOfRange
}
}
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public Series<double> HighOfRange
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> LowOfRange
{
get { return Values[1]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private OpeningRangeIndicator[] cacheOpeningRangeIndicator;
public OpeningRangeIndicator OpeningRangeIndicator()
{
return OpeningRangeIndicator(Input);
}
public OpeningRangeIndicator OpeningRangeIndicator(ISeries<double> input)
{
if (cacheOpeningRangeIndicator != null)
for (int idx = 0; idx < cacheOpeningRangeIndicator.Length; idx++)
if (cacheOpeningRangeIndicator[idx] != null && cacheOpeningRangeIndicator[idx].EqualsInput(input))
return cacheOpeningRangeIndicator[idx];
return CacheIndicator<OpeningRangeIndicator>(new OpeningRangeIndicator(), input, ref cacheOpeningRangeIndicator);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.OpeningRangeIndicator OpeningRangeIndicator()
{
return indicator.OpeningRangeIndicator(Input);
}
public Indicators.OpeningRangeIndicator OpeningRangeIndicator(ISeries<double> input )
{
return indicator.OpeningRangeIndicator(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.OpeningRangeIndicator OpeningRangeIndicator()
{
return indicator.OpeningRangeIndicator(Input);
}
public Indicators.OpeningRangeIndicator OpeningRangeIndicator(ISeries<double> input )
{
return indicator.OpeningRangeIndicator(input);
}
}
}
#endregion

Comment