|
来个用在文华上给炒单预备的程序。只管开仓就可以,平仓按照我写的这个动作自动做了,大家供参考。我没怎么用这个炒过,只是个参考,大家自己看着拿去用。
这是多头平仓部分的,空头部分大家可以根据这个自己想想后补完修改。我是炒单挣不到钱,研究着玩。
//抄单20秒价格没过+2且>0,则挂+1,30秒不成交并且+0则平推,35秒则对价止损。20秒后仍然<0则挂-1止损,50秒则全部对价出。
VAR_TICKDATA data;
VAR CodeName; // 交易合约
VAR StopBit; // 止羸止损点数
VAR OPEN; // 开盘价
VAR StopBitPrice;
VAR PRICE;
GLOBAL_VAR SK_PRICE, BK_PRICE, SK_TIME, BK_TIME, BK_DEAL, SK_DEAL;
GLOBAL_VAR SP_PRICE, BP_PRICE, SP_TIME, BP_TIME;
GLOBAL_VAR BPID;
GLOBAL_VAR SPID;
GLOBAL_VAR orderstate;
GLOBAL_VAR SPFlag; // 判断是否发出卖平委托
VOID MAIN()
{
CodeName = "p1505";
StopBitPrice = 2 * MinPrice(CodeName); // 止羸止损2个点
data = Def_TickData(CodeName, 1, 1);
IF( T_BuyPosition(CodeName)==0 && T_SellPosition(CodeName)==0)
{
BK_TIME=0;
SK_TIME=0;
RETURN; //无持仓,返回
}
PRICE = data[0].TickPrice;
IF(T_OrderState(SPID) == 1) //IF(T_IsNoOrder()) 这里初始值为0 平仓结束后也可以通过判断委托状态来初始化 如果是判断是否有挂单 可能委托发出后,
// 委托回报没有回来,这时候挂单依然不存在
{
orderstate=0;
SPFlag = 0;
}
IF (T_BuyPosition(CodeName)>0)//如果多头持仓大于0
{
IF(BK_TIME==0)
{
BK_TIME=CurrentTime();
}// 记录成交时间
SPDeal(); // 执行卖平程序
MessageOut("orderstate="+orderstate);
}
IF (T_SellPosition(CodeName)>0) //如果空头持仓大于0
{
SPDeal(); //执行买平程序
}
}
VOID SPDeal()
{
IF( T_BuyPosition(CodeName) !=0 )
{
SPID = 0;
}
// 成交后20秒内价格大于持仓价格2点则挂对价单出,orderstate=1
IF( PRICE > (T_BuyAvgPrice(CodeName)+StopBitPrice) && orderstate == 0)
{
IF((CurrentTime()-BK_TIME) < 20 )
{
SP_PRICE = data[0].Bid1;
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("快速波动止赢:卖平"+T_BuyRemainPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyRemainPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 1;
SPFlag = 1;
}
RETURN;
}
}
//抄单20秒价格没过+2且>0,则挂+1,orderstate=2
IF( PRICE <=T_BuyAvgPrice(CodeName)+StopBitPrice && PRICE>=T_BuyAvgPrice(CodeName) && orderstate==0)
{
IF((CurrentTime()-BK_TIME) < 20 )
{
SP_PRICE = T_BuyAvgPrice(CodeName)+1*MinPrice(CodeName);
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("止赢1点:卖平"+T_BuyRemainPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyRemainPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 2;
SPFlag = 1;
}
RETURN;
}
}
//30秒不成交并且+0则挂平推单,orderstate=3
IF( PRICE ==T_BuyAvgPrice(CodeName) && orderstate==2)
{
IF((CurrentTime()-BK_TIME) >=30 )
{
T_DeleteOrder(SPID);//撤掉止盈1点的单子,挂平推单
SP_PRICE = T_BuyAvgPrice(CodeName) ;
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("不盈利:平推"+T_BuyRemainPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyRemainPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 3;
SPFlag = 1;
}
RETURN;
}
}
//35秒时候平推单没成交,对价止损,orderstate=4
IF(orderstate==3 && CurrentTime()-BK_TIME>=35)
{
T_DeleteOrder(SPID);//撤掉平推单,对价止损
SP_PRICE = data[0].Bid1 ;
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("不盈利:对价止损"+T_BuyRemainPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyRemainPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 4;
SPFlag = 1;
}
RETURN;
}
// 成交后20秒后价格小于持仓价格-2以内,则挂-1出,orderstate=5
IF( PRICE < T_BuyAvgPrice(CodeName) && PRICE >= (T_BuyAvgPrice(CodeName)-2*MinPrice(CodeName) && orderstate == 0))
{
IF((CurrentTime()-BK_TIME) >= 20 )
{
SP_PRICE =T_BuyAvgPrice(CodeName)-1*MinPrice(CodeName);
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("小幅亏损:-1卖平"+T_BuyRemainPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyRemainPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 5;
SPFlag = 1;
}
RETURN;
}
}
// 成交后20秒后价格小于持仓价格-2,则对价出,orderstate=6
IF( PRICE < (T_BuyAvgPrice(CodeName)-3*MinPrice(CodeName) && orderstate == 0))
{
IF((CurrentTime()-BK_TIME) >= 20 )
{
SP_PRICE =data[0].Bid1;
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("大幅亏损:对手卖平"+T_BuyPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 6;
SPFlag = 1;
}
RETURN;
}
}
//50秒还有挂单不成交,对价全平,orderstate=7
IF((CurrentTime()-BK_TIME) >= 50)
{
IF(orderstate != 0 && T_OpenOrder(CodeName, 2) >0)
{
T_DeleteOrder(SPID);
}
SP_PRICE =data[0].Bid1;
IF(T_BuyRemainPosition(CodeName) > 0 && SPFlag == 0)
{
MessageOut("50秒没处理完单子:对手卖平"+T_BuyPosition(CodeName));
SPID = T_Deal(CodeName, 1, 1, T_BuyPosition(CodeName), SP_PRICE);
SP_TIME = CurrentTime();
orderstate = 7;
SPFlag = 1;
}
RETURN;
}
}
|
|