- 策略广场
- 盘口炒单法
盘口炒单法
Author:
量价时空, Date: 2020-07-13 09:51:49
Tags:
C++
void main() {
Sleep(10000);
Log(exchange.GetAccount());
auto id=0;
while (1) {
exchange.SetContractType(Symbol);
auto trades = exchange.GetTrades();
if (exchange.IO("status") == 1 && trades.size() > 0) {
exchange.SetContractType(Symbol);
auto trades = exchange.GetTrades();
auto ticker = exchange.GetTicker();
auto position = exchange.GetPosition();
auto orders = exchange.GetOrders();
if (position.size() > 0 && !(orders.size() > 0)) {
exchange.SetContractType(Symbol);
auto depth = exchange.GetDepth();
int i=0;
auto m1=depth.Asks[0].Amount;
auto b1=depth.Bids[0].Amount;
auto mz1=m1;
auto bz1=b1;
for(i=1; i < 10; i++)
{
mz1=mz1 + depth.Asks[i].Amount;
bz1=bz1 + depth.Bids[i].Amount;
}
if (!position[0].Type) {
if ( mz1 > bz1 || position[0].Profit < -30 || position[0].Profit > 50) {
exchange.SetContractType(Symbol);
exchange.SetDirection("closebuy_today");
exchange.Sell(ticker.Buy - 1000, 1);
}
}
if (position[0].Type) {
if ( mz1 > bz1 || position[0].Profit < -30 || position[0].Profit > 50) {
exchange.SetContractType(Symbol);
exchange.SetDirection("closesell_today");
exchange.Buy(ticker.Sell + 1000, 1);
}
}
} else if (!(orders.size() > 0) ){
int i=0;
auto q=0;
auto e=0;
exchange.SetContractType(Symbol);
auto trades = exchange.GetTrades();
for(i=1;i<20;i++ ) {
if (trades[trades.size() - i].Type == 0){
q=q+trades[trades.size() - i].Amount;
}else {
e=e+trades[trades.size() - i].Amount;
}
}
auto depth = exchange.GetDepth();
auto m1=depth.Asks[0].Amount;
auto b1=depth.Bids[0].Amount;
auto mz1=m1;
auto bz1=b1;
for(i=1; i < 20; i++)
{
mz1=mz1 + depth.Asks[i].Amount;
bz1=bz1 + depth.Bids[i].Amount;
}
if (e > q && mz1 > bz1 && m1 > b1 ) {
exchange.SetContractType(Symbol);
exchange.SetDirection("sell");
id=exchange.Sell(ticker.Sell - 1000, 1);
}else if (q > e && mz1 < bz1 && m1 < b1 ) {
exchange.SetContractType(Symbol);
exchange.SetDirection("buy");
id=exchange.Buy(ticker.Buy + 1000, 1);
}
}
/*else if (orders.size() > 0){
exchange.SetContractType(Symbol);
auto depth = exchange.GetDepth();
auto q=0;
auto e=0;
int i=0;
auto m1=depth.Asks[0].Amount;
auto b1=depth.Bids[0].Amount;
//auto m2=depth.Asks[1].Amount;
// auto b2=depth.Bids[1].Amount;
auto mz1=m1;
auto bz1=b1;
for(i=1; i < 20; i++)
{
mz1=mz1 + depth.Asks[i].Amount;
bz1=bz1 + depth.Bids[i].Amount;
}
auto trades = exchange.GetTrades();
for(i=1;i<20;i++ ) {
if (trades[trades.size() - i].Type == 0){
q=q+trades[trades.size() - i].Amount;
}else {
e=e+trades[trades.size() - i].Amount;
}
}
auto orders = exchange.GetOrders();
if(orders[0].Type == 0 && e > q && mz1 > bz1 ) {
exchange.CancelOrder(id);
} else if(orders[0].Type == 1 && e < q && mz1 < bz1){
exchange.CancelOrder(id);
}
}*/
} else {
LogStatus(_D(), "未连接CTP !");
Sleep(10000);
}
}
}
相关内容
更多内容