protected override void OnCalculate() { //Init list on startup if (ProcessingBarIndex == 0) { _distributionlist = new Queue <DateTime>(); } //Delete all old if (this._distributionlist.Count() > 0 && this._distributionlist.Peek() <= Time[0].AddDays(this.Period * (-1))) { this._distributionlist.Dequeue(); } bool volumespike = false; //Volume Calculation switch (this.Volume_Calculation) { case Enum_Volume_Calucation.VolumeIsGreaterThanYesterday: if (Volume[0] > (Volume[1] * (this.VolumePercent / 100.0))) { volumespike = true; } break; case Enum_Volume_Calucation.VolumeisGreaterThantheEMAOfTheLastXCandles: if (Volume[0] > EMA(Volume, this.EMA_Period)[0]) { volumespike = true; } break; } //Draw Distribution Arrow. if (volumespike && ((Close[1] - Close[0]) / Close[1]) > (this.Percent / 100.0)) { this._distributionlist.Enqueue(Time[0]); //Draw the indicator if (ShowDistributionDayArrows) { Color color = Color.Black; if (this._distributionlist.Count > this.DistributionDayCount) { color = ColorLongSignalDistribution; AddChartArrowDown(ProcessingBarIndex.ToString(), true, 0, High[0], ColorLongSignalDistribution); } else { color = ColorLongSignalDistributionStrong; AddChartArrowDown(ProcessingBarIndex.ToString(), true, 0, High[0], ColorLongSignalDistributionStrong); } if (this.ShowDistributionDayLabel) { AddChartText("dday" + Time[0], true, "DD", Time[0], Low[0], 0, color, new Font("Arial", 8, FontStyle.Bold), StringAlignment.Far, HorizontalAlignment.Center, VerticalAlignment.Top, color, Color.White, 255); } } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnCalculate() { double rsi0, rsi1, dar, tr, dv; if (ProcessingBarIndex <= StartBar) { return; } Value1.Set(EMA(RSI(rSI_Period, 3), sF)[0]); AtrRsi.Set(Math.Abs(Value1[1] - Value1[0])); MaAtrRsi.Set(EMA(AtrRsi, Wilders_Period)[0]); tr = Value2[1]; rsi1 = Value1[1]; rsi0 = Value1[0]; dar = EMA(MaAtrRsi, Wilders_Period)[0] * 4.236; dv = tr; if (rsi0 < tr) { tr = rsi0 + dar; if (rsi1 < dv) { if (tr > dv) { tr = dv; } } } else if (rsi0 > tr) { tr = rsi0 - dar; if (rsi1 > dv) { if (tr < dv) { tr = dv; } } } Value2.Set(tr); //Change Colors PlotColors[0][0] = Line_01; PlotColors[1][0] = Line_02; //Drawing if (CrossAbove(Value1, Value2, 0)) { AddChartArrowUp(ProcessingBarIndex.ToString(), true, 0, Low[0], Color.Green); lastcrossabove = Bars[0]; AddChartText("lastsegmentpercentline" + Time[0], true, "QQI", Time[0], Low[0], 0, Color.Green, new Font("Arial", 8, FontStyle.Bold), StringAlignment.Far, HorizontalAlignment.Center, VerticalAlignment.Bottom, Color.Green, Color.White, 255); } else if (CrossBelow(Value1, Value2, 0)) { AddChartArrowDown(ProcessingBarIndex.ToString(), true, 0, High[0], Color.Red); AddChartText("lastsegmentpercentline" + Time[0], true, "QQI", Time[0], High[0], 0, Color.Red, new Font("Arial", 8, FontStyle.Bold), StringAlignment.Far, HorizontalAlignment.Center, VerticalAlignment.Top, Color.Red, Color.White, 255); } if (lastcrossabove != null && CrossBelow(Value1, Value2, 0)) { AddChartLine("drawaline" + Time[0], true, lastcrossabove.Time, lastcrossabove.Close, Time[0], Close[0], Color.Black, DashStyle.DashDotDot, 1); } }