开拓者期货期权程序化系统交易论坛
标题:
请教全局变量问题
[打印本页]
作者:
i7755_1
时间:
2019-1-10 02:42:07
标题:
请教全局变量问题
本帖最后由 i7755_1 于 2019-1-10 02:41 编辑
新手,刚刚接触TB,学着写策略,遇到如下问题。
见图片[attach]37474[/attach]:
开盘到收盘,一直不停地写。
请问出现这样的情况,怎样解决。
//If(!CallAuctionFilter) Return;
If( BarStatus ==0 )
{
SetGlobalVar( 0, 1 ); //记录
SetGlobalVar( 1, 1 ); //记录
SetGlobalVar( 2, 0 ); //记录
SetGlobalVar( 3, 0 ); //记录
SetGlobalVar( 4, 0 ); //记录
SetGlobalVar( 5, 0 ); //记录
SetGlobalVar( 6, 0 ); //记录
SetGlobalVar( 7, 0 ); //记录
}
MA = AverageFC( Close, M );
PlotNumeric( "均线", MA, 0, Yellow );
PlotNumeric( "上线", MA + yuanli*MinMove*PriceScale , 0, Green );
PlotNumeric( "下线", MA - zhisun*MinMove*PriceScale , 0, Red );
If( BarStatus ==2 )
{
If( CurrentTime < opentime/100 )
{
SetGlobalVar( 6, 0 );
Return;
}
If( Q_BidPrice > MA and GetGlobalVar(0) ==1 )
SetGlobalVar( 0, 0 );
If( ( A_BuyPosition >0 or A_BuyPosition ==0 and A_GetLastOpenOrderIndex( Enum_Buy, Enum_Entry ) == InvalidInteger ) and GetGlobalVar(1) ==1 )
{
SetGlobalVar( 1, 0 ); //允许开仓
FileAppend( "C:\\WeiJun_MA_A_" +SymbolName+ ".txt ", "时间 = " + Text( date + CurrentTime ) + " GetGlobalVar(1)归零时 = " + Text( A_GetOpenOrderCount ));
}
If( ( A_BuyPosition ==0 OR A_BuyPosition >0 and A_GetLastOpenOrderIndex( Enum_Sell, Enum_Exit ) == InvalidInteger ) and GetGlobalVar(3) <>0 )
{
SetGlobalVar( 3, 0 ); //允许止盈
FileAppend( "C:\\WeiJun_MA_A_" +SymbolName+ ".txt ", "时间 = " + Text( date + CurrentTime ) + " GetGlobalVar(3)归零时 = " + A_OpenOrderContractNo( A_GetLastOpenOrderIndex( Enum_Sell, Enum_Exit ) ) );
}
If( A_BuyPosition ==0 and GetGlobalVar(1) ==0 and GetGlobalVar(0) ==0 and Q_BidPrice < MA + yuanli*MinMove*PriceScale and CurrentTime <= lastopentime/100 )
{
A_SendOrder( Enum_Buy, Enum_Entry, lots, Q_BidPrice - N2*MinMove*PriceScale );
SetGlobalVar( 2, Q_BidPrice );
SetGlobalVar( 1, 1 );
SetGlobalVar( 4, 0 );
SetGlobalVar( 7, 0 );
FileAppend( "C:\\WeiJun_MA_A_" +SymbolName+ ".txt ", "时间 = " + Text( date + CurrentTime ) + " 开仓 = " + Text( Q_BidPrice ));
}
If( GetGlobalVar(2) == InvalidNumeric OR GetGlobalVar(2) ==0 ) SetGlobalVar( 2, Q_BidPrice );
If( A_BuyPosition ==0 and A_GetLastOpenOrderIndex( Enum_Buy, Enum_Entry ) <> InvalidInteger and Q_BidPrice >= GetGlobalVar(2) + N3*MinMove*PriceScale and GetGlobalVar(1) ==1)
{
A_DeleteOrder( A_OpenOrderContractNo( A_GetLastOpenOrderIndex( Enum_Buy, Enum_Entry ) ) );
SetGlobalVar( 1, 0 );
SetGlobalVar( 2, Q_BidPrice );
FileAppend( "C:\\WeiJun_MA_A_" +SymbolName+ ".txt ", "时间 = " + Text( date + CurrentTime ) + " 撤开仓和尾仓 = " + A_OpenOrderContractNo( A_GetLastOpenOrderIndex( Enum_Buy, Enum_Entry ) ) );
}
If( A_BuyPosition >0 and GetGlobalVar(3) ==0 and GetGlobalVar(4) ==0 and CurrentTime < stoptime/100 )
{
A_SendOrder( Enum_Sell, Enum_Exit, lots, GetGlobalVar(2) + zhiying*MinMove*PriceScale );[/code]
作者:
i7755_1
时间:
2019-1-10 09:40:51
请版主帮忙看看!!!
作者:
i7755_1
时间:
2019-1-10 15:32:47
版主在吗?
作者:
小米
时间:
2019-1-10 16:32:14
日志都是在条件下的,如果一直写入,那一定是条件都有满足啊。
您的疑问是什么?
作者:
i7755_1
时间:
2019-1-10 17:06:18
提示仓位不符
作者:
i7755_1
时间:
2019-1-10 17:08:19
重复开仓,重复平仓
作者:
小米
时间:
2019-1-11 14:44:31
i7755_1 发表于 2019-1-10 17:08
重复开仓,重复平仓
前面有提到,你的日志是不断在写入,那说明条件是不断被满足。
想要一一排查,则需要将每一个条件里所需的值都全部输出,再人工眼肉判断,是哪一步哪一个数据与你的需求不匹配?
代码逻辑挺混的,实在不明白你的3,4号全局变量本来就一直是0的情况下,你要判断3,4为0时平仓。那不就是开完就平吗?
PS: 建议在完全了解TB的机制以及熟练掌握TB的公式编写后再进程A函数的编写。
作者:
i7755_1
时间:
2019-1-12 03:54:32
非常感谢版主回复和建议!
欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/)
Powered by Discuz! X2