鼎元C++期货量化/程序化教程【tick与bar模式下ask价与bid价相关的说明】
  
- UID
- 2
- 积分
- 2948020
- 威望
- 1424047 布
- 龙e币
- 1523973 刀
- 在线时间
- 13794 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-5-1

|
鼎元C++期货量化/程序化教程【tick与bar模式下ask价与bid价相关的说明】
鼎元C++期货量化/程序化教程【tick与bar模式下ask价与bid价相关的说明】
第一部分、开仓委托下单语句:
void test::OrderInsert(string acc, string inst, char bs, char oc, int vol, double price, string forfok, string ref2)
解读:
(1)、元素:
t->sName = sName; //策略名
t->InvestorID = acc; //期货账户
t->InstrumentID = inst; //期货合约
t->BuySell = bs; //0时为buy ,1时为sell
t->OpenClose = oc; // 0时为open 或1时为close
t->Volume = vol; //数量,即下单数量
t->LimitPrice = price; //下单价格
t->FakFok = forfok;//两种成交指令,(fok,立即全部成交否则自动撤销指令,fill or kill),(fak,立即成交剩余指令自动撤销指令,fill and kill)
t->Ref1 = sName;//策略名
t->Ref2 = ref2;//保留参数
(2)、在tick行情中交易委托语句:- OrderInsert(期货账号, 交易合约, '买', '开盘价', 数量, 价格, "保留空白", "保留空白")
复制代码 时我们要这样写:- OrderInsert(it->first, sInst, '0', '0', sl, t->AskPrice1 + hd * mapInstrument[sInst].PriceTick, "", "");
复制代码 第二部分、平仓语句:
(1)、多单平仓- closesell1(it->first, sInst, sl, mapMd[sInst].BidPrice1 - hd * mapInstrument[sInst].PriceTick);//卖出平仓,优先平昨
复制代码- closesell2(it->first, sInst, sl, mapMd[sInst].BidPrice1 - hd * mapInstrument[sInst].PriceTick); //卖出平仓,优先平今
复制代码 (2)、空单平仓- closebuy1(it->first, sInst, sl, mapMd[sInst].AskPrice1 + hd * mapInstrument[sInst].PriceTick);//买入平仓语句.优先平昨
复制代码- closebuy2(it->first, sInst, sl, mapMd[sInst].AskPrice1 + hd * mapInstrument[sInst].PriceTick);//买入平仓语句,优先平今
复制代码 第三部分:关于买与卖的价格说明:
(1)、tick行情中使用“t->AskPrice1”这样的价格形式。除了askprice1价格外还有这样的一些价格元素:
//最新价
TThostFtdcPriceType LastPrice;
///上次结算价
TThostFtdcPriceType PreSettlementPrice;
///昨收盘
TThostFtdcPriceType PreClosePrice;
///今开盘
TThostFtdcPriceType OpenPrice;
///最高价
TThostFtdcPriceType HighestPrice;
///最低价
TThostFtdcPriceType LowestPrice;
///今收盘
TThostFtdcPriceType ClosePrice;
///涨停板价
TThostFtdcPriceType UpperLimitPrice;
///跌停板价
TThostFtdcPriceType LowerLimitPrice;
///申买价一
TThostFtdcPriceType BidPrice1;
///申卖价一
TThostFtdcPriceType AskPrice1;
///申买价二
TThostFtdcPriceType BidPrice2;
///申卖价二
TThostFtdcPriceType AskPrice2;
///申买价三
TThostFtdcPriceType BidPrice3;
///申卖价三
TThostFtdcPriceType AskPrice3;
///申买价四
TThostFtdcPriceType BidPrice4;
///申卖价四
TThostFtdcPriceType AskPrice4;
///申买价五
TThostFtdcPriceType BidPrice5;
///申卖价五
TThostFtdcPriceType AskPrice5;
///当日均价
TThostFtdcPriceType AveragePrice;
平时我们在下单为了能尽可能的成交,我们多使用第一档的这两个:BidPrice1,AskPrice1;使用办法看下图。
(2)、Bar行情中使用“mapMd[sInst].BidPrice1”这样的价格形式。里面的价格元素与(1)中没有区别。

上面是一个范例。
卖时价格是按从高到低排列。
买时也是按从最高到低排列。
正常情况下,卖方想高价卖,买方想低价买。双方以最新价中界,卖方在上,买方在下形成对峙。
如果为了保证成交,卖方按最高的买价卖,买方想按卖方最低价买,这时就要付出的价格点位就是滑点。一般是买1与卖1.
在上方演示中,卖方想立刻成交,就要挂[best bid]价卖出——立马成交;买方想立刻成交,就要挂[best ask]价买 入--马立成交。 |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|
|
|
|
|
|
  
- UID
- 2
- 积分
- 2948020
- 威望
- 1424047 布
- 龙e币
- 1523973 刀
- 在线时间
- 13794 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-5-1

|
TICK模式下:
1、买 入开仓语句:- OrderInsert(it->first, sInst, '0', '0', sl, t->LastPrice + hd * mapInstrument[sInst].PriceTick, "", ""); //开仓买入语句
复制代码 2、卖出开仓语句:- OrderInsert(it->first, sInst, '1', '0', sl, t->LastPrice - hd * mapInstrument[sInst].PriceTick, "", "");
复制代码 3、多单平仓语句:
//优先平昨- closesell1(it->first, sInst, sl, t->LastPrice - hd * mapInstrument[sInst].PriceTick);
复制代码 //优先平今- closesell2(it->first, sInst, sl, t->LastPrice - hd * mapInstrument[sInst].PriceTick);
复制代码 3、空单平仓语句:
//优先平昨- closebuy1(it->first, sInst, sl, t->LastPrice + hd * mapInstrument[sInst].PriceTick);
复制代码 //优先平昨今- closebuy2(it->first, sInst, sl, t->LastPrice + hd * mapInstrument[sInst].PriceTick);
复制代码 |
|
|
|
|
|
|
  
- UID
- 2
- 积分
- 2948020
- 威望
- 1424047 布
- 龙e币
- 1523973 刀
- 在线时间
- 13794 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-5-1

|
bar格式下:
1、买 入开仓语句:- OrderInsert(it->first, sInst, '0', '0', sl, mapMd[sInst].BidPrice1 + hd * mapInstrument[sInst].PriceTick, "", "");//买入开仓语句
复制代码 2、卖出开仓语句:- OrderInsert(it->first, sInst, '1', '0', sl, mapMd[sInst].AskPrice1 - hd * mapInstrument[sInst].PriceTick, "", "");//卖出开仓语句
复制代码 3、多单平仓语句:
//优先平昨- closesell1(it->first, sInst, sl, mapMd[sInst].AskPrice1 - hd * mapInstrument[sInst].PriceTick);//卖出平仓,优先平昨仓
复制代码 //优先平今- closesell2(it->first, sInst, sl, t->LastPrice - hd * mapInstrument[sInst].PriceTick);
复制代码 3、空单平仓语句:
//优先平昨- closebuy1(it->first, sInst, sl, mapMd[sInst].BidPrice1 + hd * mapInstrument[sInst].PriceTick); //买入平仓,优先平昨仓
复制代码 //优先平昨今- closebuy2(it->first, sInst, sl, mapMd[sInst].BidPrice1 + hd * mapInstrument[sInst].PriceTick); //买入平仓,优先平今仓
复制代码 |
|
|
|
|
|
|