public override void OnBar(Bar bar) { if (VolatilityExitEnabled) { rangeSeries.Add(bar.DateTime, bar.High - bar.Low); } // check if there are least "length" bars if (series.Count >= EntryLength && rangeSMA.Count > 0) { double highestHigh = series.HighestHigh(EntryLength); double lowestLow = series.LowestLow(EntryLength); double volatilty = 0; if (VolatilityBarrierEnabled) { volatilty = rangeSMA.Last; } highestHighSeries.Add(bar.DateTime, highestHigh); lowestLowSeries.Add(bar.DateTime, lowestLow); double channelHigh = highestHigh + barrier - volatilty; double channelLow = lowestLow - barrier + volatilty; channelHighSeries.Add(bar.DateTime, channelHigh); channelLowSeries.Add(bar.DateTime, channelLow); if (!HasPosition) { if (channelHigh <= bar.Close) { OpenPosition(OrderSide.Buy); } else if (channelLow >= bar.Close) { OpenPosition(OrderSide.Sell); } } else { SetExit(); } } series.Add(bar); }
public void 设置指标() { 操盘 cp = new 操盘(); TickBuffer = new List <Tick>(); 操盘表 = new AtsList <操盘>(); 盘口表 = new AtsList <盘口>(); // _1mlist = GetBarSeries(EnumMarket.期货, DefaultFutureCode, 1, EnumBarType.分钟, 240, EnumRestoration.前复权); // _5mlist = GetBarSeries(EnumMarket.期货, "ru1609", 5, EnumBarType.分钟, 100, EnumRestoration.前复权); // _15mlist = GetBarSeries(EnumMarket.期货, "ru1609", 15, EnumBarType.分钟, 100, EnumRestoration.前复权); // _1dlist = GetBarSeries(EnumMarket.期货, "ru1605", 1, EnumBarType.日线, 100, EnumRestoration.前复权); if (_1mlist != null) { for (int i = 0; i < _1mlist.Count; i++) { cp.dt = _1mlist[i].BeginTime; cp.高低点差 = _1mlist.HighestHigh(0, i) - _1mlist.LowestLow(0, i); 操盘表.Add(cp); // Print("k:" + _1mlist[i].ToString()); } } 计算开盘前涨跌(); 多空.多量 = 0; 多空.开多数 = 0; 多空.空量 = 0; 多空.平多数 = 0; 多空.平空数 = 0; }
/* * 按照股指的时间要求,时间划分是这样的 * 9:15 * 9:45 * 10:15 * 10:45 * 11:15-11:30 13:00-13:15 两个15分钟被午休隔开了 * 13:45 * 14:15 * 14:45 * 15:15 交割日时只到15:00,已经到最后一天了,少15分钟也没什么 */ public override void OnBar(Bar bar) { //只处理15分钟的 if (900 == bar.Size) { if (bars == null) { bars = new BarSeries(); } bars.Add(bar); //在处理11:15-11:30 13:00-13:15这两个15分钟时会合并成一个 if (bars.Count == 2) // 2 * 15min = 30 min { // get OHLC values for 30min bar double open = bars[0].Open; double high = bars.HighestHigh(); double low = bars.LowestLow(); double close = bars[1].Close; long volume = bars[0].Volume + bars[1].Volume; // todo something Bar b = new Bar(bars[0].DateTime, open, high, low, close, volume, 900 * 2); bars30min.Add(b); Console.WriteLine(b); // reset 15min bar series bars = null; } } }
private void Update() { if (lbd.Count < 1) { return; } int lookBackDaysInt = (int)lbd.Last; longLiqPoint = SMA.Value(bars86400, bars86400.Count - 1, lookBackDaysInt, BarData.Close); if (double.IsNaN(longLiqPoint)) { return; } nEnd = bars86400.Count - 1; nBegin = nEnd - lookBackDays + 1; buyPoint = bars86400.HighestHigh(nBegin, nEnd); sellPoint = bars86400.LowestLow(nBegin, nEnd); shortLiqPoint = SMA.Value(bars86400, bars86400.Count - 1, lookBackDaysInt, BarData.Close); upBand = BBU.Value(bars86400, bars86400.Count - 1, lookBackDaysInt, bolBandTrig, BarData.Close); dnBand = BBL.Value(bars86400, bars86400.Count - 1, lookBackDaysInt, bolBandTrig, BarData.Close); }
public override void OnBar(Bar bar) { if (bar.Size == 86400) { return; } if (lbd.Count < 1 || dbbu.Count < 1) { return; } int lookBackDaysInt = (int)lbd.Last; int nEnd = bars86400.Count - 1; int nBegin = nEnd - lookBackDays + 1; double buyPoint = bars86400.HighestHigh(nBegin, nEnd); double sellPoint = bars86400.LowestLow(nBegin, nEnd); double longLiqPoint = dbbu.SMA.Last; double shortLiqPoint = dbbu.SMA.Last; double upBand = dbbu.Last; double dnBand = dbbu.BBL.Last; upBandSeries.Add(bar.DateTime, upBand); dnBandSeries.Add(bar.DateTime, dnBand); buyPointSeries.Add(bar.DateTime, buyPoint); sellPointSeries.Add(bar.DateTime, sellPoint); // 下面代码可能有问题 if (HasPosition) { if (Position.Amount > 0 && Bar.Close < longLiqPoint) { ClosePosition("T|"); } if (Position.Amount < 0 && Bar.Close > shortLiqPoint) { ClosePosition("T|"); } } else { if (Bar.Close > upBand)// && Bar.Close >= buyPoint { Buy(Qty, "O|"); } if (Bar.Close < dnBand)// && Bar.Close <= sellPoint { Sell(Qty, "O|"); } } }
public override void OnBar(Bar bar) { if (bar.Size == 86400) { base.ChangeTradingDay(); return; } if (lbd.Count < 1 || dbbu.Count < 1) { return; } int lookBackDaysInt = (int)lbd.Last; int nEnd = bars86400.Count - 1; int nBegin = nEnd - lookBackDays + 1; double buyPoint = bars86400.HighestHigh(nBegin, nEnd); double sellPoint = bars86400.LowestLow(nBegin, nEnd); double longLiqPoint = dbbu.SMA.Last; double shortLiqPoint = dbbu.SMA.Last; double upBand = dbbu.Last; double dnBand = dbbu.BBL.Last; upBandSeries.Add(bar.DateTime, upBand); dnBandSeries.Add(bar.DateTime, dnBand); buyPointSeries.Add(bar.DateTime, buyPoint); sellPointSeries.Add(bar.DateTime, sellPoint); do { if (GetCurrentQty() > 0) { if (bar.Close < longLiqPoint) { TargetPosition = 0; TextParameter.Text = "低于多头流动点"; } } else if (GetCurrentQty() < 0) { if (bar.Close > shortLiqPoint) { TargetPosition = 0; TextParameter.Text = "高于空头流动点"; } } else { if (bar.Close > upBand) { TargetPosition = 1; TextParameter.Text = "突破上轨开仓"; } else if (bar.Close < dnBand) { TargetPosition = -1; TextParameter.Text = "突破下轨开仓"; } } } while (false); base.OnBar(bar); }