private bool AlreadyOpenedBreakDownPosition(double value) { //if(OpenedOrders.Count > 0 && OpenedOrders.Last().CurrentValue > OpenedOrders.Last().StopLoss) // return true; foreach (DelayedPositionInfo info in DelayedPositions) { if (info.Mark == "RW" && Math.Abs(info.Price - value) / value < 0.005) { return(true); } } foreach (OpenPositionInfo info in OpenedOrders) { if (info.Mark != "RW") { continue; } SRValue res = SRIndicator.FindSupportByTime(info.CandlestickTime); if (res != null && info.Type == OrderType.Buy && SRIndicator.BelongsSameSupportLevel(res)) { return(true); } } return(false); }
protected bool AlreadyOpenedPingPongPosition() { if (OpenedOrders.Count > 0 && OpenedOrders.Last().CurrentValue > OpenedOrders.Last().StopLoss) { return(true); } CombinedStrategyDataItem last = (CombinedStrategyDataItem)StrategyData.Last(); foreach (OpenPositionInfo info in OpenedOrders) { if (info.Mark != "PP") { continue; } SRValue res = SRIndicator2.FindSupportByTime(info.CandlestickTime); if (res != null && info.Type == OrderType.Buy && (SRIndicator2.BelongsSameSupportLevel(res) || last.Index - info.DataItemIndex < 5)) { return(true); } } return(false); }
protected virtual void ProcessTickerCore() { if (Ticker.CandleStickData.Count < StrategyStartItemsCount) /// need back data for simulation { return; } if (Ticker.OrderBook.IsDirty || Ticker.OrderBook.Asks.Count == 0) { return; } CombinedStrategyDataItem item = (CombinedStrategyDataItem)StrategyData.Last(); if (!string.IsNullOrEmpty(item.Mark)) // processed { return; } if (SRIndicator.Resistance.Count == 0 || SRIndicator.Support.Count == 0 || SRIndicator2.Resistance.Count == 0 || SRIndicator2.Support.Count == 0) { return; } SRValue lr = SRIndicator.Resistance.Last(); SRValue ls = SRIndicator.Support.Last(); //double spread = lr.Value - ls.Value; double lastAsk = Ticker.OrderBook.Asks[0].Value; double spreadFromResistance = lastAsk - SRIndicator2.Resistance.Last().Value; //(lastAsk - lr.Value); double spreadFromSupport = (ls.Value - lastAsk); //item.BreakPercent = spreadFromResistance / item.SRSpread * 100; item.SpreadBaseResistance = spreadFromResistance; item.SRSpread = (SRIndicator2.Resistance.Last().Value - SRIndicator.Support.Last().Value) / SRIndicator2.Support.Last().Value * 100; if (BreakUpSettings.Enable && spreadFromResistance > BreakUpSettings.MinBreakValue && spreadFromResistance < BreakUpSettings.MaxBreakValue) // to high { if (!AlreadyOpenedBreakUpPosition()) { OpenBreakUpPosition(lastAsk); } //EnableTrailingForPingPong(); } else if (BreakDownSettings.Enable && spreadFromSupport > BreakDownSettings.MinSupportBreakValue) // to low { double probableBottom = GetProbableBottom(lastAsk); double openValue = 0; if (probableBottom != 0) { openValue = probableBottom + (ls.Value - probableBottom) * 0.1; // 10% addition } if (openValue == 0 || openValue >= lastAsk) { probableBottom = 0; openValue = lastAsk; } if (!AlreadyOpenedBreakDownPosition(openValue)) { OpenBreakDownPosition(openValue, ls.Value, probableBottom != 0); } } else { SRValue lr2 = SRIndicator2.Resistance.Last(); SRValue ls2 = SRIndicator2.Support.Last(); double spread2 = lr2.Value - ls2.Value; double pc = (lastAsk - ls2.Value) / spread2; if (PingPongSettings.Enable && item.SRSpread > PingPongSettings.MinimalPriceRangeInPc && pc > 0 && pc < 0.1 && ls.Length > PingPongSettings.SupportLevelLength) // minimal spread { if (!AlreadyOpenedPingPongPosition()) { OpenPingPongPosition(lastAsk, lr2.Value, ls2.Value); } } } ProcessDelayedPositions(); ProcessLongPositions(); item.Earned = Earned; return; }