我在on bar 域里写了,If(BarStatus == 2 && CurrentTime < 0.09 ) Return; 来避免策略在没开盘的时候发单,但是早晨一打开自动交易,就给了以下提示。为啥还会报单呢?
If(BarStatus == 2 && CurrentTime < 0.09 ) Return;
你这句代码的意思应该是 执行到最新的bar,并且机器时间在0点到早上9点之间,return
那么如果你没执行到最新的bar,现在在历史bar上,那不就不会return了吗?
这个应该很好理解的吧
因为你的a函数在历史bar上也报单了
用两种方式控制
第一种,设置好的策略单元不要直接点击启动交易,先点启动,再点启动交易
第二种,对报单命令a_sendorderex进行控制,仅限在barstatus==2的时候,也就是最新bar才报单
虽然不太懂您说的原因,但貌似解决方法很简单。为啥我写了If(BarStatus == 2 && CurrentTime < 0.09 ) Return;这句依旧无法控制A函数报单呢?而且报出去的价格还是后复权的错误价格?在交易时间开启自动交易就没上述问题
揣摩了一下,是不是我以为的barstatus已经是最后一根,但是系统不这么认为,然后就规避了控制。我直接把If(BarStatus == 2 && CurrentTime < 0.09 ) Return;改成If(CurrentTime < 0.09 ) Return; 同时,在a_sendorderex开仓语句里加了您说的barstatus == 2作为条件。
这种问题要查看代码和配置环境进行调试测试的
刘老师,barstatus == 2这个判断语句,还能用在实盘中吗?
OnBar(ArrayRef<Integer> indexs)
{
If(BarStatus == 2 && CurrentTime < 0.09 ) Return;
If(BarStatus == 2 && CurrentTime < 0.1330 && CurrentTime > 0.1130) Return;
If(BarStatus == 2 && CurrentTime < 0.21 && CurrentTime > 0.15) Return;
(中间条件判断和执行语句省略)
}
可以用在实盘
建议你发原文,而且要完整
之前你的就没有发原文,导致根本没法回答。你明明用的是a函数,给的demo例子却写的是图表信号命令,两边机制完全是不同的,等于答非所问。
Params
Numeric Length(2); //周期
Numeric SlowLength(26);
Numeric Offset(1.5); //标准差倍数
Vars
Series<Numeric> UpLine; //上轨
Series<Numeric> DownLine; //下轨
Series<Numeric> MidLine; //中间线
Series<Numeric> Band;//样本方差
global Numeric lposition;//多头持仓量
global Numeric sposition;//空头持仓量
Global Numeric entbar(1);//检验是否在同一根bar
Events
OnInit()
{
AddDataFlag(Enum_Data_RolloverBackWard());
AddDataFlag(Enum_Data_RolloverRealPrice());
AddDataFlag(Enum_Data_AutoSwapPosition());
AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());
SetBeginBarMaxCount(10); //设置最大起始bar数为10
SetOrderMap2MainSymbol();//映射主力合约
}
OnReady()
{
SetBackBarMaxCount(1+Max(SlowLength,Length));
}
OnBarOpen(ArrayRef<Integer> indexs)
{
entbar = 0;//控制变量,为0时才退出
}
OnBar(ArrayRef<Integer> indexs)
{
Numeric a;
Numeric result = 1;
for a = 0 to DataSourceSize-1
{
result = result*data[a].BarExistStatus;
}
If (result <> 1) Return;//检查跨周期数据源是否闪烁
If(BarStatus == 2 && CurrentTime < 0.09 ) Return;
If(BarStatus == 2 && CurrentTime < 0.1330 && CurrentTime > 0.1130) Return;
If(BarStatus == 2 && CurrentTime < 0.21 && CurrentTime > 0.15) Return;
Position pos;//获取指定合约当前仓位
A_GetPosition(relativeSymbol, pos, \"\");
lposition = pos.longCurrentVolume;
sposition = pos.shortCurrentVolume;
Range[0:DataSourceSize() - 1]
{
MidLine = AverageFC(Close[1],Length);
Band = StandardDev(Close[1],Length,2);
UpLine = MidLine + Offset * Band;
DownLine = MidLine - Offset * Band;
PlotNumeric(\"UpLine\",UpLine);
PlotNumeric(\"DownLine\",DownLine);
PlotNumeric(\"MidLine\",MidLine);
}
If (CurrentBar >= Max(SlowLength,Length))
{
Range[0:0]
{
If(lposition == 0 && Q_AskPrice <= DownLine)
{
Array<Integer> orderids;
A_SendOrderEx(RelativeSymbol, enum_Buy, Enum_Entry, 1, Q_AskPrice/rollover(), orderids,\"\",\"\");//低线做多
entbar = 1;
}
If(lposition > 0 && Q_BidPrice >= UpLine && entbar == 0)//多头止赢
{
Array<Integer> orderids;
A_SendOrderEx(RelativeSymbol, Enum_Sell,Enum_Exit, 1, Q_BidPrice/rollover(), orderids,\"\",\"\");
}
If( sposition == 0 && Q_BidPrice >= UpLine)
{
Array<Integer> orderids;
A_SendOrderEx(RelativeSymbol, Enum_Sell,Enum_Entry, 1, Q_BidPrice/rollover(), orderids,\"\",\"\");//高线做空
entbar = 1;
}
If(sposition > 0 && Q_AskPrice <= downLine && entbar == 0)//空头止赢
{
Array<Integer> orderids;
A_SendOrderEx(RelativeSymbol, Enum_buy, Enum_Exit, 1, Q_AskPrice/rollover(), orderids,\"\",\"\");
}
}
}
}
//------------------------------------------------------------------------
// 编译版本 2024/06/20 220532
// 版权所有 xingn1991
// 更改声明 TradeBlazer Software保留对TradeBlazer平台
// 每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
好的老师,代码如上哈,每天交易时间前点击自动交易,就会报单,价格还是错的。
夜盘还没开始,又开始报单了,明明加了条件控制的
刚发现,这个报单的委托价格还是错的,我策略里都复权处理过的,前期的成交单报价都没问题。用的A函数,报单价格是q_bidprice/rollover( )这种形式