来看看这个开拓者程序为什么不开仓 [开拓者 TB]
- 咨询内容: //价格上穿20均线开多,下穿开空
//
//30%仓位上限
//
//------------------------------------------------------------------------
Params
Numeric Length(20); // 平均波动周期 ATR Length
Vars
NumericSeries AvgValue;
Numeric TotalEquity; // 按最新收盘价计算出的总资产
String BuyPositionStr;
String SellPositionStr;
Numeric BuyPosition;
Numeric SellPosition;
Numeric Units;
String BuyUnitsStr; // 交易单位
String SellUnitsStr;
Numeric BuyUnits; // 交易单位
Numeric SellUnits;
Begin
//If ( Q_Last == 0 || ( Date != Date[1] && High == Low ) ) Return; //如果未开盘,则直接返回
AvgValue = Average(Close,Length);
TotalEquity = Portfolio_CurrentCapital() + Portfolio_UsedMargin();
Units=IntPart((TotalEquity*0.3) /(Close* ContractUnit()*MarginRatio()));
If(GetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyPosition")==InvalidString) //持仓状态赋初值
{
BuyPosition=0;
}
If(GetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellPosition")==InvalidString)
{
SellPosition=0;
}
If(GetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyPosition")!=InvalidString)
{
BuyPositionStr=GetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyPosition");
BuyPosition=Value(BuyPositionStr);
}
If(GetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellPosition")!=InvalidString)
{
SellPositionStr=GetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellPosition");
SellPosition=Value(SellPositionStr);
}
If(GetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyUnits")!=InvalidString)
{
BuyUnitsStr=GetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyUnits");
BuyUnits=Value(BuyUnitsStr);
}
If(GetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellUnits")!=InvalidString)
{
SellUnitsStr=GetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellUnits");
SellUnits=Value(SellUnitsStr);
}
If((Q_Last > AvgValue) &&(Q_High<AvgValue)&&(Units >= 1)&&BuyPosition==0&&SellPosition==0) //无持仓上穿开多
{
A_SendOrder(Enum_Buy,Enum_Entry,Units,Q_UpperLimit);
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyPosition",Text(1));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyUnits",Text(Units));
}
If((Q_Last < AvgValue) &&(Q_Low>AvgValue)&&(Units >= 1)&&SellPosition==0&&BuyPosition==0) //无持仓下穿开空
{
A_SendOrder(Enum_Sell,Enum_Entry,Units,Q_LowerLimit);
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellPosition",Text(-1));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellUnits",Text(Units));
}
If((Q_Last > AvgValue) && (Units >= 1)&&BuyPosition==0&&SellPosition==-1) //空单平仓反手
{
A_SendOrder(Enum_Buy,Enum_Exit,SellUnits,Q_UpperLimit);
A_SendOrder(Enum_Buy,Enum_Entry,Units,Q_UpperLimit);
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellPosition",Text(0));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyPosition",Text(1));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellUnits",Text(0));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyUnits",Text(Units));
}
If((Q_Last < AvgValue) && (Units >= 1)&&SellPosition==0&&BuyPosition==1) //多单平仓反手
{
A_SendOrder(Enum_Sell,Enum_Exit,BuyUnits,Q_LowerLimit);
A_SendOrder(Enum_Sell,Enum_Entry,Units,Q_LowerLimit);
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyPosition",Text(0));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellPosition",Text(-1));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"BuyUnits",Text(0));
SetTBProfileString2File("D:\\TBlog.log",Symbol(),"SellUnits",Text(Units));
}
End - TB技术人员: 具体代码没有细看,这里先提醒楼主Q_Last 只能用于实时行情交易,不能用于历史测试。
- TB客服: 就是因为要具体到判断每一跳的行情才这样写的,求指导,看看问题出在哪里了
- 网友回复: 在明确一下,我的意思是实盘中不下单,不是历史测试
- 网友回复: 好的,明白了。代码需要仔细研究,请耐心等候回复……
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 262069696 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容