/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 2) { return; } if (High[0] >= High[1]) { var maxidx = CurrentBar; var count = 1; var idx = 1; var cursell = Low[0]; while (count < levels) { if (idx >= maxidx) { break; } if (Low[idx] < cursell) { ++count; cursell = Low[idx]; } else if (High[idx] > High[0]) { cursell = -1; break; } ++idx; } if (cursell > sellLevel) { sellLevel = cursell; } } if (Low[0] <= Low[1]) { var maxidx = CurrentBar; var count = 1; var idx = 1; var curbuy = High[0]; while (count < levels) { if (idx >= maxidx) { break; } if (High[idx] > curbuy) { ++count; curbuy = High[idx]; } else if (Low[idx] < Low[0]) { curbuy = Double.MaxValue; break; } ++idx; } if (curbuy < buyLevel) { buyLevel = curbuy; } } //BuyLine.Set(Close[0]); if (sellLevel >= 0) { SellLine.Set(sellLevel); } if (buyLevel < Double.MaxValue) { BuyLine.Set(buyLevel); } if (Close[0] < sellLevel) { sellLevel = -1; } if (Close[0] > buyLevel) { buyLevel = Double.MaxValue; } }
/// <summary> /// Initialize buy and sell /// </summary> public void Clear() { BuyLine.Clear(); SellLine.Clear(); }