I am coding the HiLo Activator in 3 time frames(with default next two time frames in 50mins and 1 day). but the step lines do not plot. I checked the codes several times, but still don't get it where is wrong.
Besides, in the single time frame HiLo, whenever I delete the DrawArrow line, the indicator does not plot either. This seems wired, because it is logically parallel with Value.Set method.
Any help about why is this happening is highly appreciated. Here is the code:
// This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// HiLo Activator with 3 time frames /// </summary> [Description("HiLo Activator with 3 time frames")] public class TripleHiLo : Indicator { #region Variables // Wizard generated variables private int length = 5; // Default setting for Length private int nextBars = 50; // Default setting for NextBars private int highBars = 1; // Default setting for HighBars // User defined variables (add any user defined variables below) private double Havg,Lavg,HavgNext,LavgNext,HavgHigh,LavgHigh; private int swing,previous_swing,swingNext,previous_swingNext,swingHigh,previous_swingHigh; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.Salmon), PlotStyle.Square, "OwnBottom")); Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.Square, "OwnHat")); Add(new Plot(Color.FromKnownColor(KnownColor.Salmon), PlotStyle.Square, "NextBottom")); Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.Square, "NextHat")); Add(new Plot(Color.FromKnownColor(KnownColor.Salmon), PlotStyle.Square, "HighBottom")); Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.Square, "HighHat")); Add(PeriodType.Minute, nextBars); Add(PeriodType.Day,highBars); CalculateOnBarClose = false; Overlay = true; PriceTypeSupported = true; // Different price types can be selected when applying an indicator to a chart } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if(BarsInProgress==0) { if(CurrentBar<length+1) return; Havg = SMA(High,length)[1]; Lavg = SMA(Low,length)[1]; if(Input[0]<Lavg) swing = -1; if(Input[0]>Havg) swing = 1; if(swing==-1) { if(previous_swing!=swing) { DrawArrowDown(CurrentBar.ToString(), true, 0, Havg, Color.Tomato); OwnHat.Set(Havg); } } if(swing==1) { if(previous_swing!=swing) { DrawArrowUp(CurrentBar.ToString(),true, 0, Lavg, Color.SkyBlue); OwnBottom.Set(Lavg); } } } if (BarsInProgress==1) { if(CurrentBar<length+1) return; HavgNext = SMA(Highs[1],length)[1]; LavgNext = SMA(Lows[1],length)[1]; if(Input[0]<LavgNext) swingNext = -1; if(Input[0]>HavgNext) swingNext = 1; if(swingNext==-1) { if(previous_swingNext!=swingNext) { DrawArrowDown(CurrentBar.ToString(), true, 0, HavgNext, Color.Tomato); NextHat.Set(HavgNext); } } if(swingNext==1) { if(previous_swingNext!=swingNext) { DrawArrowUp(CurrentBar.ToString(),true, 0, LavgNext, Color.SkyBlue); NextBottom.Set(LavgNext); } } } if (BarsInProgress==2) { if(CurrentBar<length+1) return; HavgHigh = SMA(Highs[2],length)[1]; LavgHigh = SMA(Lows[2],length)[1]; if(Input[0]<LavgHigh) swingHigh = -1; if(Input[0]>HavgHigh) swingHigh = 1; if(swingHigh==-1) { if(previous_swingHigh!=swingHigh) { DrawArrowDown(CurrentBar.ToString(), true, 0, HavgHigh, Color.Tomato); HighHat.Set(HavgHigh); } } if(swingHigh==1) { if(previous_swingHigh!=swingHigh) { DrawArrowUp(CurrentBar.ToString(),true, 0, LavgHigh, Color.SkyBlue); HighBottom.Set(LavgHigh); } } } previous_swing = swing; previous_swingNext = swingNext; previous_swingHigh = swingHigh; } #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 DataSeries OwnBottom { get { return Values[0]; } } [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 DataSeries OwnHat { get { return Values[1]; } } [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 DataSeries NextBottom { get { return Values[2]; } } [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 DataSeries NextHat { get { return Values[3]; } } [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 DataSeries HighBottom { get { return Values[4]; } } [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 DataSeries HighHat { get { return Values[5]; } } [Description("Period for all 3 time frames")] [GridCategory("Parameters")] public int Length { get { return length; } set { length = Math.Max(1, value); } } [Description("Calculating Period for BarsArray[1] (in minutes)")] [GridCategory("Parameters")] public int NextBars { get { return nextBars; } set { nextBars = Math.Max(1, value); } } [Description("Calculating Period for BarsArray[2] (in days)")] [GridCategory("Parameters")] public int HighBars { get { return highBars; } set { highBars = Math.Max(1, value); } } #endregion } }
Comment