Beispiel #1
0
        public SmaStrategy(CandleSeries series, SimpleMovingAverage longSma, SimpleMovingAverage shortSma)
        {
            _series = series;

            LongSma  = longSma;
            ShortSma = shortSma;

            _longSmaPeriod  = this.Param("LongSmaPeriod", longSma.Length);
            _shortSmaPeriod = this.Param("ShortSmaPeriod", shortSma.Length);
        }
Beispiel #2
0
		public SmaStrategy(CandleSeries series, SimpleMovingAverage longSma, SimpleMovingAverage shortSma)
		{
			_series = series;

			LongSma = longSma;
			ShortSma = shortSma;

			_longSmaPeriod = this.Param("LongSmaPeriod", longSma.Length);
			_shortSmaPeriod = this.Param("ShortSmaPeriod", shortSma.Length);
		}
		/// <summary>
		/// Initialize <see cref="BaseAnalyticsStrategy"/>.
		/// </summary>
		protected BaseAnalyticsStrategy()
		{
			_from = this.Param<DateTime>("From");
			_to = this.Param("To", DateTime.MaxValue);
		}
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DailyHighestVolumeStrategy"/>.
 /// </summary>
 public DailyHighestVolumeStrategy()
 {
     _timeFrame = this.Param("TimeFrame", TimeSpan.FromMinutes(5));
 }
 /// <summary>
 /// Initialize <see cref="BaseAnalyticsStrategy"/>.
 /// </summary>
 protected BaseAnalyticsStrategy()
 {
     _from = this.Param <DateTime>("From");
     _to   = this.Param("To", DateTime.MaxValue);
 }
Beispiel #6
0
        public void ResumeStrategy(StrategyContext oContext)
        {
            this.m_sStrategyId = oContext.Uid;
            //"合约一;合约二;是否标准合约;开仓条件;价差门限;开仓数量;平仓条件一;平仓价差一;平仓条件二;平仓价差二;启用策略执行下单;优先开仓合约;每天开仓次数小于;下单账号;开仓方向";
            if (oContext.Params.Count >= 15)
            {
                StrategyParam _param = oContext.Params[2];
                if (0 == _param.ParamName.CompareTo("是否标准合约") && 0 == _param.ParamValue.CompareTo("1"))
                {
                    this.rdoStd.Checked       = true;
                    this.cmbStdArbitrage.Text = oContext.Params[0].ParamValue;
                }
                else
                {
                    this.rdoCustom.Checked = true;
                    this.txtCode1.Text     = oContext.Params[0].ParamValue;
                    this.txtCode2.Text     = oContext.Params[1].ParamValue;
                }

                this.cmbCondtion.Text = oContext.Params[3].ParamValue;
                this.txtPriceDiv.Text = oContext.Params[4].ParamValue;
                this.txtOpenNum.Text  = oContext.Params[5].ParamValue;

                if (0 == oContext.Params[6].ParamName.CompareTo("平仓条件一") && string.Empty != oContext.Params[6].ParamValue)
                {
                    this.chkCloseCon1.Checked = true;
                    this.cmbPriceDivCon1.Text = oContext.Params[6].ParamValue;
                    this.txtPriceDivCon1.Text = oContext.Params[7].ParamValue;
                }

                if (0 == oContext.Params[8].ParamName.CompareTo("平仓条件二") && string.Empty != oContext.Params[8].ParamValue)
                {
                    this.chkCloseCon2.Checked = true;
                    this.cmbPriceDivCon2.Text = oContext.Params[8].ParamValue;
                    this.txtPriceDivCon2.Text = oContext.Params[9].ParamValue;
                }

                if (0 == oContext.Params[10].ParamName.CompareTo("平仓条件二") && 0 == oContext.Params[10].ParamValue.CompareTo("1"))
                {
                    this.chkStrategyOrder.Checked = true;
                    int iFirstOpen = Int32.Parse(oContext.Params[11].ParamValue);
                    if (0 == iFirstOpen)
                    {
                        this.cmbFirstOpenContract.Text = "合约一";
                    }
                    else if (1 == iFirstOpen)
                    {
                        this.cmbFirstOpenContract.Text = "合约二";
                    }
                    else if (2 == iFirstOpen)
                    {
                        this.cmbFirstOpenContract.Text = "同时开仓";
                    }
                }

                this.txtOpenLimit.Text = oContext.Params[12].ParamValue;

                this.cmbAccount.Text = oContext.Params[13].ParamValue;

                int iDir = Int32.Parse(oContext.Params[14].ParamValue);
                if (0 == iDir)
                {
                    this.cmbDir.SelectedIndex = 0;
                }
                else
                {
                    this.cmbDir.SelectedIndex = 1;
                }
            }



            //resume open postion
            for (int i = 0; i < oContext.Postions.Count; i++)
            {
                ContractPostion oPos  = oContext.Postions[i];
                ListViewItem    oItem = new ListViewItem(new string[] {
                    "",
                    oPos.ContractCode,
                    (0 == oPos.Direction ? "买入" : "卖出"),
                    oPos.Postion.ToString(),
                    oPos.OpenPrice.ToString(),
                    oPos.OpenTime
                });
                this.lstPostion.Items.Add(oItem);
            }
        }
 /// <summary>
 /// Initialize <see cref="BaseAnalyticsStrategy"/>.
 /// </summary>
 protected BaseAnalyticsStrategy()
 {
     _from = this.Param <DateTime>(nameof(From));
     _to   = this.Param(nameof(To), DateTime.MaxValue);
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="PriceVolumeDistributionStrategy"/>.
		/// </summary>
		public PriceVolumeDistributionStrategy()
		{
			_timeFrame = this.Param("TimeFrame", TimeSpan.FromMinutes(5));
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceVolumeDistributionStrategy"/>.
 /// </summary>
 public PriceVolumeDistributionStrategy()
 {
     _timeFrame = this.Param("TimeFrame", TimeSpan.FromMinutes(5));
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="DailyHighestVolumeStrategy"/>.
		/// </summary>
		public DailyHighestVolumeStrategy()
		{
			_timeFrame = this.Param("TimeFrame", TimeSpan.FromMinutes(5));
		}
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int nt = comboBox1.SelectedIndex;

            if (nt == -1)
            {
                return;
            }

            string name = comboBox1.Items[nt].ToString();

            dataGridView1.Columns.Clear();
            //检查此策略是否存在上次未运行完毕
            FormStrategyResume frmResume = new FormStrategyResume();

            if (frmResume.HasResumeStrategy(name))
            {
                frmResume.delegate_GetAllStrategyName = this.delegate_GetAllStrategyName;
                if (DialogResult.Yes == frmResume.ShowDialog())
                {
                    StrategyContext oStrategy = null;
                    if (frmResume.GetResumeStrategyCase(frmResume.ResumeStrategyId, ref oStrategy))
                    {
                        m_sStrategyId = oStrategy.Uid;
                        dataGridView1.Columns.Add("col0", "参数名");
                        dataGridView1.Columns.Add("col1", "参数值");
                        dataGridView1.Columns.Add("col2", "说明");
                        dataGridView1.Columns[0].ReadOnly = true;
                        dataGridView1.Columns[2].ReadOnly = true;
                        for (int i = 0; i < oStrategy.Params.Count; i++)
                        {
                            StrategyParam    _param = oStrategy.Params[i];
                            DataGridViewRow  oRow = new DataGridViewRow();
                            DataGridViewCell oCell0, oCell1, oCell2;
                            if (0 == _param.ParamName.CompareTo("涨停类型"))
                            {
                                oCell0       = new DataGridViewTextBoxCell();
                                oCell0.Value = _param.ParamName;
                                DataGridViewCellStyle oCell0Style = new DataGridViewCellStyle();
                                oCell0Style.BackColor = SystemColors.Control;
                                DataGridViewComboBoxCell oCellCmb = new DataGridViewComboBoxCell();


                                oCellCmb.Items.Add("0");
                                oCellCmb.Items.Add("1");
                                oCellCmb.Value = "0";

                                oCell1 = oCellCmb;

                                oCell2       = new DataGridViewTextBoxCell();
                                oCell2.Value = "0,普通涨停; 1,一字涨停";
                            }
                            else if (0 == _param.ParamName.CompareTo("退出信号为指令价或收盘价"))
                            {
                                oCell0       = new DataGridViewTextBoxCell();
                                oCell0.Value = _param.ParamName;
                                DataGridViewComboBoxCell oCellCmb = new DataGridViewComboBoxCell();
                                oCellCmb.Items.Add("0");
                                oCellCmb.Items.Add("1");
                                oCellCmb.Value = "0";
                                oCell1         = oCellCmb;

                                oCell2       = new DataGridViewTextBoxCell();
                                oCell2.Value = "0,指令价; 1,收盘价";
                            }

                            else
                            {
                                oCell0       = new DataGridViewTextBoxCell();
                                oCell0.Value = _param.ParamName;
                                oCell1       = new DataGridViewTextBoxCell();
                                oCell1.Value = _param.ParamValue;
                                oCell2       = new DataGridViewTextBoxCell();
                                oCell2.Value = "";
                            }


                            oRow.Cells.Add(oCell0);
                            oRow.Cells.Add(oCell1);
                            oRow.Cells.Add(oCell2);

                            dataGridView1.Rows.Add(oRow);
                        }


                        //resume open postion
                        for (int i = 0; i < oStrategy.Postions.Count; i++)
                        {
                            ContractPostion oPos  = oStrategy.Postions[i];
                            ListViewItem    oItem = new ListViewItem(new string[] { oPos.OpenTime,
                                                                                    oPos.ContractCode,
                                                                                    oPos.ContractName, (0 == oPos.Direction ? "买入" : "卖出"),
                                                                                    oPos.HighPrice.ToString(),
                                                                                    oPos.OpenPrice.ToString(),
                                                                                    oPos.Postion.ToString(),
                                                                                    (oPos.Postion * oPos.OpenPrice).ToString() });
                            this.lstTradeRec.Items.Add(oItem);
                        }
                    }
                }
                else
                {
                    m_sStrategyId = Guid.NewGuid().ToString();
                    OnInitStrategyParams(name);
                }
            }
            else
            {
                m_sStrategyId = Guid.NewGuid().ToString();
                OnInitStrategyParams(name);
            }
        }
Beispiel #12
0
 public StrategyBase(StrategyParam param)
 {
 }
		/// <summary>
		/// Initialize <see cref="BaseAnalyticsStrategy"/>.
		/// </summary>
		protected BaseAnalyticsStrategy()
		{
			_from = this.Param<DateTime>(nameof(From));
			_to = this.Param(nameof(To), DateTime.MaxValue);
		}