开拓者期货期权程序化系统交易论坛
标题:
A函数+全局变量控制,还是重复发单问题
[打印本页]
作者:
lolo1973
时间:
2018-11-22 10:28:01
标题:
A函数+全局变量控制,还是重复发单问题
本帖最后由 lolo1973 于 2018-11-22 10:29 编辑
Params
Numeric longPrice(3650);
Numeric shortPrice(3000);
Numeric shiftUnits(100); //下单价格偏移跳数
Numeric waitTime(50); //撤单前等待时长,秒
Vars
Numeric timeSeconds;
Numeric buyPosition;
Numeric sellPosition;
Numeric minPoint;
Numeric units;
String mySection;
String orderStatus;
String orderTime;
Bool buyPositionCon;
Bool sellPositionCon;
String curTime; //currentTime
String path;
Begin
If(!CallAuctionFilter) Return;
path = "C:\\Users\\Administrator\\Desktop\\00_" + FormulaName + "_" + Symbol + ".log";
mySection = FormulaName + Symbol;
orderStatus = "order_status";
orderTime = "order_time";
curTime = TimeToString(CurrentTime);
minPoint = MinMove * PriceScale;
units = 1;
If(BarStatus == 0)
{
SetTBProfileString(mySection, orderStatus, Text(0));
SetTBProfileString(mySection, orderTime, Text(0));
}
timeSeconds = Value(Left(curTime, 2)) * 3600 + Value(Mid(curTime, 3, 2)) * 60 + Value(Right(curTime, 2));
FileAppend(path, "----------------------------" + curTime + "--------------------------");
FileAppend(path, "initial order status: " + GetTBProfileString(mySection, orderStatus) + "; value of order status is: "
+ text(Value(GetTBProfileString(mySection, orderStatus))));
FileAppend(path, "order status == 0: " + IIFString(Value(GetTBProfileString(mySection, orderStatus)) == 0, "true" ,"false"));
//开仓
If(Value(GetTBProfileString(mySection, orderStatus)) == 0);
{
If(Q_AskPrice >= longPrice)
{
A_SendOrder(Enum_Buy, Enum_Entry, units, Q_AskPrice - shiftUnits * minPoint);
SetTBProfileString(mySection, orderStatus, Text(1));
SetTBProfileString(mySection, orderTime, Text(timeSeconds));
FileAppend(path, "long condition filled----order status is: " + GetTBProfileString(mySection, orderStatus) +
"-----order time is: " + curTime);
}Else If(Q_BidPrice <= shortPrice)
{
A_SendOrder(enum_sell, enum_entry, units, Q_BidPrice + shiftUnits * minPoint);
SetTBProfileString(mySection, orderStatus, Text(-1));
SetTBProfileString(mySection, orderTime, Text(timeSeconds));
}
}
buyPosition = A_BuyPosition;
sellPosition = A_SellPosition;
buyPositionCon = (buyPosition > 0);
sellPositionCon = (sellPosition < 0);
FileAppend(path, "buyPosition = " + Text(buyPosition));
If(Value(GetTBProfileString(mySection, orderStatus)) == 1)
{
If(timeSeconds - Value(GetTBProfileString(mySection, orderTime)) >= waitTime and !buyPositionCon)
{
A_DeleteOrder();
SetTBProfileString(mySection, orderStatus, Text(0));
}
}else If(Value(GetTBProfileString(mySection, orderStatus)) == -1)
{
If(timeSeconds - Value(GetTBProfileString(mySection, orderTime)) >= waitTime and !sellPositionCon)
{
A_DeleteOrder();
SetTBProfileString(mySection, orderStatus, Text(0));
}
}
End
复制代码
通过fileappend,开仓之前order status的值确定为1,但程序还是能进入到开仓的条件中,不明所以。
作者:
lolo1973
时间:
2018-11-22 10:35:39
本帖最后由 lolo1973 于 2018-11-22 10:37 编辑
。
作者:
小米
时间:
2018-11-22 10:53:56
第45行的if条件后有加了分号啊。。这样自然限制不住的。
作者:
lolo1973
时间:
2018-11-22 11:36:57
小米 发表于 2018-11-22 10:53
第45行的if条件后有加了分号啊。。这样自然限制不住的。
露出了不争气的微笑。。多谢!
欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/)
Powered by Discuz! X2