/// <summary> /// Bollinger Bands are plotted at standard deviation levels above and below a moving average. Since standard deviation is a measure of volatility, the bands are self-adjusting: widening during volatile markets and contracting during calmer periods. /// </summary> /// <returns></returns> public Bollinger Bollinger(Data.IDataSeries input, double numStdDev, int period) { if (cacheBollinger != null) { for (int idx = 0; idx < cacheBollinger.Length; idx++) { if (Math.Abs(cacheBollinger[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheBollinger[idx].Period == period && cacheBollinger[idx].EqualsInput(input)) { return(cacheBollinger[idx]); } } } lock (checkBollinger) { checkBollinger.NumStdDev = numStdDev; numStdDev = checkBollinger.NumStdDev; checkBollinger.Period = period; period = checkBollinger.Period; if (cacheBollinger != null) { for (int idx = 0; idx < cacheBollinger.Length; idx++) { if (Math.Abs(cacheBollinger[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheBollinger[idx].Period == period && cacheBollinger[idx].EqualsInput(input)) { return(cacheBollinger[idx]); } } } Bollinger indicator = new Bollinger(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.NumStdDev = numStdDev; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); Bollinger[] tmp = new Bollinger[cacheBollinger == null ? 1 : cacheBollinger.Length + 1]; if (cacheBollinger != null) { cacheBollinger.CopyTo(tmp, 0); } tmp[tmp.Length - 1] = indicator; cacheBollinger = 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); }
protected override void OnStartUp() { extdat = Bars.BarsType as rwt.IExtendedData; if (extdat == null) { throw new Exception("Only use this indicator on an Extended Data BarType, fool!"); } lastUpCount = 0; lastDnCount = 0; buytotals = new DataSeries(this); selltotals = new DataSeries(this); pones = new DataSeries(this); b1 = Bollinger(pones, 1.0, avgLen); b2 = Bollinger(pones, 2.0, avgLen); uplight = Color.FromArgb(50, uplight2); dnlight = Color.FromArgb(50, dnlight2); updark = Color.FromArgb(50, updark2); dndark = Color.FromArgb(50, dndark2); }
/// <summary> /// Bollinger Bands are plotted at standard deviation levels above and below a moving average. Since standard deviation is a measure of volatility, the bands are self-adjusting: widening during volatile markets and contracting during calmer periods. /// </summary> /// <returns></returns> public Bollinger Bollinger(Data.IDataSeries input, double numStdDev, int period) { if (cacheBollinger != null) for (int idx = 0; idx < cacheBollinger.Length; idx++) if (Math.Abs(cacheBollinger[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheBollinger[idx].Period == period && cacheBollinger[idx].EqualsInput(input)) return cacheBollinger[idx]; lock (checkBollinger) { checkBollinger.NumStdDev = numStdDev; numStdDev = checkBollinger.NumStdDev; checkBollinger.Period = period; period = checkBollinger.Period; if (cacheBollinger != null) for (int idx = 0; idx < cacheBollinger.Length; idx++) if (Math.Abs(cacheBollinger[idx].NumStdDev - numStdDev) <= double.Epsilon && cacheBollinger[idx].Period == period && cacheBollinger[idx].EqualsInput(input)) return cacheBollinger[idx]; Bollinger indicator = new Bollinger(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.NumStdDev = numStdDev; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); Bollinger[] tmp = new Bollinger[cacheBollinger == null ? 1 : cacheBollinger.Length + 1]; if (cacheBollinger != null) cacheBollinger.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheBollinger = tmp; return indicator; } }