I'm starting on a new course for me: Dictionaries.
I'm getting an error that, "the given key was not present in the dictionary". I have verified through Print() that the valleysRising.Key does have value, but for some reason around the 25th bar I get the error. Here is my code.
#region Variables B1StochDir2 stochDirection; B1HourGlass hourGlass; B1PVStoch stochPV; protected Dictionary<int, ValleysRising> valleys; #endregion protected override void Initialize() { Overlay = true; BarsRequired = 15; } protected override void OnStartUp() { stochDirection = B1StochDir2(3, 5, 2); hourGlass = B1HourGlass(14, 14, 7, 15, 3); stochPV = B1PVStoch(3, 5, 2); } protected override void OnBarUpdate() { if(CurrentBar < BarsRequired) return; var valleysRising = new ValleysRising(){Key = 1}; valleys = new Dictionary<int, ValleysRising>(); for (int x = 0; x <= 3; x++){ if(stochPV.StochValley[x] != -1){ valleysRising.BarNumber = CurrentBar; valleysRising.Value = stochPV.StochValley[x]; valleys.Add(valleysRising.Key, valleysRising); break; } } Print(CurrentBar); Print(valleysRising.Key); Print(""); ValleysRising valleysCheck = valleys[1]; } #region Properties #endregion } public class ValleysRising { public int Key {get; set;} public int BarNumber {get; set;} public double Value {get; set;} public ValleysRising(){ } }
Comment