I have simple indicator see below.
When I set value in condition
if (CurrentBar > 1) { LastDayLow[0] = lastDayLow; }
thanks a lot
Paul
using GolemTools; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui; using NinjaTrader.NinjaScript.DrawingTools; using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Windows.Media; using System.Xml.Serialization; namespace NinjaTrader.NinjaScript.Indicators { /// <summary> /// Current Day OHL Middles /// </summary> public class Golem_SR_Levels : Indicator { private ValidateLicense validateLicense; private string sIndicatorId = "c35d-7d5f-e5de-4154a"; private const string eshopId = "esh-11111111"; private string sUsername; private DateTime currentDate = Core.Globals.MinDate; private double currentHigh = 0; private double currentLow = 0; private double currentMid = 0; private double currentOpen = 0; private double lastDayHigh = 0; private double lastDayLow = 0; private double lastDayMid = 0; private double lastDayClose = 0; private SessionIterator sessionIterator; #region Properties [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public Series<double> CurrentOpen { get { return Values[0]; } } [Browsable(false)] [XmlIgnore()] public Series<double> CurrentHigh { get { return Values[1]; } } [Browsable(false)] [XmlIgnore()] public Series<double> CurrentLow { get { return Values[2]; } } [Browsable(false)] [XmlIgnore()] public Series<double> CurrentMid { get { return Values[3]; } } [Browsable(false)] [XmlIgnore()] public Series<double> LastDayClose { get { return Values[4]; } } [Browsable(false)] [XmlIgnore()] public Series<double> LastDayHigh { get { return Values[5]; } } [Browsable(false)] [XmlIgnore()] public Series<double> LastDayLow { get { return Values[6]; } } [Browsable(false)] [XmlIgnore()] public Series<double> LastDayMiddle { get { return Values[7]; } } [Browsable(false)] [XmlIgnore()] public Series<double> CB { get { return Values[8]; } } [NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Přihlašovací jméno", Order = 4, Description = "Uživatel, kterého používáte k připojení k webu")] public string Nickname { get { return sUsername; } set { sUsername = value; } } #endregion #region Methods protected override void OnBarUpdate() { if (!Bars.BarsType.IsIntraday) return; if (currentDate != sessionIterator.GetTradingDay(Time[0]) || currentOpen == 0) { lastDayHigh = currentHigh; lastDayLow = currentLow; lastDayMid = currentMid; lastDayClose = Close[0]; // Resetuj hodnoty pro nový den currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; if (CurrentBar > 1) { //CurrentOpen[0] = currentOpen; //CurrentHigh[0] = currentHigh; //CurrentLow[0] = currentLow; //CurrentMid[0] = currentMid; // LastDayClose[0] = lastDayClose; // LastDayHigh[0] = lastDayHigh; LastDayLow[0] = lastDayLow; // LastDayMiddle[0] = lastDayMid; } } else { currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); currentMid = currentLow + ((currentHigh - currentLow) / 2); LastDayClose[0] = lastDayClose; LastDayHigh[0] = lastDayHigh; LastDayLow[0] = lastDayLow; LastDayMiddle[0] = lastDayMid; CurrentOpen[0] = currentOpen; CurrentHigh[0] = currentHigh; CurrentLow[0] = currentLow; CurrentMid[0] = currentMid; } currentDate = sessionIterator.GetTradingDay(Time[0]); } protected override void OnStateChange() { if (State == State.SetDefaults) { Description = ""; Name = "Golem_SR_Levels"; IsAutoScale = false; DrawOnPricePanel = false; IsOverlay = true; IsSuspendedWhileInactive = true; BarsRequiredToPlot = 0; AddPlot(new Stroke(Brushes.Goldenrod, DashStyleHelper.Dot, 1), PlotStyle.Square, "Today Open"); AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.Solid, 2), PlotStyle.Square, "Today High"); AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 2), PlotStyle.Square, "Today Low"); AddPlot(new Stroke(Brushes.Blue, DashStyleHelper.DashDotDot, 2), PlotStyle.Square, "Today Middle"); AddPlot(new Stroke(Brushes.Goldenrod, DashStyleHelper.Dot, 1), PlotStyle.Square, "LastDay Close"); AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.Dot, 1), PlotStyle.Square, "LastDay High"); AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Dot, 1), PlotStyle.Square, "LastDay Low"); AddPlot(new Stroke(Brushes.Blue, DashStyleHelper.Dot, 1), PlotStyle.Square, "LastDay Middle"); } else if (State == State.Configure) { currentDate = Core.Globals.MinDate; currentOpen = double.MinValue; currentHigh = double.MinValue; currentLow = double.MaxValue; } else if (State == State.DataLoaded) { sessionIterator = new SessionIterator(Bars); } else if (State == State.Historical) { if (!Bars.BarsType.IsIntraday) { Draw.TextFixed(this, "NinjaScriptInfo", Custom.Resource.CurrentDayOHLError, TextPosition.BottomRight); Log(Custom.Resource.CurrentDayOHLError, LogLevel.Error); } } } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private Golem_SR_Levels[] cacheGolem_SR_Levels; public Golem_SR_Levels Golem_SR_Levels(string nickname) { return Golem_SR_Levels(Input, nickname); } public Golem_SR_Levels Golem_SR_Levels(ISeries<double> input, string nickname) { if (cacheGolem_SR_Levels != null) for (int idx = 0; idx < cacheGolem_SR_Levels.Length; idx++) if (cacheGolem_SR_Levels[idx] != null && cacheGolem_SR_Levels[idx].Nickname == nickname && cacheGolem_SR_Levels[idx].EqualsInput(input)) return cacheGolem_SR_Levels[idx]; return CacheIndicator<Golem_SR_Levels>(new Golem_SR_Levels(){ Nickname = nickname }, input, ref cacheGolem_SR_Levels); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.Golem_SR_Levels Golem_SR_Levels(string nickname) { return indicator.Golem_SR_Levels(Input, nickname); } public Indicators.Golem_SR_Levels Golem_SR_Levels(ISeries<double> input , string nickname) { return indicator.Golem_SR_Levels(input, nickname); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.Golem_SR_Levels Golem_SR_Levels(string nickname) { return indicator.Golem_SR_Levels(Input, nickname); } public Indicators.Golem_SR_Levels Golem_SR_Levels(ISeries<double> input , string nickname) { return indicator.Golem_SR_Levels(input, nickname); } } } #endregion
Comment