/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBars[0] < 10 || CurrentBars[1] < 10) { return; } if (BarsInProgress == 0) { zigZagObject1.UpdateOnBar(this, CurrentBar, High, Low, Input[0], Input); zigZagObject2.UpdateOnBar(this, CurrentBar, High, Low, Input[0], Input); _dayVolume.Add(VOL()[0]); DayVolumeResize(_dayVolume); MaxVolumeOfDay = GetMaxVolumeOfDay(_dayVolume); if (zigZagObject1.LastBarPosition == 0) { return; } double crossZigZagsVolume = VOL()[CurrentBar - zigZagObject1.LastBarPosition + 1]; if (zigZagObject1.LastPricePosition == zigZagObject2.HighZigZagPrice || zigZagObject1.LastPricePosition == zigZagObject2.LowZigZagPrice) { if (zigZagObject2.IsChangePeriod) { zigZagObject2.IsChangePeriod = false; Print("--------------"); Print(Time[0]); Print("CurrentBar -> " + CurrentBars[0]); Print("zigZagObject1 LastPosition-> " + zigZagObject1.LastPricePosition); Print("zigZagObject2 HighZigZagPrice-> " + zigZagObject2.HighZigZagPrice); Print("zigZagObject1 LastPosition-> " + zigZagObject1.LastPricePosition); Print("zigZagObject2 LowZigZagPrice-> " + zigZagObject2.LowZigZagPrice); Print("zigZagObject1.LastBarPosition -> " + zigZagObject1.LastBarPosition); Print("MaxVolumeOfDay -> " + MaxVolumeOfDay); Print("crossZigZagsVolume -> " + crossZigZagsVolume); if (MaxVolumeOfDay < crossZigZagsVolume) { isCanEnterOrder = true; } } } } else if (BarsInProgress == 1) { if (isCanEnterOrder) { double price = Opens[1][0]; if (Position.MarketPosition == MarketPosition.Flat) { if (zigZagObject2.IsTrendDown == -1) { _isBuyOrder = false; startOrderPrice = Opens[1][0]; EnterShort("ShortOrder"); } else if (zigZagObject2.IsTrendDown == 1) { _isBuyOrder = true; startOrderPrice = Opens[1][0]; EnterLong("LongOrder"); } } else { if (_isBuyOrder) { if ((price < startOrderPrice - _stopLoss) || (price > startOrderPrice + _takeProfit)) { ExitLong("LongOrder"); isCanEnterOrder = false; } } else { if ((price > startOrderPrice + _stopLoss) || (price < startOrderPrice - _takeProfit)) { ExitShort("ShortOrder"); isCanEnterOrder = false; } } } } } }