private double GetMoneyPit(double price) { //checks if the volume is less than one tick above // and also less than one tick below double nextlevelUp = price + TickSize; double nextLevelDown = price - TickSize; double testVolumeUp; double testVolumeDown; if (!VolumeDictionary.TryGetValue(nextlevelUp, out testVolumeUp) || !VolumeDictionary.TryGetValue(nextLevelDown, out testVolumeDown)) { return(double.MaxValue); // default value } // valid money pit try { if (VolumeDictionary[price] < testVolumeUp && VolumeDictionary[price] < testVolumeDown) { return(price); } } catch { // ok, whatever } // otherwise remove if it exists (level has cleared) if (MoneyPits.Contains(price)) { MoneyPits.Remove(price); } // no match, return default value return(double.MaxValue); }
protected override void OnBarUpdate() { if (CurrentBars[1] < RangePeriod) { shouldColorTrueRange = false; } else { shouldColorTrueRange = true; } // just makes on bar stuff easier to read barsUpdating = (BarsUpdating)BarsInProgress; switch (barsUpdating) { case BarsUpdating.Primary: { maxVolume = GetMaxVolume(trueRangeMax, trueRangeMin); // recacualte trading hours/session template data before accessing below if (Bars.IsFirstBarOfSession) // cached for performance optimizations { renet.RecalculateSession(Time[0]); } // primary bars are in session if (renet.IsRegularTradingHours(Time[0])) { // used to color the volume profile openPrice = greenRanger.DayOpen[0]; trueRangeMax = greenRanger.RangeMax[0]; trueRangeMin = greenRanger.RangeMin[0]; trueRangeLow = greenRanger.RangeLow[0]; trueRangeHigh = greenRanger.RangeHigh[0]; double tmpPit = GetMoneyPit(Close[0]); if (tmpPit < double.MaxValue) { MoneyPits.Add(tmpPit); } } break; } case BarsUpdating.Tick: { // add tick volume at price for volume AddToVolumeDictionary(Time[0], Close[0], Volume[0]); break; } case BarsUpdating.Daily: return; default: throw new Exception(string.Format("Unhandled BarsInProgress={0} ({1})", BarsInProgress, BarsArray[BarsInProgress].ToChartString())); } }