protected override void OnStartUp() { DYNRSI = RSI(Input, RSIPeriod, 1); DYNPrice = SMA(DYNRSI, PricePeriod); DYNSignal = SMA(DYNRSI, SignalPeriod); // added the following Aug 19 2014 zondor emaEMAhls = EMA(EMA(hls, EMAPeriod1), EMAPeriod2); emaEMAsms = (EMA(EMA(sms, EMAPeriod1), EMAPeriod2)); emaSMI = EMA(smis, SMIEMAPeriod); MaxHI = MAX(High, range); MinLO = MIN(Low, range); }
/// <summary> /// The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time. /// </summary> /// <returns></returns> public SMA SMA(Data.IDataSeries input, int period) { if (cacheSMA != null) { for (int idx = 0; idx < cacheSMA.Length; idx++) { if (cacheSMA[idx].Period == period && cacheSMA[idx].EqualsInput(input)) { return(cacheSMA[idx]); } } } lock (checkSMA) { checkSMA.Period = period; period = checkSMA.Period; if (cacheSMA != null) { for (int idx = 0; idx < cacheSMA.Length; idx++) { if (cacheSMA[idx].Period == period && cacheSMA[idx].EqualsInput(input)) { return(cacheSMA[idx]); } } } SMA indicator = new SMA(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); SMA[] tmp = new SMA[cacheSMA == null ? 1 : cacheSMA.Length + 1]; if (cacheSMA != null) { cacheSMA.CopyTo(tmp, 0); } tmp[tmp.Length - 1] = indicator; cacheSMA = tmp; return(indicator); } }
protected override void MyInitialize() { _boll = Bollinger(BollingerStdDev, BollingerPeriod); Add(_boll); _smaFast = SMA(SMAFastPeriod); _smaFast.Plots[0].Pen.Color = Color.Blue; Add(_smaFast); _smaSlow = SMA(SMASlowPeriod); _smaSlow.Plots[0].Pen.Color = Color.Purple; Add(_smaSlow); InitialStoploss = 100; ProfitTicks = 300; SetProfitTarget(CalculationMode.Ticks, 300); // SetStopLoss(CalculationMode.Ticks, 200); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar <= period) return; if (_atr == null) _atr = ATR(period); if (_ema == null) _ema = SMA(_atr, period); if (_atr == null & _ema == null) return; ATRPlotHigh.Set(High[0] + _atr[0] * multiplier); ATRPlotLow.Set(Low[0] - _atr[0] * multiplier); EMAPlotHigh.Set(High[0] + _ema[0] * multiplier); EMAPlotLow.Set(Low[0] - _ema[0] * multiplier); }
/// <summary> /// Calculates the indicator value(s) at the current index. /// </summary> protected override void OnStartUp() { DYNRSI = RSI(Input, RSIPeriod, 1); DYNPrice = SMA(DYNRSI, PricePeriod); DYNSignal = SMA(DYNRSI, SignalPeriod); DYNAverage = SMA(DYNRSI, BandPeriod); SDBB = StdDev(DYNRSI, BandPeriod); Plots[0].Pen.Color = main; Plots[1].Pen.Color = signal; Plots[2].Pen.Color = bbAverage; Plots[3].Pen.Color = bbUpper; Plots[4].Pen.Color = bbLower; Plots[0].Pen.Width = plot0Width; Plots[0].PlotStyle = plot0Style; Plots[0].Pen.DashStyle = dash0Style; Plots[1].Pen.Width = plot1Width; Plots[1].PlotStyle = plot1Style; Plots[1].Pen.DashStyle = dash1Style; Plots[2].Pen.Width = plot2Width; Plots[2].PlotStyle = plot2Style; Plots[2].Pen.DashStyle = dash2Style; Plots[3].Pen.Width = plot3Width; Plots[3].PlotStyle = plot3Style; Plots[3].Pen.DashStyle = dash3Style; Plots[4].Pen.Width = plot3Width; Plots[4].PlotStyle = plot3Style; Plots[4].Pen.DashStyle = dash3Style; Lines[0].Pen.Color = baselineColor; Lines[1].Pen.Color = upperlineColor; Lines[2].Pen.Color = lowerlineColor; Lines[0].Pen.Width = baselineWidth; Lines[0].Pen.DashStyle = baselineStyle; Lines[1].Value = valueUpperLine; Lines[1].Pen.Width = upperlineWidth; Lines[1].Pen.DashStyle = upperlineStyle; Lines[2].Value = valueLowerLine; Lines[2].Pen.Width = lowerlineWidth; Lines[2].Pen.DashStyle = lowerlineStyle; }
protected override void LookForEntry() { _sma = SMA(BarsArray[1], SMAFastPeriod); if (!EntryOk()) return; if (_latestSubmittedOrder != null) return; double priorHigh = _indiPrior.PriorHigh[0]; double priorLow = _indiPrior.PriorLow[0]; if (priorLow == 0 || priorHigh == 0) return; // go long? if (Close[0] > priorLow && Close[0] <= priorLow + (TickSize * _maxTicksToTarget) && Falling(Close) && Rising(_sma)) { _latestSubmittedOrder = EnterLongLimit(0, true, DefaultQuantity, priorLow, "long"); _tradeState = TradeState.InitialStop; if (_exitType == ExitType.TrailingATR) { _lossLevel = priorLow - EMA(ATR(MMAtrPeriod), MMAtrEMAPeriod)[0] * MMAtrMultiplier; SetStopLoss("long", CalculationMode.Price, _lossLevel, true); } else { _lossLevel = priorLow - TickSize * _mmInitialSL; } _orderDates.Add(Time[0].ToShortDateString()); } // go short? if (Close[0] < priorHigh && Close[0] >= priorHigh - (TickSize * _maxTicksToTarget) && Rising(Close) && Falling(_sma)) { _latestSubmittedOrder = EnterShortLimit(0, true, DefaultQuantity, priorHigh, "short"); _tradeState = TradeState.InitialStop; if (_exitType == ExitType.TrailingATR) { _lossLevel = priorHigh + EMA(ATR(MMAtrPeriod), MMAtrEMAPeriod)[0] * MMAtrMultiplier; SetStopLoss("short", CalculationMode.Price, _lossLevel, true); } else { _lossLevel = priorHigh + TickSize*_mmInitialSL; } _orderDates.Add(Time[0].ToShortDateString()); } }
/// <summary> /// The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time. /// </summary> /// <returns></returns> public SMA SMA(Data.IDataSeries input, int period) { if (cacheSMA != null) for (int idx = 0; idx < cacheSMA.Length; idx++) if (cacheSMA[idx].Period == period && cacheSMA[idx].EqualsInput(input)) return cacheSMA[idx]; lock (checkSMA) { checkSMA.Period = period; period = checkSMA.Period; if (cacheSMA != null) for (int idx = 0; idx < cacheSMA.Length; idx++) if (cacheSMA[idx].Period == period && cacheSMA[idx].EqualsInput(input)) return cacheSMA[idx]; SMA indicator = new SMA(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); SMA[] tmp = new SMA[cacheSMA == null ? 1 : cacheSMA.Length + 1]; if (cacheSMA != null) cacheSMA.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheSMA = tmp; return indicator; } }
protected override void OnStartUp() { sma1 = SMA(Inputs[0], Period); sma2 = SMA(sma1, Period); sma3 = SMA(sma2, Period); }