private void Open(double price, double qty, OpenType ot, SecurityInfo si, TickData td, string tr)
        {
            PolicyResultEventArgs arg = new PolicyResultEventArgs();

            arg.PolicyName1 = this.policyName;
            arg.SecInfo     = si;
            arg.IsReal      = currentTick.IsReal;
            OpenPoint op = new OpenPoint();

            op.SecInfo             = si;
            op.OpenTime            = td.Time;
            op.OpenPrice           = price;
            op.OpenType            = ot;
            op.OpenQty             = qty;
            op.DealQty             = 0;
            op.Openop              = true;
            op.FirstTradePriceType = parameter.EnterOrderPriceType;
            op.CancelLimitTime     = parameter.EnterOrderWaitSecond;
            op.ReEnterPecentage    = parameter.ReEnterPercent;

            TradePoints tp = new TradePoints(op, 0);

            tp.Fee      = parameter.Fee;
            tp.TpRemark = tr;
            /////////////add//////////////////////
            tp.IsReal = arg.IsReal;
            this.tps.TryAdd(tp.TradeGuid, tp);
            arg.PairePoint   = tp;
            arg.PolicyObject = this;
            arg.Tickdata     = td;
            RaiseResult(arg);
        }
 void policy_PolicyResult_Arrival(object sender, PolicyResultEventArgs args)
 {
     if (args.PairePoint.Closed)
     {
         RaiseResult(sender, args);
     }
 }
 public void frmRaiseResult(object sender, PolicyResultEventArgs args)
 {
     if (frmPolicyResult_Arrival != null)
     {
         frmPolicyResult_Arrival(sender, args);
     }
 }
 //private void RaiseResult(RunningPolicy policy,PolicyResultEventArgs args)
 //{
 //    if (StockMonitor_ResultArrival != null)
 //    {
 //        StockMonitor_ResultArrival(policy,args);
 //    }
 //}
 void policy_PolicyResult_Arrival(object sender, PolicyResultEventArgs args)
 {
     if (StockMonitor_ResultArrival != null)
     {
         StockMonitor_ResultArrival((RunningPolicy)sender, args);
     }
 }
 void frm_BackTestResult_BackTestResult_Arrival(object sender, PolicyResultEventArgs args)
 {
     if (args.PairePoint.Closed)
     {
         Guid g = ((RunningPolicy)sender).PolicyGuid;
         ctradePoints[g].Add(args.PairePoint);
     }
 }
Beispiel #6
0
 void policy_PolicyResult_Arrival(object sender, PolicyResultEventArgs args)
 {
     if (!args.PairePoint.Closed)
     {
         ((RunningPolicy)sender).Notify(args.PairePoint.TradeGuid, OpenStatus.Opened, args.PairePoint.EnterPoint.OpenQty);
     }
     else
     {
         ((RunningPolicy)sender).Notify(args.PairePoint.TradeGuid, OpenStatus.Close, args.PairePoint.OutPoint.OpenQty, 0, "1234");
         ((RunningPolicy)sender).Notify(args.PairePoint.TradeGuid, OpenStatus.Closed, args.PairePoint.OutPoint.OpenQty, args.PairePoint.OutPoint.OpenPrice, "1234");
         RaiseResult(sender, args);
     }
 }
Beispiel #7
0
        private void Leave(double qty, double price, Guid tradeGuid)
        {
            foreach (var tp in tps)
            {
                if (tp.TradeGuid == tradeGuid)
                {
                    if (tp.OutPoint == null)
                    {
                        OpenPoint op = new OpenPoint();
                        op.SecInfo = currentTick.SecInfo;
                        //op.FirstTradePriceType = TradeSendOrderPriceType.ShiJiaWeiTuo_SH_SZ_WuDangJiChenShenChe;
                        op.FirstTradePriceType = parameter.CloseOrderPriceType;
                        op.CancelLimitTime     = parameter.CloseOrderWaitSecond;
                        op.ReTradePriceType    = parameter.ReCloseOrderPriceType;
                        op.ReEnterPecentage    = 1;
                        op.Openop = false;
                        //op.Remark = string.Format("MA2:{0},Close{1}", args.Bar.MA.MA2, args.Bar.Close);
                        tp.OutPoint = op;
                        openPoints.Add(op);
                        tp.HowToClose = CloseType.Normal;
                        tp.Status     = OpenStatus.Closed;
                    }
                    tp.OutPoint.OpenTime = currentTick.Time;
                    tp.OutPoint.OpenQty  = qty;
                    if (tp.EnterPoint.OpenType == OpenType.KaiDuo)
                    {
                        tp.OutPoint.OpenType  = OpenType.PingDuo;
                        tp.OutPoint.OpenPrice = price;
                    }
                    else
                    {
                        tp.OutPoint.OpenType  = OpenType.PingKong;
                        tp.OutPoint.OpenPrice = price;
                    }
                    PolicyResultEventArgs arg = new PolicyResultEventArgs();
                    arg.Tickdata    = currentTick;
                    arg.PolicyName1 = this.policyName;
                    arg.SecInfo     = this.SecInfo;
                    arg.IsReal      = tp.IsReal;
                    arg.PairePoint  = tp;
                    arg.OpenRmks    = tp.EnterPoint.Remark;

                    RaiseResult(arg);

                    close_complete = 1;
                    break;
                }
            }
        }
Beispiel #8
0
 private void Write(PolicyResultEventArgs args)
 {
     try
     {
         StreamWriter sw = new StreamWriter(string.Format("{0}\\result.txt", Application.StartupPath), true, Encoding.UTF8);
         if (!args.PairePoint.Closed)
         {
             sw.WriteLine(string.Format("{0},=\"{1}\",{2},{3},入场,{4},{5},{6}", args.PolicyName1, args.SecInfo.Code, args.SecInfo.Name, args.SecInfo.Market, Enum.GetName(typeof(OpenType), args.PairePoint.EnterPoint.OpenType), args.PairePoint.EnterPoint.OpenPrice, args.PairePoint.EnterPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss")));
         }
         else
         {
             sw.WriteLine(string.Format("{0},=\"{1}\",{2},{3},入场,{4},{5},{6},出场,{7},{8},{9}", args.PolicyName1, args.SecInfo.Code, args.SecInfo.Name, args.SecInfo.Market, Enum.GetName(typeof(OpenType), args.PairePoint.EnterPoint.OpenType), args.PairePoint.EnterPoint.OpenPrice, args.PairePoint.EnterPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss"), Enum.GetName(typeof(OpenType), args.PairePoint.OutPoint.OpenType), args.PairePoint.OutPoint.OpenPrice, args.PairePoint.OutPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss")));
         }
         sw.Close();
     }
     catch { }
 }
Beispiel #9
0
        //策略开仓
        void PolicyResultArraival(object sender, PolicyResultEventArgs args)
        {
            RunningPolicy policy = (RunningPolicy)sender;

            if (args.IsSim)
            {
                if (!args.PairePoint.Closed)
                {
                    policy.Notify(args.PairePoint.TradeGuid, OpenStatus.Opened);
                }
                else
                {
                    policy.Notify(args.PairePoint.TradeGuid, OpenStatus.Closed);
                }
            }
            else
            {
                ////////////add/////////////
                if (!args.IsReal)
                {
                    if (!args.PairePoint.Closed)
                    {
                        policy.Notify(args.PairePoint.TradeGuid, OpenStatus.Opened);
                    }
                    else
                    {
                        policy.Notify(args.PairePoint.TradeGuid, OpenStatus.Closed);
                    }
                }
                //////////add end////////////
                //if (args.IsReal)
                else
                {
                    Trader trader = traders[args.SecInfo.Market];
                    if (!args.PairePoint.Closed) //开仓
                    {
                        trader.policyTrade(args.SecInfo, args.PolicyName1, args.PairePoint, policy, PolicyTradeType.Open);
                    }
                    else //平仓
                    {
                        trader.policyTrade(args.SecInfo, args.PolicyName1, args.PairePoint, policy, PolicyTradeType.Close);
                    }
                }
            }
        }
        private void Open(double price, double qty, OpenType ot, SecurityInfo si, TickData td, double zhuidan, string _tr = "")
        {
            PolicyResultEventArgs arg = new PolicyResultEventArgs();

            arg.PolicyName1 = this.policyName;
            arg.SecInfo     = si;
            arg.IsReal      = currentTick.IsReal;
            OpenPoint op = new OpenPoint();

            op.SecInfo   = si;
            op.OpenTime  = td.Time;
            op.OpenPrice = price;
            op.OpenType  = ot;
            op.OpenQty   = qty;
            op.DealQty   = 0;
            op.Openop    = true;
            if (zhuidan < 0)
            {
                op.FirstTradePriceType = parameter.EnterOrderPriceType;
                op.CancelLimitTime     = parameter.EnterOrderWaitSecond;
                op.ReEnterPecentage    = zhuidan;
            }
            else
            {
                op.FirstTradePriceType = TradeSendOrderPriceType.Market;
                op.CancelLimitTime     = parameter.EnterOrderWaitSecond;
                op.ReEnterPecentage    = zhuidan;
            }
            openPoints.Add(op);
            string tr = _tr;

            if (tr == "")
            {
                tr = DateTime.Now.ToString("yyyyMMddHHmmss");
            }
            TradePoints tp = new TradePoints(op, 0);

            tp.TpRemark = tr;
            tp.Fee      = parameter.Fee;
            tp.IsReal   = arg.IsReal;
            this.tps.Add(tp);
            arg.PairePoint = tp;
            arg.Tickdata   = currentTick;
            RaiseResult(arg);
        }
        private void Open(double price, double qty, OpenType ot)
        {
            PolicyResultEventArgs arg = new PolicyResultEventArgs();

            arg.PolicyName1 = this.policyName;
            arg.SecInfo     = this.SecInfo;
            arg.IsReal      = currentTick.IsReal;
            OpenPoint op = new OpenPoint();

            op.SecInfo             = currentTick.SecInfo;
            op.OpenTime            = currentTick.Time;
            op.OpenPrice           = price;
            op.OpenType            = ot;
            op.OpenQty             = qty;
            op.DealQty             = 0;
            op.Openop              = true;
            op.FirstTradePriceType = parameter.EnterOrderPriceType;
            op.CancelLimitTime     = parameter.EnterOrderWaitSecond;
            op.ReEnterPecentage    = parameter.ReEnterPercent;
            //op.CancelLimitTime = 60;
            //op.ReEnterPecentage = 0.05;
            openPoints.Add(op);
            PTradePoints tp = new PTradePoints(op, 0);

            if (ot == OpenType.KaiDuo)
            {
                tp.Y      = (1 + parameter.ZhiYingBeiShu) * price;
                tp.ZhiSun = (1 - parameter.ZhiSunBiLi) * price;
            }
            if (ot == OpenType.KaiKong)
            {
                tp.Y      = (1 - parameter.ZhiYingBeiShu) * price;
                tp.ZhiSun = (1 + parameter.ZhiSunBiLi) * price;
            }
            tp.Fee = parameter.Fee;
            /////////////add//////////////////////
            tp.IsReal = arg.IsReal;
            this.tps.TryAdd(tp.TradeGuid, tp);
            arg.PairePoint   = tp;
            arg.PolicyObject = this;
            arg.Tickdata     = currentTick;
            RaiseResult(arg);
        }
Beispiel #12
0
        private void Open(double price, double qty, OpenType ot)
        {
            PolicyResultEventArgs arg = new PolicyResultEventArgs();

            arg.PolicyName1 = this.policyName;
            arg.SecInfo     = this.SecInfo;
            arg.IsReal      = currentTick.IsReal;
            OpenPoint op = new OpenPoint();

            op.SecInfo             = currentTick.SecInfo;
            op.OpenTime            = currentTick.Time;
            op.OpenPrice           = price;
            op.OpenType            = ot;
            op.OpenQty             = qty;
            op.DealQty             = 0;
            op.Openop              = true;
            op.FirstTradePriceType = parameter.EnterOrderPriceType;
            op.CancelLimitTime     = parameter.EnterOrderWaitSecond;
            op.ReEnterPecentage    = parameter.ReEnterPercent;
            //op.CancelLimitTime = 60;
            //op.ReEnterPecentage = 0.05;
            openPoints.Add(op);

            TradePoints tp = new TradePoints(op, 0);

            tp.Fee = parameter.Fee;
            /////////////add//////////////////////
            tp.IsReal = arg.IsReal;
            this.tps.Add(tp);
            arg.PairePoint = tp;
            arg.Tickdata   = currentTick;

            open_complete = 1;

            RaiseResult(arg);
        }
Beispiel #13
0
        void updateResult(PolicyResultEventArgs args)
        {
            if (this.grid_result.InvokeRequired)
            {
                //通过调用委托,来改变args的值
                this.Invoke(new updateResultDelegate(updateResult), new object[] { args });
            }
            else
            {
                //在grid_result中显示历史数据
                if (args.PairePoint.Closed)
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////
                    this.grid_resultX.Rows.Add();
                    int rowindex = grid_resultX.Rows.Count - 1;
                    grid_resultX.Rows[rowindex][1] = args.SecInfo.Code;
                    grid_resultX.Rows[rowindex][0] = args.PolicyName1;

                    grid_resultX.Rows[rowindex][6] = args.PairePoint.EnterPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                    grid_resultX.Rows[rowindex][7] = Enum.GetName(typeof(OpenType), args.PairePoint.EnterPoint.OpenType);
                    grid_resultX.Rows[rowindex][5] = args.PairePoint.EnterPoint.OpenPrice.ToString("0.000");

                    grid_resultX.Rows[rowindex][8]  = args.PairePoint.EnterPoint.OpenQty;
                    grid_resultX.Rows[rowindex][2]  = "出场";
                    grid_resultX.Rows[rowindex][9]  = args.PairePoint.OutPoint.OpenPrice.ToString("0.000");
                    grid_resultX.Rows[rowindex][10] = args.PairePoint.OutPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                    grid_resultX.Rows[rowindex][11] = Enum.GetName(typeof(OpenType), args.PairePoint.OutPoint.OpenType);

                    // grid_resultX.Rows[rowindex][12] = args.SecInfo.Market1;
                    double startprice, endprice, baseprice;
                    if (args.PairePoint.EnterPoint.OpenType == OpenType.KaiDuo)
                    {
                        startprice = args.PairePoint.EnterPoint.OpenPrice;
                        endprice   = args.PairePoint.OutPoint.OpenPrice;
                        baseprice  = startprice;
                    }
                    else if (args.PairePoint.EnterPoint.OpenType == OpenType.KaiKong)
                    {
                        endprice   = args.PairePoint.EnterPoint.OpenPrice;
                        startprice = args.PairePoint.OutPoint.OpenPrice;
                        baseprice  = endprice;
                    }
                    else if (args.PairePoint.EnterPoint.OpenType == OpenType.Buy)
                    {
                        startprice = args.PairePoint.EnterPoint.OpenPrice;
                        endprice   = args.PairePoint.OutPoint.OpenPrice;
                        baseprice  = startprice;
                    }
                    else
                    {
                        endprice   = args.PairePoint.EnterPoint.OpenPrice;
                        startprice = args.PairePoint.OutPoint.OpenPrice;
                        baseprice  = endprice;
                    }
                    double profit    = 0;
                    double profitamt = 0;
                    if (args.PairePoint.EnterPoint.OpenType == OpenType.KaiDuo || args.PairePoint.EnterPoint.OpenType == OpenType.KaiKong)
                    {
                        profitamt = Math.Round((1 / startprice - 1 / endprice) * args.PairePoint.EnterPoint.OpenQty * System.Convert.ToInt32(args.SecInfo.ContractVal) - (1 / startprice + 1 / endprice) * args.PairePoint.EnterPoint.OpenQty * args.PairePoint.Fee * System.Convert.ToInt32(args.SecInfo.ContractVal), 8, MidpointRounding.AwayFromZero);
                        profit    = Math.Round(profitamt / args.PairePoint.EnterPoint.OpenQty / baseprice * 100, 8, MidpointRounding.AwayFromZero);
                    }
                    else
                    {
                        profitamt = Math.Round((endprice - startprice) * args.PairePoint.EnterPoint.OpenQty * System.Convert.ToInt16(args.SecInfo.ContractVal) - 28, 8, MidpointRounding.AwayFromZero);
                        profit    = Math.Round(profitamt / args.PairePoint.EnterPoint.OpenQty / baseprice * 100, 8, MidpointRounding.AwayFromZero);
                    }

                    grid_resultX.Rows[rowindex][4]  = profitamt;
                    grid_resultX.Rows[rowindex][3]  = string.Format("{0}%", profit);// +"%";
                    grid_resultX.Rows[rowindex][12] = args.OpenRmks;
                    grid_resultX.Rows[rowindex][13] = args.CloseRmks;
                }
                else
                {
                    this.grid_resultX.Rows.Add();
                    int rowindex = grid_resultX.Rows.Count - 1;
                    grid_resultX.Rows[rowindex][1] = args.SecInfo.Code;
                    grid_resultX.Rows[rowindex][0] = args.PolicyName1;

                    grid_resultX.Rows[rowindex][6] = args.PairePoint.EnterPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                    grid_resultX.Rows[rowindex][7] = Enum.GetName(typeof(OpenType), args.PairePoint.EnterPoint.OpenType);
                    grid_resultX.Rows[rowindex][5] = args.PairePoint.EnterPoint.OpenPrice.ToString("0.000");

                    grid_resultX.Rows[rowindex][8]  = args.PairePoint.EnterPoint.OpenQty;
                    grid_resultX.Rows[rowindex][2]  = "入场";
                    grid_resultX.Rows[rowindex][12] = args.OpenRmks;
                    //grid_resultX.Rows[rowindex][9] = args.PairePoint.OutPoint.OpenPrice.ToString("0.00");
                    //grid_resultX.Rows[rowindex][10] = args.PairePoint.OutPoint.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                    //grid_resultX.Rows[rowindex][11] = Enum.GetName(typeof(OpenType), args.PairePoint.OutPoint.OpenType);
                }
                //grid_result.Rows[0].Cells[10].Value = "View";
                //grid_result.Rows[0].Tag = args.Tickdata;
            }
        }
 void rp_PolicyResult_Arrival(object sender, PolicyResultEventArgs args)
 //void stockMonitor_StockMonitor_ResultArrival(RunningPolicy policy,StockPolicies.PolicyResultEventArgs args)
 {
     args.IsSim = isSim;
     frmRaiseResult(sender, args);
 }