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);
        }
 /// <summary>
 /// Constructor with all data
 /// </summary>
 /// <param name="d"></param>
 public GenericStrategy(AnalysisData d)
 {
     this.data          = d;
     this.adviceInfo    = new TradePoints();
     this.last_position = 0;
     this.trailing_stop = -1;
 }
 /// <summary>
 /// constructor
 /// </summary>
 public GenericStrategy()
 {
     if (adviceInfo == null)
     {
         adviceInfo = new TradePoints();
     }
 }
        //todo https://github.com/aspnet/EntityFrameworkCore/issues/1100
        public async Task <TradePoint[]> GetNearestAsync(Location location, double radius)
        {
            var sql = $"SELECT * FROM {GetTableName(typeof(TradePoint))} " +
                      $"WHERE Location.STDistance({ToPoint(location)}) <= {radius.ToString(CultureInfo.InvariantCulture)}";

            return(await TradePoints.FromSql(sql).Include(tp => tp.Type).ToArrayAsync().ConfigureAwait(false));
        }
Beispiel #5
0
        override public TradePoints Execute(application.Data data, int[] parameters)
        {
            //application.Data vnidxData1 =  data.New("^VNINDEX");

            adviceInfo = new TradePoints();
            DataSeries minusDmi_14 = new Indicators.MinusDI(data.Bars, parameters[0], "");
            DataSeries plusDmi_14  = new Indicators.PlusDI(data.Bars, parameters[1], "");

            AppTypes.MarketTrend lastTrend    = AppTypes.MarketTrend.Unspecified;
            AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified;

            for (int idx = 0; idx < minusDmi_14.Count; idx++)
            {
                currentTrend = ((plusDmi_14[idx] > minusDmi_14[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward);
                if (lastTrend == AppTypes.MarketTrend.Downward && currentTrend == AppTypes.MarketTrend.Upward)
                {
                    BuyAtClose(idx);
                }
                if (lastTrend == AppTypes.MarketTrend.Upward && currentTrend == AppTypes.MarketTrend.Downward)
                {
                    SellAtClose(idx);
                }
                lastTrend = currentTrend;
            }
            return(adviceInfo);
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            var guid          = ReportTree.SelectedNode.Name;
            var bill          = TradePoints.FirstOrDefault(x => x.Guid.ToString() == guid);
            var spendingGroup = SpendingGroupComboBox.SelectedItem;
            var gr            = SpendingGroups.First(x => x.Name == spendingGroup);

            gr.Marks.Add(bill.GroupDesc);
            DoGood_Click(null, null);
            SaveSettingsBtn.Enabled = true;
        }
 /// <summary>
 /// Constructor with all data and parameter
 /// </summary>
 /// <param name="d"></param>
 /// <param name="p"></param>
 public GenericStrategy(AnalysisData d, Parameters p)
 {
     this.data       = d;
     this.parameters = p;
     if (adviceInfo == null)
     {
         this.adviceInfo = new TradePoints();
     }
     this.last_position = 0;
     this.trailing_stop = -1;
 }
 //virtual public TradePoints Execute(AnalysisData data, double[] paras)
 virtual public TradePoints Execute(AnalysisData data, double[] paras)
 {
     this.data  = data;
     parameters = new Parameters(paras);
     //??Bug fixed by Dung 11 Nov 2011
     if (adviceInfo == null)
     {
         adviceInfo = new TradePoints();
     }
     StrategyExecute();
     return(adviceInfo);
 }
        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);
        }
Beispiel #10
0
        private TreeNode CreateTreeNode(SpendingGroup spendingGroup)
        {
            var    node  = new TreeNode();
            double summ  = 0;
            var    count = 0;

            foreach (var mark in spendingGroup.Marks)
            {
                var tradePoint = TradePoints.FirstOrDefault(x => x.GroupDesc.Contains(mark));
                if (tradePoint != null)
                {
                    summ  += tradePoint.MainSumm;
                    count += tradePoint.Bills.Count();
                    node.Nodes.Add(tradePoint.Guid.ToString(), tradePoint.ToString());
                    TradePoints.Remove(tradePoint);
                }
            }
            node.Text = $"{spendingGroup.Name}. Сумма: {summ}. Счетов: {count}";
            return(node);
        }
Beispiel #11
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);
        }
 public override void Notify(Guid tradeGuid, OpenStatus status, double dealQty = 0, double dealPrice = 0, string weituobianhao = "", string pendWeituobianhao = "")
 {
     if (tps.ContainsKey(tradeGuid))
     {
         TradePoints t = tps[tradeGuid];
         if (t.TradeGuid == tradeGuid)
         {
             if (status == OpenStatus.Opened)
             {
                 if (t.EnterPoint.SecInfo.Key == SecInfo.Key)
                 {
                     firstDeal = true;
                 }
                 if (t.EnterPoint.SecInfo.Key == SecondSi.Key)
                 {
                     secondDeal = true;
                 }
                 t.Status = OpenStatus.Opened;
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受开仓通知,成交数量:{1}", this.policyName, dealQty)));
             }
             else if (status == OpenStatus.Open)
             {
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受开仓下单通知", this.policyName)));
             }
             else if (status == OpenStatus.OpenPending)
             {
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接收入场追单通知", this.policyName)));
             }
             else if (status == OpenStatus.Failed)
             {
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受失败通知", this.policyName)));
             }
             else if (status == OpenStatus.PartOpend)
             {
                 if (dealQty > (t.EnterPoint.DealQty - t.EnterPoint.PartDealQty))
                 {
                     decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                     t.EnterPoint.DealQty = dealQty + t.EnterPoint.PartDealQty;
                     RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分入场成交通知,成交数量:{1}", this.policyName, dealQty)));
                 }
             }
             else if (status == OpenStatus.OpenRest)
             {
                 if (t.EnterPoint.SecInfo.Key == SecInfo.Key)
                 {
                     firstDeal = true;
                 }
                 if (t.EnterPoint.SecInfo.Key == SecondSi.Key)
                 {
                     secondDeal = true;
                 }
                 if (t.EnterPoint.DealQty == 0)
                 {
                     t.Finished = true;
                 }
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受入场撤单通知", this.policyName)));
             }
             else if (status == OpenStatus.OpenCanceled)
             {
                 if (t.EnterPoint.SecInfo.Key == SecInfo.Key)
                 {
                     double openPrice = 0;
                     if (t.EnterPoint.OpenType == OpenType.Buy)
                     {
                         openPrice = currentTick.Ask;
                     }
                     else
                     {
                         openPrice = currentTick.Bid;
                     }
                     OpenArgs oa = new OpenArgs(
                         openPrice,
                         parameter.qty,
                         t.EnterPoint.OpenType,
                         SecInfo,
                         currentTick,
                         t.TpRemark);
                     OpenDelete od = new OpenDelete(OpenThread);
                     od.BeginInvoke(oa, null, null);
                 }
                 if (t.EnterPoint.SecInfo.Key == SecondSi.Key)
                 {
                     double openPrice = 0;
                     if (t.EnterPoint.OpenType == OpenType.Buy)
                     {
                         openPrice = SecondTick.Ask;
                     }
                     else
                     {
                         openPrice = SecondTick.Bid;
                     }
                     OpenArgs oa = new OpenArgs(
                         openPrice,
                         parameter.qty,
                         t.EnterPoint.OpenType,
                         SecondSi,
                         SecondTick,
                         t.TpRemark);
                     OpenDelete od = new OpenDelete(OpenThread);
                     od.BeginInvoke(oa, null, null);
                 }
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受入场撤单通知", this.policyName)));
             }
             else if (status == OpenStatus.CloseCanceled)
             {
                 RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受出场撤单通知", this.policyName)));
             }
         }
     }
 }