Example #1
0
 //定义一个带有参数的方法
 public void DataBarArrival(LiveBarArrivalEventArgs args)
 {
     if (Data_Bar_Arrival != null)
     {
         Data_Bar_Arrival(this, args);
     }
 }
        void ldpa_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int intevals = ((LiveBars)sender).Inteval;

            if (intevals == 60)
            {
                _riscPoints.InsertBar(args.Bar);
            }
        }
Example #3
0
        void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int inteval = ((LiveBars)sender).Inteval;

            #region 策略bar逻辑
            if (inteval == parameter.BarInteval)
            {
                while (LiveBars.Count > parameter.BarCount)
                {
                    LiveBars.RemoveAt(0);
                }
                if (LiveBars.Count == parameter.BarCount)
                {
                    CalArgs();
                }
                LiveBars.Add(args.Bar.Close);
            }
            #endregion
        }
 void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
 {
     int inteval = ((LiveBars)sender).Inteval;
 }
Example #5
0
        void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int inteval = ((LiveBars)sender).Inteval;

            if (inteval == parameter.BarInteval)
            {
                //DieBar bar = new DieBar();
                //bar.Open = args.Bar.Open;
                //bar.High = args.Bar.High;
                //bar.Low = args.Bar.Low;
                //bar.Close = args.Bar.Close;
                //bar.Finish = args.Bar.Finish;

                if (args.Bar.Close == 0)
                {
                    return;
                }
                if (args.Bar.Finish)
                {
                    // fast enter bar
                    list_efast.RemoveAt(parameter.EFast - 1);
                    list_efast.Insert(0, args.Bar.Close);
                    double sum = 0;
                    for (int i = 0; i < list_efast.Count; i++)
                    {
                        sum += list_efast[i];
                    }
                    last_maefast = sum / parameter.EFast;

                    // fast exit bar
                    list_xfast.RemoveAt(parameter.XFast - 1);
                    list_xfast.Insert(0, args.Bar.Close);
                    sum = 0;
                    for (int i = 0; i < list_xfast.Count; i++)
                    {
                        sum += list_xfast[i];
                    }
                    last_maxfast = sum / parameter.XFast;

                    // slow enter bar
                    list_eslow.RemoveAt(parameter.ESlow - 1);
                    list_eslow.Insert(0, args.Bar.Close);
                    sum = 0;
                    for (int i = 0; i < list_eslow.Count; i++)
                    {
                        sum += list_eslow[i];
                    }
                    last_maeslow = sum / parameter.ESlow;

                    // slow exit bar
                    list_xslow.RemoveAt(parameter.XSlow - 1);
                    list_xslow.Insert(0, args.Bar.Close);
                    sum = 0;
                    for (int i = 0; i < list_xslow.Count; i++)
                    {
                        sum += list_xslow[i];
                    }
                    last_maxslow = sum / parameter.XSlow;

                    if (!has_pull_data)
                    {
                        if (args.Bar.High >= init_high)
                        {
                            last_high = args.Bar.High;
                        }
                        else
                        {
                            last_high = init_high;
                        }
                        if (args.Bar.Low <= init_low)
                        {
                            last_low = args.Bar.Low;
                        }
                        else
                        {
                            last_low = init_low;
                        }
                        has_pull_data = true;
                    }
                    else
                    {
                        last_high = args.Bar.High;
                        last_low  = args.Bar.Low;
                    }
                }
            }
        }
        void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int inteval = ((LiveBars)sender).Inteval;

            #region 策略bar逻辑
            if (inteval == parameter.BarInteval)
            {
                LiveBars["close"].Add(args.Bar.Close);
                LiveBars["high"].Add(args.Bar.High);
                LiveBars["low"].Add(args.Bar.Low);
                if (LiveBars["close"].Count > parameter.BarCount)
                {
                    MarkDp        mdp      = new MarkDp();
                    List <Signal> listsig  = mdp.GetDpData(LiveBars);
                    bool          NewPoint = false;
                    for (int i = 0; i < listsig.Count; i++)
                    {
                        if (listsig[i].Info == "low" && !ListLowSig.ContainsKey(listsig[i].Index))
                        {
                            ListLowSig.Add(listsig[i].Index, listsig[i].Price);
                            NewPoint = true;
                        }
                        if (listsig[i].Info == "high" && !ListHighSig.ContainsKey(listsig[i].Index))
                        {
                            ListHighSig.Add(listsig[i].Index, listsig[i].Price);
                            NewPoint = true;
                        }
                    }
                    if (NewPoint)
                    {
                        slope       = CalSlope(ListSig.Keys.ToList(), ListSig.Values.ToList());
                        AvgDistance = 0;
                        foreach (var item in ListSig)
                        {
                            AvgDistance += GetDistance(slope, item.Key, item.Value);
                        }
                        AvgDistance = AvgDistance / ListSig.Count;
                    }
                    double Cha = args.Bar.Close - ((slope * (LiveBars["close"].Count - 1 - avgX) / stdX) * stdY + avgY);

                    if (Cha > 0)
                    {
                        if (KongHands > 0)
                        {
                            foreach (var item in tps)
                            {
                                PTradePoints tp = item.Value;
                                if (!tp.Finished)
                                {
                                    if (tp.EnterPoint.OpenType == OpenType.KaiKong)
                                    {
                                        double qty = tp.EnterPoint.DealQty - (tp.OutPoint != null ? tp.OutPoint.OpenQty : 0);
                                        if (qty > 0)
                                        {
                                            Leave(currentTick.Ask, qty, tp.TradeGuid);
                                        }
                                    }
                                }
                            }
                        }

                        if (slope < 0 && Math.Abs(Cha) > AvgDistance)
                        {
                            if (DuoHands + FrozenDuoHands == 0)
                            {
                                FrozenDuoHands += (Decimal)parameter.qty;
                                Open(currentTick.Bid, parameter.qty, OpenType.KaiDuo);
                            }
                        }
                    }
                    else
                    {
                        if (DuoHands > 0)
                        {
                            foreach (var item in tps)
                            {
                                PTradePoints tp = item.Value;
                                if (!tp.Finished)
                                {
                                    if (tp.EnterPoint.OpenType == OpenType.KaiDuo)
                                    {
                                        double qty = tp.EnterPoint.DealQty - (tp.OutPoint != null ? tp.OutPoint.OpenQty : 0);
                                        if (qty > 0)
                                        {
                                            Leave(currentTick.Bid, qty, tp.TradeGuid);
                                        }
                                    }
                                }
                            }
                        }
                        if (slope > 0 && Math.Abs(Cha) > AvgDistance)
                        {
                            if (KongHands + FrozenKongHands == 0)
                            {
                                FrozenKongHands += (Decimal)parameter.qty;
                                Open(currentTick.Ask, parameter.qty, OpenType.KaiKong);
                            }
                        }
                    }
                }
            }
            #endregion
        }
        void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int inteval = ((LiveBars)sender).Inteval;

            #region 策略bar逻辑
            if (inteval == parameter.BarInteval)
            {
                MarkPrice mp = new MarkPrice(args.Bar.BarOpenTime, args.Bar.Close);
                if (MarkHigh == null)
                {
                    MarkHigh = new MarkPrice(args.Bar.BarOpenTime, args.Bar.High);
                    MarkLow  = new MarkPrice(args.Bar.BarOpenTime, args.Bar.Low);
                }
                else
                {
                    if (LiveBars.Count == parameter.BarCount)
                    {
                        if (TuPoHigh)
                        {
                            double low = 100000;
                            for (int i = 0; i < LiveBars.Count; i++)
                            {
                                if (LiveBars[i].Price < low)
                                {
                                    low     = LiveBars[i].Price;
                                    MarkLow = LiveBars[i];
                                }
                            }
                        }
                        else if (TuPoLow)
                        {
                            double high = 0;
                            for (int i = 0; i < LiveBars.Count; i++)
                            {
                                if (LiveBars[i].Price > high)
                                {
                                    high     = LiveBars[i].Price;
                                    MarkHigh = LiveBars[i];
                                }
                            }
                        }
                    }
                    if (LiveBars.Count >= 2 * parameter.BarCount && !CanOpen)
                    {
                        if ((MarkHigh.Price - MarkLow.Price) < currentTick.Last * 0.015 && (MarkHigh.Price - MarkLow.Price) > currentTick.Last * 0.005)
                        {
                            CanOpen = true;
                            if (!parameter.DebugModel)
                            {
                                Open(MarkHigh.Price * 0.999, parameter.qty, OpenType.KaiKong);
                                Open(MarkLow.Price * 1.001, parameter.qty, OpenType.KaiDuo);
                            }
                        }
                    }
                    if (args.Bar.Close > MarkHigh.Price)
                    {
                        UpTuPoCounts += 1;
                    }
                    else
                    {
                        UpTuPoCounts = 0;
                    }
                    if (args.Bar.Close < MarkLow.Price)
                    {
                        DownTuPoCounts += 1;
                    }
                    else
                    {
                        DownTuPoCounts = 0;
                    }
                    if (args.Bar.Close > MarkHigh.Price * 1.002)
                    {
                        MarkHigh     = mp;
                        UpTuPoCounts = 0;
                        CanOpen      = false;
                        TuPoHigh     = true;
                        TuPoLow      = false;
                        LiveBars.Clear();
                        foreach (var item in OpenWeiTuos)
                        {
                            NeedCheDanWeiTuos.Add(item.Key, item.Key);
                        }
                    }
                    if (args.Bar.Close < MarkLow.Price * 0.998)
                    {
                        MarkLow        = mp;
                        DownTuPoCounts = 0;
                        CanOpen        = false;
                        TuPoHigh       = false;
                        TuPoLow        = true;
                        LiveBars.Clear();
                        foreach (var item in OpenWeiTuos)
                        {
                            NeedCheDanWeiTuos.Add(item.Key, item.Key);
                        }
                    }
                    LiveBars.Add(mp);
                }
            }
            #endregion
        }
Example #8
0
        void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int inteval = ((LiveBars)sender).Inteval;

            #region 策略bar逻辑
            if (inteval == parameter.BarInteval)
            {
                if (args.Bar.Finish)
                {
                    if (!InitKaiCangBar)
                    {
                        if (LiveBars.Count < parameter.BarCount)
                        {
                            DieBar bar = new DieBar();
                            bar.High = args.Bar.High;
                            bar.Low  = args.Bar.Low;
                            if (bar.High > SighHighPrice)
                            {
                                SighHighPrice = bar.High;
                            }
                            if (bar.Low < SighLowPrice)
                            {
                                SighLowPrice = bar.Low;
                            }
                            LiveBars.Add(bar);
                        }
                        else
                        {
                            InitKaiCangBar  = true;
                            StartTrade      = true;
                            RegionHighPrice = SighHighPrice;
                            RegionLowPrice  = SighLowPrice;
                        }
                    }
                    else
                    {
                        if (args.Bar.High > RegionHighPrice)
                        {
                            RegionHighPrice = args.Bar.High;
                        }
                        if (args.Bar.Low < RegionLowPrice)
                        {
                            RegionLowPrice = args.Bar.Low;
                        }
                        if (args.Bar.Close < SighHighPrice && K1)
                        {
                            K1         = false;
                            arriveHigh = false;
                        }
                        if (args.Bar.Close > SighLowPrice && K2)
                        {
                            K2        = false;
                            arriveLow = false;
                        }
                        if (arriveHigh && !K1)
                        {
                            if (args.Bar.Close < args.Bar.Open)
                            {
                                if (args.Bar.Close < args.Bar.PreBar.Low)
                                {
                                    K1 = true;
                                }
                            }
                        }
                        if (arriveLow && !K2)
                        {
                            if (args.Bar.Close > args.Bar.Open)
                            {
                                if (args.Bar.Close > args.Bar.PreBar.High)
                                {
                                    K2 = true;
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }
        void liveDataProcessor_OnLiveBarArrival(object sender, LiveBarArrivalEventArgs args)
        {
            int inteval = ((LiveBars)sender).Inteval;

            if (inteval == parameter.BarInteval)
            {
                if (LiveBarsIn.Count == 0)
                {
                    LoadHistoryBars();
                }
                else
                {
                    DieBar bar = new DieBar();
                    bar.Open   = args.Bar.Open;
                    bar.High   = args.Bar.High;
                    bar.Low    = args.Bar.Low;
                    bar.Close  = args.Bar.Close;
                    bar.Finish = args.Bar.Finish;

                    if (bar.Close == 0)
                    {
                        return;
                    }

                    if (LiveBarsIn.Count < parameter.BarCountIn)
                    {
                        if (bar.Finish)
                        {
                            LiveBarsIn.Add(bar);
                        }
                    }
                    else
                    {
                        if (!init)
                        {
                            foreach (DieBar tempBar in LiveBarsIn)
                            {
                                if (tempBar.High > signInHighPrice)
                                {
                                    signInHighPrice = tempBar.High;
                                }
                                if (tempBar.Low < signInLowPrice)
                                {
                                    signInLowPrice = tempBar.Low;
                                }
                            }
                            Ratio = ((signInHighPrice - signInLowPrice) / ((signInHighPrice + signInLowPrice) * 0.5)) * 100;
                            init  = true;
                        }
                        if (bar.Finish)
                        {
                            DieBar removeBar = LiveBarsIn[0];
                            LiveBarsIn.RemoveAt(0);
                            LiveBarsIn.Add(bar);

                            if (bar.High > signInHighPrice)
                            {
                                signInHighPrice = bar.High;
                            }
                            else
                            {
                                if (removeBar.High == signInHighPrice)
                                {
                                    signInHighPrice = 0;
                                    foreach (DieBar tempBar in LiveBarsIn)
                                    {
                                        if (tempBar.High > signInHighPrice)
                                        {
                                            signInHighPrice = tempBar.High;
                                        }
                                    }
                                }
                            }

                            if (bar.Low < signInLowPrice)
                            {
                                signInLowPrice = bar.Low;
                            }
                            else
                            {
                                if (removeBar.Low == signInLowPrice)
                                {
                                    signInLowPrice = 1000000;
                                    foreach (DieBar tempBar in LiveBarsIn)
                                    {
                                        if (tempBar.Low < signInLowPrice)
                                        {
                                            signInLowPrice = tempBar.Low;
                                        }
                                    }
                                }
                            }
                            Ratio = ((signInHighPrice - signInLowPrice) / ((signInHighPrice + signInLowPrice) * 0.5)) * 100;
                        }
                    }
                }
            }
        }