public override void ApplyTo(StockSerie stockSerie) { FloatSerie lowEMASerie = stockSerie.GetIndicator(this.SerieNames[0]).Series[0]; FloatSerie highEMASerie = stockSerie.GetIndicator(this.SerieNames[1]).Series[0]; FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); this.Series[0] = lowEMASerie; this.Series[1] = highEMASerie; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = (int)this.parameters[0]; i < stockSerie.Count; i++) { if (lowSerie[i] > highEMASerie[i]) { this.Events[0][i] = true; if (!this.Events[0][i-1]) this.Events[2][i] = true; } else if (highSerie[i] < lowEMASerie[i]) { this.Events[1][i] = true; if (!this.Events[1][i - 1]) this.Events[3][i] = true; } else { this.Events[4][i] = true; } } }
public override void ApplyTo(StockSerie stockSerie) { // Calculate Bands int period = (int)this.parameters[0]; FloatSerie ema = stockSerie.GetIndicator("EMA(" + period + ")").Series[0]; FloatSerie atr = stockSerie.GetIndicator("ATR(" + period + ")").Series[0]; float upCoef = (float)this.parameters[1]; float downCoef = (float)this.parameters[2]; FloatSerie upperKeltnerBand = ema + atr * upCoef; this.series[0] = upperKeltnerBand; this.Series[0].Name = this.SerieNames[0]; FloatSerie lowerKeltnerBand = ema + atr * downCoef; this.series[1] = lowerKeltnerBand; this.Series[1].Name = this.SerieNames[1]; // Detecting events this.CreateEventSeries(stockSerie.Count); FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); for (int i = 1; i < upperKeltnerBand.Count; i++) { this.eventSeries[0][i] = closeSerie[i] > upperKeltnerBand[i]; this.eventSeries[1][i] = closeSerie[i] < lowerKeltnerBand[i]; this.eventSeries[2][i] = closeSerie[i] >= lowerKeltnerBand[i] && closeSerie[i] <= upperKeltnerBand[i]; } }
public static IStockViewableSeries CreateInitialisedFrom(IStockViewableSeries aViewableSerie, StockSerie stockSerie) { if (!stockSerie.Initialise()) return null; IStockViewableSeries viewableSerie = null; switch (aViewableSerie.Type) { case ViewableItemType.Indicator: viewableSerie = stockSerie.GetIndicator(aViewableSerie.Name); break; case ViewableItemType.Decorator: viewableSerie = stockSerie.GetDecorator(aViewableSerie.Name, ((IStockDecorator)aViewableSerie).DecoratedItem); break; case ViewableItemType.PaintBar: viewableSerie = stockSerie.GetPaintBar(aViewableSerie.Name); break; case ViewableItemType.TrailStop: viewableSerie = stockSerie.GetTrailStop(aViewableSerie.Name); break; case ViewableItemType.Trail: viewableSerie = stockSerie.GetTrail(aViewableSerie.Name, ((IStockTrail)aViewableSerie).TrailedItem); break; default: break; } return viewableSerie; }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie fastSerie = stockSerie.GetIndicator(this.SerieNames[0]).Series[0].ShiftForward((int)this.parameters[3]); FloatSerie mediumSerie = stockSerie.GetIndicator(this.SerieNames[1]).Series[0].ShiftForward((int)this.parameters[4]); FloatSerie slowSerie = stockSerie.GetIndicator(this.SerieNames[2]).Series[0].ShiftForward((int)this.parameters[5]); this.Series[0] = fastSerie; this.Series[1] = mediumSerie; this.Series[2] = slowSerie; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 2; i < stockSerie.Count; i++) { if (fastSerie[i] > mediumSerie[i] && mediumSerie[i] > slowSerie[i]) { this.Events[0][i] = true; } else if (fastSerie[i] < mediumSerie[i] && mediumSerie[i] < slowSerie[i]) { this.Events[1][i] = true; } } }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie indicatorSerie = stockSerie.GetIndicator(this.parameters[0].ToString()).Series[0]; FloatSerie speedSerie = indicatorSerie - indicatorSerie.CalculateEMA((int) this.parameters[1]); this.series[0] = speedSerie; this.Series[0].Name = this.Name; }
public override void ApplyTo(StockSerie stockSerie) { int period = (int)this.parameters[0]; int smoothing = (int)this.parameters[1]; IStockIndicator donchianIndicator = stockSerie.GetIndicator("DONCHIAN(" + period + ")"); // Calculate Donchian Channel FloatSerie upLine = donchianIndicator.Series[0]; FloatSerie downLine = donchianIndicator.Series[4]; FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); this.series[0] = ((upLine - downLine) / (closeSerie * 0.01f)).CalculateEMA(smoothing); this.Series[0].Name = this.SerieNames[0]; // Detecting events this.CreateEventSeries(stockSerie.Count); }
public override void ApplyTo(StockSerie stockSerie) { int period = (int)this.parameters[0]; IStockIndicator momentum = stockSerie.GetIndicator("MOMENTUM(" + period + ",1,10)"); FloatSerie momentumSerie = momentum.Series[0]; FloatSerie atrSerie = stockSerie.GetSerie(StockDataType.ATR); FloatSerie distSerie = momentumSerie.Div(atrSerie.Cumul(period)); //cciSerie = cciSerie.CalculateSigmoid(100f, 0.02f).CalculateEMA((int)Math.Sqrt(); //FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); //for (int i = 10; i < cciSerie.Count; i++) //{ // if (cciSerie[i] > overbought && cciSerie[i] <= cciSerie[i - 1] && closeSerie[i] >= closeSerie[i-1]) // { // cciSerie[i] = cciSerie[i - 1] + (100 - cciSerie[i - 1]) / 4f; // } // else if (cciSerie[i] < oversold && cciSerie[i] >= cciSerie[i - 1] && closeSerie[i] <= closeSerie[i-1]) // { // cciSerie[i] = cciSerie[i - 1] *0.75f; // } //} this.series[0] = distSerie; this.series[0].Name = this.Name; }
public override void ApplyTo(StockSerie stockSerie) { // Calculate Bollinger Bands FloatSerie upperBB = null; FloatSerie lowerBB = null; FloatSerie ema = stockSerie.GetIndicator(this.parameters[1] + "(" + (int)this.parameters[0] + ")").Series[0]; stockSerie.GetSerie(StockDataType.CLOSE).CalculateBB(ema, (int)this.parameters[0], 1f, -1f, ref upperBB, ref lowerBB); FloatSerie widthLog = ((upperBB - lowerBB)/ema)*20.0f; for (int i = (int) this.parameters[0]; i < stockSerie.Count; i++) { widthLog[i] = (float)Math.Log10(widthLog[i]); } this.series[0] = widthLog; this.Series[0].Name = this.SerieNames[0]; // Detecting events this.CreateEventSeries(stockSerie.Count); }
public override void ApplyTo(StockSerie stockSerie) { // Detecting events this.CreateEventSeries(stockSerie.Count); FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); FloatSerie atr1Serie = stockSerie.GetIndicator("ATR(1)").Series[0]; FloatSerie atr20Serie = stockSerie.GetIndicator("ATR(20)").Series[0]; for (int i = 1; i < stockSerie.Count; i++) { // Check Gaps this.eventSeries[0][i] = highSerie[i - 1] < lowSerie[i]; this.eventSeries[1][i] = lowSerie[i - 1] > highSerie[i]; this.eventSeries[2][i] = atr1Serie[i] > 1.5*atr20Serie[i]; } }
public bool EMAUp(int i, StockSerie stockSerie) { FloatSerie ema6 = stockSerie.GetIndicator("EMA(6)").Series[0]; FloatSerie ema12 = stockSerie.GetIndicator("EMA(12)").Series[0]; FloatSerie ema50 = stockSerie.GetIndicator("EMA(50)").Series[0]; FloatSerie longStop = stockSerie.GetTrailStop("TRAILHL(3)").Series[0]; FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); return (!float.IsNaN(longStop[i - 1]) && !float.IsNaN(longStop[i]) && closeSerie[i] < ema50[i]); }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie fastSerie = stockSerie.GetIndicator(this.SerieNames[0]).Series[0]; FloatSerie slowSerie = stockSerie.GetIndicator(this.SerieNames[1]).Series[0]; FloatSerie closeSerie = (stockSerie.GetSerie(StockDataType.CLOSE) + stockSerie.GetSerie(StockDataType.HIGH) + stockSerie.GetSerie(StockDataType.LOW)) / 3.0f; this.Series[0] = fastSerie; this.Series[1] = slowSerie; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 2; i < stockSerie.Count; i++) { if (fastSerie[i] > slowSerie[i]) { if (closeSerie[i] > fastSerie[i]) { this.Events[2][i] = true; } else { this.Events[4][i] = true; } if (fastSerie[i - 1] < slowSerie[i - 1]) { this.Events[0][i] = true; } } else { if (closeSerie[i] < fastSerie[i]) { this.Events[3][i] = true; } else { this.Events[5][i] = true; } if (fastSerie[i - 1] > slowSerie[i - 1]) { this.Events[1][i] = true; } } } }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie trail1Serie = new FloatSerie(stockSerie.Count); //FloatSerie trail2Serie = new FloatSerie(stockSerie.Count); //FloatSerie trail3Serie = new FloatSerie(stockSerie.Count); int period = (int)this.parameters[0]; BoolSerie event1 = stockSerie.GetIndicator("TRAILHLSR(" + period + ")").Events[8]; BoolSerie event2 = stockSerie.GetIndicator("TRAILHLSR(" + period * 3 + ")").Events[8]; BoolSerie event3 = stockSerie.GetIndicator("TRAILHLSR(" + period * 9 + ")").Events[8]; BoolSerie event4 = stockSerie.GetIndicator("TRAILHLSR(" + period * 27 + ")").Events[8]; for (int i = period * 9; i < stockSerie.Count; i++) { trail1Serie[i] = (event1[i] ? 1f : -1f) + (event2[i] ? 2f : -2f) + (event3[i] ? 3f : -3f) + (event4[i] ? 4f : -4f); //trail2Serie[i] = event2[i] ? 2f : -2f; //trail3Serie[i] = event3[i] ? 3f : -3f; } this.series[0] = trail1Serie; //this.series[1] = trail2Serie; //this.series[2] = trail3Serie; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 10; i < stockSerie.Count; i++) { this.eventSeries[0][i] = event1[i] && event2[i] && event3[i]; this.eventSeries[1][i] = !(event1[i] || event2[i] || event3[i]); this.eventSeries[2][i] = this.eventSeries[0][i] && !this.eventSeries[0][i - 1]; this.eventSeries[3][i] = this.eventSeries[1][i] && !this.eventSeries[1][i - 1]; } }
public override void ApplyTo(StockSerie stockSerie) { int period = (int)this.parameters[0]; FloatSerie stdevSerie = stockSerie.GetSerie(StockDataType.CLOSE).CalculateStdev(period); FloatSerie emaSerie = stockSerie.GetIndicator("EMA(" + period + ")").Series[0]; FloatSerie stdevCount = new FloatSerie(emaSerie.Count, this.SerieNames[0]); FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); for (int i = period; i < emaSerie.Count; i++) { if (stdevSerie[i] >= -0.00001f && stdevSerie[i] <= 0.00001f) { stdevCount[i] = 0; } else { stdevCount[i] = (closeSerie[i] - emaSerie[i]) / stdevSerie[i]; } } this.Series[0] = stdevCount; }
public override void ApplyTo(StockSerie stockSerie) { using (MethodLogger ml = new MethodLogger(this)) { List<string> eventNames = this.EventNames.ToList(); int ExhaustionTopIndex = eventNames.IndexOf("ExhaustionTop"); int ExhaustionBottomIndex = eventNames.IndexOf("ExhaustionBottom"); int BearishDivergenceIndex = eventNames.IndexOf("BearishDivergence"); int BullishDivergenceIndex = eventNames.IndexOf("BullishDivergence"); int ExhaustionTopOccuredIndex = eventNames.IndexOf("ExhaustionTopOccured"); int ExhaustionBottomOccuredIndex = eventNames.IndexOf("ExhaustionBottomOccured"); int PositiveIndex = eventNames.IndexOf("Positive"); int NegativeIndex = eventNames.IndexOf("Negative"); int BullishIndex = eventNames.IndexOf("Bullish"); int BearishIndex = eventNames.IndexOf("Bearish"); int BearFailureIndex = eventNames.IndexOf("BearFailure"); int BullFailureIndex = eventNames.IndexOf("BullFailure"); CreateEventSeries(stockSerie.Count); int smoothing = (int)this.parameters[0]; float overbought = (float)this.parameters[1]; float oversold = (float)this.parameters[2]; int lookbackPeriod = (int)this.parameters[3]; int signalSmoothing = (int)this.parameters[4]; int countNegative = 0; int countPositive = 0; IStockIndicator indicator = stockSerie.GetIndicator(this.DecoratedItem); if (indicator != null && indicator.Series[0].Count > 0) { FloatSerie indicatorToDecorate = indicator.Series[0].CalculateEMA(smoothing); FloatSerie signalSerie = indicatorToDecorate.CalculateEMA(signalSmoothing); FloatSerie upperLimit = new FloatSerie(indicatorToDecorate.Count); upperLimit.Reset(overbought); FloatSerie lowerLimit = new FloatSerie(indicatorToDecorate.Count); lowerLimit.Reset(oversold); if (smoothing <= 1) { this.SerieVisibility[0] = false; } if (signalSmoothing <= 1) { this.SerieVisibility[3] = false; } this.Series[0] = indicatorToDecorate; this.Series[0].Name = this.SerieNames[0]; this.Series[1] = upperLimit; this.Series[1].Name = this.SerieNames[1]; this.Series[2] = lowerLimit; this.Series[2].Name = this.SerieNames[2]; this.Series[3] = signalSerie; this.Series[3].Name = this.SerieNames[3]; if (indicator.DisplayTarget == IndicatorDisplayTarget.RangedIndicator && indicator is IRange) { IRange range = (IRange)indicator; indicatorToDecorate = indicatorToDecorate.Sub((range.Max + range.Min) / 2.0f); } FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); int lastExhaustionSellIndex = int.MinValue; int lastExhaustionBuyIndex = int.MinValue; float exhaustionBuyPrice = highSerie[0]; float exhaustionSellPrice = lowSerie[0]; float previousValue = indicatorToDecorate[0]; float currentValue; int i = 0; for (i = 1; i < indicatorToDecorate.Count - 1; i++) { if (indicatorToDecorate[i] > 0) { this.Events[PositiveIndex][i] = true; countPositive++; countNegative = 0; } else { this.Events[NegativeIndex][i] = true; countPositive = 0; countNegative++; } if (indicatorToDecorate[i] > signalSerie[i]) { this.Events[BullishIndex][i] = true; } else { this.Events[BearishIndex][i] = true; } currentValue = indicatorToDecorate[i]; if (currentValue == previousValue) { if (indicatorToDecorate.IsBottomIsh(i)) { if (currentValue <= oversold) { // This is an exhaustion selling this.Events[ExhaustionBottomIndex][i + 1] = true; exhaustionSellPrice = lowSerie[i]; lastExhaustionSellIndex = i + 1; } else { // Check if divergence if (lowSerie[i] <= exhaustionSellPrice) { this.Events[BullishDivergenceIndex][i + 1] = true; } } } else if (indicatorToDecorate.IsTopIsh(i)) { if (currentValue >= overbought) { // This is an exhaustion buying this.Events[ExhaustionTopIndex][i + 1] = true; exhaustionBuyPrice = highSerie[i]; lastExhaustionBuyIndex = i + 1; } else { // Check if divergence if (highSerie[i] >= exhaustionBuyPrice) { this.Events[BearishDivergenceIndex][i + 1] = true; } } } } else if (currentValue < previousValue) { if (indicatorToDecorate.IsBottom(i)) { if (currentValue <= oversold) { // This is an exhaustion selling this.Events[ExhaustionBottomIndex][i + 1] = true; exhaustionSellPrice = lowSerie[i]; lastExhaustionSellIndex = i + 1; } else { // Check if divergence if (lowSerie[i] <= exhaustionSellPrice) { this.Events[BullishDivergenceIndex][i + 1] = true; } } } } else if (currentValue > previousValue) { if (indicatorToDecorate.IsTop(i)) { if (currentValue >= overbought) { // This is an exhaustion selling this.Events[ExhaustionTopIndex][i + 1] = true; exhaustionBuyPrice = highSerie[i]; lastExhaustionBuyIndex = i + 1; } else { // Check if divergence if (highSerie[i] >= exhaustionBuyPrice) { this.Events[BearishDivergenceIndex][i + 1] = true; } } } } previousValue = currentValue; // Exhaustion occured events if (lookbackPeriod > 0) { if (i + 1 - lookbackPeriod < lastExhaustionBuyIndex) { this.Events[ExhaustionTopOccuredIndex][i + 1] = true; } if (i + 1 - lookbackPeriod < lastExhaustionSellIndex) { this.Events[ExhaustionBottomOccuredIndex][i + 1] = true; } } this.Events[BearFailureIndex][i] = (this.Events[ExhaustionTopOccuredIndex][i] && countPositive == 1); this.Events[BullFailureIndex][i] = (this.Events[ExhaustionBottomOccuredIndex][i] && countNegative == 1); } } else { for (int i = 0; i < this.EventNames.Length; i++) { this.Events[i] = new BoolSerie(0, this.EventNames[i]); } } } }
public override void ApplyTo(StockSerie stockSerie) { IStockIndicator fastSerie = stockSerie.GetIndicator("EMA(" + this.parameters[0] + ")"); IStockIndicator slowSerie = stockSerie.GetIndicator("EMA(" + this.parameters[1] + ")"); FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); FloatSerie POSCSerie = fastSerie.Series[0].Sub(slowSerie.Series[0]) / closeSerie; this.series[0] = POSCSerie; this.Series[0].Name = this.Name; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 2; i < stockSerie.Count; i++) { this.eventSeries[0][i] = (POSCSerie[i - 2] < POSCSerie[i - 1] && POSCSerie[i - 1] > POSCSerie[i]); this.eventSeries[1][i] = (POSCSerie[i - 2] > POSCSerie[i - 1] && POSCSerie[i - 1] < POSCSerie[i]); this.eventSeries[2][i] = (POSCSerie[i - 1] < 0 && POSCSerie[i] >= 0); this.eventSeries[3][i] = (POSCSerie[i - 1] > 0 && POSCSerie[i] <= 0); } }
public bool TrailHL(int i, StockSerie stockSerie, ref string eventName) { eventName = "UpBreak_TRAILHL(4)"; BoolSerie upTrend = stockSerie.GetTrailStop("TRAILHL(1)").Events[0]; BoolSerie upBar = stockSerie.GetPaintBar("HIGHLOWDAYS(6)").Events[0]; FloatSerie roc = stockSerie.GetIndicator("ROCEX3(200,100,50,10,20)").Series[0]; return upTrend[i] && roc[i] > 0 && (upBar[i] && !upBar[i - 1]); }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie HMACDSerie = stockSerie.GetIndicator("HOSC(" + this.parameters[1] + "," + this.parameters[0] + ")").Series[0]; FloatSerie signalSerie = HMACDSerie.CalculateMA((int)this.parameters[2]); this.series[0] = HMACDSerie; this.series[0].Name = this.SerieNames[0]; this.series[1] = signalSerie; this.series[1].Name = this.SerieNames[1]; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 1; i < HMACDSerie.Count; i++) { this.eventSeries[0][i] = HMACDSerie[i] >= 0; this.eventSeries[1][i] = HMACDSerie[i] < 0; this.eventSeries[2][i] = signalSerie[i] < HMACDSerie[i]; this.eventSeries[3][i] = signalSerie[i] > HMACDSerie[i]; } }
public static IStockViewableSeries GetViewableItem(string fullString, StockSerie stockSerie) { IStockViewableSeries viewableSerie = null; string[] fields = fullString.Split('|'); int offset = 2; switch (fields[0].ToUpper()) { case "INDICATOR": if (stockSerie == null) { viewableSerie = StockIndicatorManager.CreateIndicator(fields[1]); } else { viewableSerie = stockSerie.GetIndicator(fields[1]); } offset = 2; break; case "PAINTBAR": if (stockSerie == null) { viewableSerie = StockPaintBarManager.CreatePaintBar(fields[1]); } else { viewableSerie = stockSerie.GetPaintBar(fields[1]); } offset = 2; break; case "TRAILSTOP": if (stockSerie == null) { viewableSerie = StockTrailStopManager.CreateTrailStop(fields[1]); } else { viewableSerie = stockSerie.GetTrailStop(fields[1]); } offset = 2; break; case "DECORATOR": if (stockSerie == null) { viewableSerie = StockDecoratorManager.CreateDecorator(fields[1], fields[2]); } else { viewableSerie = stockSerie.GetDecorator(fields[1], fields[2]); } offset = 3; break; case "TRAIL": if (stockSerie == null) { viewableSerie = StockTrailManager.CreateTrail(fields[1], fields[2]); } else { viewableSerie = stockSerie.GetTrail(fields[1], fields[2]); } offset = 3; break; default: return null; } if (viewableSerie != null) { for (int i = 0; i < viewableSerie.SeriesCount; i++) { int index = 2 * i + offset; if (index < fields.Length) { viewableSerie.SeriePens[i] = GraphCurveType.PenFromString(fields[index]); viewableSerie.SerieVisibility[i] = bool.Parse(fields[index + 1]); } else { viewableSerie.SerieVisibility[i] = true; } } if (fields[0].ToUpper() == "DECORATOR") { offset += viewableSerie.SeriesCount*2; IStockDecorator decorator = viewableSerie as IStockDecorator; for (int i = 0; i < decorator.EventCount; i++) { int index = 2 * i + offset; if (index < fields.Length) { decorator.EventPens[i] = GraphCurveType.PenFromString(fields[index]); decorator.EventVisibility[i] = bool.Parse(fields[index + 1]); } else { decorator.EventVisibility[i] = true; } } } } return viewableSerie; }
public override void ApplyTo(StockSerie stockSerie) { Queue<float> resistanceQueue = new Queue<float>(new float[] {float.MinValue, float.MinValue}); Queue<float> supportQueue = new Queue<float>(new float[] {float.MaxValue, float.MaxValue}); int period = (int) this.Parameters[0]; IStockIndicator indicator1 = stockSerie.GetIndicator("TRAILHLSR(" + period + ")"); this.Series[0] = indicator1.Series[0]; this.Series[0].Name = this.SerieNames[0]; this.Series[1] = indicator1.Series[1]; this.Series[1].Name = this.SerieNames[1]; IStockIndicator indicator2 = stockSerie.GetIndicator("TRAILHLSR(" + period * 3 + ")"); this.Series[2] = indicator2.Series[0]; this.Series[2].Name = this.SerieNames[2]; this.Series[3] = indicator2.Series[1]; this.Series[3].Name = this.SerieNames[3]; IStockIndicator indicator3 = stockSerie.GetIndicator("TRAILHLSR(" + period * 9 + ")"); this.Series[4] = indicator3.Series[0]; this.Series[4].Name = this.SerieNames[4]; this.Series[5] = indicator3.Series[1]; this.Series[5].Name = this.SerieNames[5]; // Detecting events this.eventSeries = indicator2.Events; }
public override void ApplyTo(StockSerie stockSerie) { // Calculate Bollinger Bands FloatSerie upperBB = null; FloatSerie lowerBB = null; IStockIndicator emaIndicator = stockSerie.GetIndicator(this.parameters[3] + "(" + (int)this.parameters[0] + ")"); stockSerie.GetSerie(StockDataType.CLOSE).CalculateBBEX(emaIndicator.Series[0], (int)this.parameters[0], (float)this.parameters[1], (float)this.parameters[2], ref upperBB, ref lowerBB); this.series[0] = upperBB; this.Series[0].Name = this.SerieNames[0]; this.series[1] = lowerBB; this.Series[1].Name = this.SerieNames[1]; this.series[2] = emaIndicator.Series[0]; this.Series[2].Name = this.SerieNames[2]; // Detecting events this.CreateEventSeries(stockSerie.Count); FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); bool waitingForBearSignal = false; bool waitingForBullSignal = false; for (int i = 1; i < upperBB.Count; i++) { if (waitingForBearSignal && highSerie[i - 1] >= highSerie[i] && closeSerie[i - 1] >= closeSerie[i]) { // BearishSignal this.eventSeries[3][i] = true; waitingForBearSignal = false; } if (highSerie[i] >= upperBB[i]) { waitingForBearSignal = true; this.eventSeries[0][i] = true; } if (waitingForBullSignal && lowSerie[i - 1] <= lowSerie[i] && closeSerie[i - 1] <= closeSerie[i]) { // BullishSignal this.eventSeries[2][i] = true; waitingForBullSignal = false; } if (lowSerie[i] <= lowerBB[i]) { waitingForBullSignal = true; this.eventSeries[1][i] = lowSerie[i] <= lowerBB[i]; } } }
public override void ApplyTo(StockSerie stockSerie) { using (MethodLogger ml = new MethodLogger(this)) { CreateEventSeries(stockSerie.Count); IStockIndicator indicator = stockSerie.GetIndicator(this.DecoratedItem); if (indicator != null && indicator.Series[0].Count > 0) { FloatSerie indicatorToDecorate = indicator.Series[0].CalculateEMA((int)this.parameters[1]); FloatSerie signalSerie = indicatorToDecorate.CalculateEMA((int)this.parameters[3]); FloatSerie upperLimit = new FloatSerie(indicatorToDecorate.Count); FloatSerie lowerLimit = new FloatSerie(indicatorToDecorate.Count); if ((int)this.parameters[1] <= 1) { this.SerieVisibility[0] = false; } this.Series[0] = indicatorToDecorate; this.Series[0].Name = this.SerieNames[0]; this.Series[1] = upperLimit; this.Series[1].Name = this.SerieNames[1]; this.Series[2] = lowerLimit; this.Series[2].Name = this.SerieNames[2]; this.Series[3] = signalSerie; this.Series[3].Name = this.SerieNames[3]; int lookbackPeriod = (int) this.parameters[2]; if (indicator.DisplayTarget == IndicatorDisplayTarget.RangedIndicator && indicator is IRange) { IRange range = (IRange)indicator; indicatorToDecorate = indicatorToDecorate.Sub((range.Max + range.Min) / 2.0f); } FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); int lastExhaustionSellIndex = int.MinValue; int lastExhaustionBuyIndex = int.MinValue; float exhaustionSellLimit = indicatorToDecorate[0]; float exhaustionBuyLimit = indicatorToDecorate[0]; float exhaustionBuyPrice = highSerie[0]; float exhaustionSellPrice = lowSerie[0]; float exFadeOut = (100.0f - (float)this.parameters[0]) / 100.0f; float previousValue = indicatorToDecorate[0]; float currentValue; int i = 0; for (i = 1; i < indicatorToDecorate.Count - 1; i++) { if (indicatorToDecorate[i] > 0) { this.Events[6][i] = true; } else { this.Events[7][i] = true; } if (indicatorToDecorate[i] >signalSerie[i]) { this.Events[8][i] = true; } else { this.Events[9][i] = true; } currentValue = indicatorToDecorate[i]; if (currentValue == previousValue) { if (indicatorToDecorate.IsBottomIsh(i)) { if (currentValue <= exhaustionSellLimit) { // This is an exhaustion selling this.Events[1][i+1] = true; exhaustionSellPrice = lowSerie[i]; exhaustionSellLimit = currentValue; lastExhaustionSellIndex = i + 1; } else { // Check if divergence if (lowSerie[i] <= exhaustionSellPrice) { this.Events[3][i + 1] = true; } exhaustionSellLimit *= exFadeOut; } exhaustionBuyLimit *= exFadeOut; } else if (indicatorToDecorate.IsTopIsh(i)) { if (currentValue >= exhaustionBuyLimit) { // This is an exhaustion buying this.Events[0][i + 1] = true; exhaustionBuyPrice = highSerie[i]; exhaustionBuyLimit = currentValue; lastExhaustionBuyIndex = i + 1; } else { // Check if divergence if (highSerie[i] >= exhaustionBuyPrice) { this.Events[2][i + 1] = true; } exhaustionSellLimit *= exFadeOut; } exhaustionBuyLimit *= exFadeOut; } else { exhaustionSellLimit *= exFadeOut; exhaustionBuyLimit *= exFadeOut; } } else if (currentValue < previousValue) { if (indicatorToDecorate.IsBottom(i)) { if (currentValue <= exhaustionSellLimit) { // This is an exhaustion selling this.Events[1][i + 1] = true; exhaustionSellPrice = lowSerie[i]; exhaustionSellLimit = currentValue; lastExhaustionSellIndex = i + 1; } else { // Check if divergence if (lowSerie[i] <= exhaustionSellPrice) { this.Events[3][i + 1] = true; } exhaustionSellLimit *= exFadeOut; } exhaustionBuyLimit *= exFadeOut; } else { // trail exhaustion limit down exhaustionSellLimit = Math.Min(currentValue, exhaustionSellLimit); exhaustionBuyLimit *= exFadeOut; } } else if (currentValue > previousValue) { if (indicatorToDecorate.IsTop(i)) { if (currentValue >= exhaustionBuyLimit) { // This is an exhaustion selling this.Events[0][i + 1] = true; exhaustionBuyPrice = highSerie[i]; exhaustionBuyLimit = currentValue; lastExhaustionBuyIndex = i + 1; } else { // Check if divergence if (highSerie[i] >= exhaustionBuyPrice) { this.Events[2][i + 1] = true; } exhaustionSellLimit *= exFadeOut; } exhaustionBuyLimit *= exFadeOut; } else { // trail exhaustion limit up exhaustionBuyLimit = Math.Max(currentValue, exhaustionBuyLimit); exhaustionSellLimit *= exFadeOut; } } else { exhaustionSellLimit *= exFadeOut; exhaustionBuyLimit *= exFadeOut; } previousValue = currentValue; upperLimit[i] = exhaustionBuyLimit; lowerLimit[i] = exhaustionSellLimit; // Exhaustion occured events if (lookbackPeriod > 0) { if (i + 1 - lookbackPeriod < lastExhaustionBuyIndex) { this.Events[4][i + 1] = true; } if (i + 1 - lookbackPeriod < lastExhaustionSellIndex) { this.Events[5][i + 1] = true; } } } // Update last values exhaustionSellLimit *= exFadeOut; exhaustionBuyLimit *= exFadeOut; upperLimit[i] = exhaustionBuyLimit; lowerLimit[i] = exhaustionSellLimit; if (indicator.DisplayTarget == IndicatorDisplayTarget.RangedIndicator && indicator is IRange) { IRange range = (IRange)indicator; this.Series[1] = upperLimit.Add((range.Max + range.Min) / 2.0f); this.Series[2] = lowerLimit.Add((range.Max + range.Min) / 2.0f); } } else { for (int i = 0; i < this.EventNames.Length; i++) { this.Events[i] = new BoolSerie(0, this.EventNames[i]); } } } }
public bool BuyMomex(int i, StockSerie stockSerie) { FloatSerie momexExhaution = stockSerie.GetIndicator("BUYMOMEX(20,True,1.5)").Series[0]; return momexExhaution[i - 2] < momexExhaution[i - 1] && momexExhaution[i - 1] > momexExhaution[i] && momexExhaution[i - 1] > 35f; }
public override void ApplyTo(StockSerie stockSerie) { // Set HLine value float trendThreshold = (float)this.Parameters[1]; int period = (int)this.Parameters[0]; FloatSerie atrSerie = stockSerie.GetIndicator("ATR(" + period + ")").Series[0]; FloatSerie pDM = new FloatSerie(stockSerie.Count); FloatSerie mDM = new FloatSerie(stockSerie.Count); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW).CalculateEMA((int)this.Parameters[2]); FloatSerie higherie = stockSerie.GetSerie(StockDataType.HIGH).CalculateEMA((int)this.Parameters[2]); // Calculate +DM and -DM for (int i = 1; i < stockSerie.Count; i++) { float rangeUp = higherie[i] - higherie[i - 1]; float rangeDown = lowSerie[i - 1] - lowSerie[i]; if (rangeUp > rangeDown) { pDM[i] = Math.Max(0, rangeUp); } else { mDM[i] = Math.Max(0, rangeDown); } } // Calclate +DI and -DI FloatSerie pDI = pDM.CalculateEMA(period).Div(atrSerie).Mult(100); FloatSerie mDI = mDM.CalculateEMA(period).Div(atrSerie).Mult(100); FloatSerie ADX = ((pDI - mDI).Abs() / (pDI + mDI)).CalculateEMA(period).Mult(100); ADX.Name = this.SerieNames[0]; pDI.Name = this.SerieNames[1]; mDI.Name = this.SerieNames[2]; this.Series[0] = ADX; this.Series[1] = pDI; this.Series[2] = mDI; // Manage events this.CreateEventSeries(stockSerie.Count); for (int i = period; i < stockSerie.Count; i++) { this.eventSeries[0][i] = ADX[i] > trendThreshold && ADX[i] > ADX[i - 1] && pDI[i] > mDI[i]; this.eventSeries[1][i] = ADX[i] > trendThreshold && ADX[i] > ADX[i - 1] && pDI[i] < mDI[i]; } }
public override void ApplyTo(StockSerie stockSerie) { // Detecting events this.CreateEventSeries(stockSerie.Count); FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH); FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); // Calculate Bands FloatSerie bbOSC = new FloatSerie(stockSerie.Count); FloatSerie emaSlowSerie = stockSerie.GetIndicator(this.parameters[4] + "(" + (int)this.parameters[1] + ")").Series[0]; FloatSerie emaFastSerie = stockSerie.GetIndicator(this.parameters[4] + "(" + (int)this.parameters[0] + ")").Series[0]; FloatSerie oscSerie = (emaFastSerie - emaSlowSerie) / emaFastSerie; bbOSC[0] = emaFastSerie[0]; for (int i = 1; i < stockSerie.Count; i++) { if (oscSerie[i] >= 0) { this.eventSeries[2][i] = lowSerie[i] > emaSlowSerie[i]; bbOSC[i] = emaFastSerie[i] * (oscSerie[i] * (float)this.parameters[2] + 1f); this.eventSeries[1][i] = highSerie[i-1] > bbOSC[i-1] && highSerie[i] < bbOSC[i]; } else { this.eventSeries[3][i] = highSerie[i] < emaSlowSerie[i]; bbOSC[i] = emaFastSerie[i] / (oscSerie[i] * -(float)this.parameters[2] + 1f); this.eventSeries[0][i] = lowSerie[i - 1] < bbOSC[i - 1] && lowSerie[i]> bbOSC[i]; } } this.series[0] = bbOSC; this.Series[0].Name = this.SerieNames[0]; this.series[1] = emaSlowSerie; this.Series[1].Name = this.SerieNames[1]; this.series[2] = emaFastSerie; this.Series[2].Name = this.SerieNames[2]; }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie longStopSerie; FloatSerie shortStopSerie; FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW); FloatSerie HighSerie = stockSerie.GetSerie(StockDataType.HIGH); IStockIndicator bbIndicator = stockSerie.GetIndicator(this.Name.Replace("TRAIL", "")); stockSerie.CalculateBBTrailStop(bbIndicator.Series[1], bbIndicator.Series[0], out longStopSerie, out shortStopSerie); this.Series[0] = longStopSerie; this.Series[1] = shortStopSerie; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 5; i < stockSerie.Count; i++) { bool upTrend; this.Events[0][i] = upTrend = float.IsNaN(shortStopSerie[i]); this.Events[1][i] = !upTrend; this.Events[2][i] = upTrend && !this.Events[0][i - 1]; this.Events[3][i] = !upTrend && !this.Events[1][i - 1]; this.Events[4][i] = upTrend && this.Events[0][i - 1] && lowSerie[i - 1] <= longStopSerie[i - 1] && lowSerie[i] > longStopSerie[i]; this.Events[5][i] = !upTrend && this.Events[1][i - 1] && HighSerie[i - 1] >= shortStopSerie[i - 1] && HighSerie[i] < shortStopSerie[i]; ; } }
public override void ApplyTo(StockSerie stockSerie) { // Set HLine value float trendThreshold = 25; // Used only for event calculation int smoothing = (int)this.Parameters[1]; int period = (int)this.Parameters[0]; var adx = stockSerie.GetIndicator("ADX(" + period + "," + trendThreshold + "," + smoothing + ")"); this.Series[0] = (adx.Series[1] - adx.Series[2]); this.Series[0].Name = this.Name; this.CreateEventSeries(stockSerie.Count); for (int i = period; i < stockSerie.Count; i++) { this.eventSeries[0][i] = adx.Series[1][i] > adx.Series[2][i]; this.eventSeries[1][i] = adx.Series[1][i] < adx.Series[2][i]; } }
public override void ApplyTo(StockSerie stockSerie) { IStockIndicator fastSerie = stockSerie.GetIndicator("EMA(" + this.parameters[0] + ")"); IStockIndicator slowSerie = stockSerie.GetIndicator("EMA(" + this.parameters[1] + ")"); bool relative = (bool) this.parameters[2]; FloatSerie oscSerie = (fastSerie.Series[0].Sub(slowSerie.Series[0]))*100f; if (relative) { oscSerie = oscSerie / fastSerie.Series[0]; } this.series[0] = oscSerie; this.Series[0].Name = this.Name; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 2; i < stockSerie.Count; i++) { this.eventSeries[0][i] = (oscSerie[i - 2] < oscSerie[i - 1] && oscSerie[i - 1] > oscSerie[i]); this.eventSeries[1][i] = (oscSerie[i - 2] > oscSerie[i - 1] && oscSerie[i - 1] < oscSerie[i]); this.eventSeries[2][i] = (oscSerie[i - 1] < 0 && oscSerie[i] >= 0); this.eventSeries[3][i] = (oscSerie[i - 1] > 0 && oscSerie[i] <= 0); this.eventSeries[4][i] = oscSerie[i] >= 0; this.eventSeries[5][i] = oscSerie[i] < 0; } }
public override void ApplyTo(StockSerie stockSerie) { IStockIndicator oscSerie = stockSerie.GetIndicator("OSC(" + this.parameters[0] + ","+ this.parameters[1] +")"); FloatSerie fastSerie = oscSerie.Series[0].CalculateEMA((int)this.parameters[0]); FloatSerie slowSerie = oscSerie.Series[0].CalculateEMA((int)this.parameters[1]); FloatSerie accelSerie = fastSerie.Sub(slowSerie); this.series[0] = accelSerie; this.Series[0].Name = this.Name; // Detecting events this.CreateEventSeries(stockSerie.Count); for (int i = 2; i < stockSerie.Count; i++) { this.eventSeries[0][i] = (accelSerie[i - 2] < accelSerie[i - 1] && accelSerie[i - 1] > accelSerie[i]); this.eventSeries[1][i] = (accelSerie[i - 2] > accelSerie[i - 1] && accelSerie[i - 1] < accelSerie[i]); this.eventSeries[2][i] = (accelSerie[i - 1] < 0 && accelSerie[i] >= 0); this.eventSeries[3][i] = (accelSerie[i - 1] > 0 && accelSerie[i] <= 0); this.eventSeries[4][i] = accelSerie[i] >= 0; this.eventSeries[5][i] = accelSerie[i] < 0; } }
public void ApplyTo(StockSerie stockSerie) { this.baseIndicator = stockSerie.GetIndicator(this.Name); }
public override void ApplyTo(StockSerie stockSerie) { FloatSerie hilbertSupport, hilbertResistance, secondarySupport, secondaryResistance; IStockIndicator hilbertIndicator = stockSerie.GetIndicator("HILBERT(" + (int)this.Parameters[0] + ")"); stockSerie.CalculateHilbertSR(hilbertIndicator, (int)this.Parameters[1], out hilbertSupport, out hilbertResistance, out secondarySupport, out secondaryResistance); this.Series[0] = hilbertSupport; this.Series[1] = hilbertResistance; this.Series[2] = secondarySupport; this.Series[3] = secondaryResistance; // Detecting events this.CreateEventSeries(stockSerie.Count); FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE); float lastSupportLevel = hilbertResistance[0]; float lastResistanceLevel = hilbertResistance[0]; bool waitingEndOfUpTrend = false; bool waitingEndOfDownTrend = false; bool supportDetected = false; bool resistanceDetected = false; for (int i = 10; i < stockSerie.Count; i++) { if (float.IsNaN(hilbertResistance[i])) { // Set UpSwing this.eventSeries[4][i] = closeSerie[i] > hilbertSupport[i]; // Set DownTrend this.eventSeries[7][i] = closeSerie[i] < hilbertSupport[i]; } else { // Set DownSwing this.eventSeries[5][i] = closeSerie[i] < hilbertResistance[i]; // Set UpTrend this.eventSeries[6][i] = closeSerie[i] > hilbertResistance[i]; } supportDetected = float.IsNaN(hilbertSupport[i - 1]) && !float.IsNaN(hilbertSupport[i]); this.eventSeries[0][i] = supportDetected; if (supportDetected) { if (waitingEndOfDownTrend && hilbertSupport[i] <= lastResistanceLevel) // End of down trend { this.eventSeries[3][i] = true; waitingEndOfDownTrend = false; // In any case we don't wait for the EOT as either it's reached or the trend changed. } else { if (hilbertSupport[i] >= lastResistanceLevel) // Pullback in up trend { this.eventSeries[2][i] = true; waitingEndOfUpTrend = true; waitingEndOfDownTrend = false; } else { waitingEndOfUpTrend = false; } } lastSupportLevel = hilbertSupport[i]; continue; } resistanceDetected = float.IsNaN(hilbertResistance[i - 1]) && !float.IsNaN(hilbertResistance[i]); this.eventSeries[1][i] = resistanceDetected; if (resistanceDetected) { if (waitingEndOfUpTrend && lastSupportLevel <= hilbertResistance[i]) // End of up trend { this.eventSeries[3][i] = true; waitingEndOfUpTrend = false; // In any case we don't wait for the EOT as either it's reached or the trend changed. } else { if (lastSupportLevel >= hilbertResistance[i]) // Pullback in down trend { this.eventSeries[2][i] = true; waitingEndOfUpTrend = false; waitingEndOfDownTrend = true; } else { waitingEndOfUpTrend = false; waitingEndOfUpTrend = false; } } lastResistanceLevel = hilbertResistance[i]; } } }