老师好!
开平仓用的是交易师,BarsSinceEntry 和 AvgEntryPrice 函数没有返回值,是什么问题!注:BarsSinceEntry 函数是在当前bar并非开仓bar的情况下 ,也就是开仓后又等了两三根bar后。
代码如下:
Params
//此处添加参数
Numeric Length(5);
Numeric Length1(10);
Numeric Length2(20);
Vars
String my_tb("tbf_wd118552");
series<Numeric> Ma1;
series<Numeric> Ma2;
series<Numeric> Ma3;
Integer Back;
Integer k1;
Integer a(0);
Integer a2(1);
Integer date1;
Integer date2;
Integer date3;
Numeric exitp;
String datetxt;
Bar mybar;
Bar mybar1;
Global Integer un;
Global map<String,Integer> ccmap;
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次
OnInit()
{
A_BindTradeAccount(my_tb);
A_SubscribeTradeByCreateId(Enum_Trade_Source_ALL);
//datetxt=GetTBProfileString2File("d:\\开拓交易者\\localdate.txt","mydate","date2");
//print("datetxt=="+datetxt);
//date3=Value(datetxt);
//print("date3=="+text(date3));
SubscribeBar("rb2301.SHFE","3m",20221101,0);
//SubscribeBar("i2301.DCE","1d",date3,0);
}
OnBar(ArrayRef<Integer> indexs)
{
range[0:0]
{
ma1=Average((open+close+high+low)/4,Length);
ma2=Average((open+close+high+low)/4,Length1);
ma3=Average((open+close+high+low)/4,Length2);
PlotNumeric("ma1",ma1);
PlotNumeric("ma2",ma2);
PlotNumeric("ma3",ma3);
}
if (BarStatus==2)
{
k1=BarsSinceEntry();
exitp=low[k1];
for k1 downto 0
{
if (exitp<low[k1-1])
{
exitp=exitp;
}
Else
{
exitp=low[k1-1];
}
print("BarsSinceEntry=="+text(BarsSinceEntry()));
print("low=="+text(exitp));
print("资金=="+text(A_FreeMargin()));//建仓后的资金变动
print("建仓价格=="+text(AvgEntryPrice()));
print("空头仓位=="+text(A_SellPosition() ));
print("多头仓位=="+text(A_BuyPosition()));
print("ccmap=="+textmap(ccmap));
}
}
}
OnOrder(OrderRef ord)
{
print("Onorder资金=="+text(A_FreeMargin()));
if (ord.combOffset==Enum_Entry and (ord.status==Enum_Filled or ord.status==Enum_FillPart))
{
if (MapContain(ccmap,ord.symbol))
{
MapErase(ccmap,ord.symbol);
}
ccmap[ord.symbol]=ord.orderId;
print("OPENccmap=="+textmap(ccmap));
}else if ((ord.combOffset==Enum_Exit or ord.combOffset==Enum_ExitToday) and ord.status==Enum_Filled)
{
if (MapContain(ccmap,ord.symbol))
{
MapErase(ccmap,ord.symbol);
}
print("EXIEccmap=="+textmap(ccmap));
}
}
图表函数 自然对A_SendOrder也没有用
图表函数只对图表信号起作用,buy sell sellshort buytocover
A函数呢?比如 A_SendOrder?
图表函数和交易师自然没有关系