- 精华
- 0
- 在线时间
- 39 小时
- UID
- 259001
- 积分
- 47
- 帖子
- 31
- 阅读权限
- 10
- 注册时间
- 2017-11-11
- 最后登录
- 2022-9-15
- 精华
- 0
- UID
- 259001
- 积分
- 47
- 帖子
- 31
- 主题
- 10
- 阅读权限
- 10
- 注册时间
- 2017-11-11
- 最后登录
- 2022-9-15
|
(1)再请教一下:同一个公式,两个参数分别用在同一品种的分钟周期和日周期上,怎么个方式实现较好
(2)上面代码如下,代码中九点半更新的数据放在全局变量中供公式其他时刻使用,在策略单元内加载板块股票进行计算测试,首先交易次数异常,查看k线图上的交易信号和输出数值,是不对的
注:如果将全局变量改为序列变量(局部变量),结果就正常了
Params
Numeric Length(1500);
Vars
Numeric NumPos(1);
Series<Numeric> mprice;
Numeric m;
Numeric i;
Numeric j;
Numeric k;
Numeric temp;
Numeric mytime0;
Numeric TT;
Numeric mmax;
Numeric mmin;
Global Numeric buynot;
Global Numeric sellnot;
Global Numeric downnot;
Global Numeric upnot;
/*
Series<Numeric> buynot;
Series<Numeric> sellnot;
Series<Numeric> downnot;
Series<Numeric> upnot;
*/
Bool Buycondition;//开多
Bool Sellcondition;//平多
Events
onBar(ArrayRef<Integer> indexs)
{
Range[0:4]
{
k=CurrentBar;
Commentary("k="+Text(CurrentBar));
NumPos=1;
mytime0=0.0930;
TT=Time();
If(TT== mytime0) //更新计算
{
mmax=High[1];
mmin=Low[1];
If(mmax==mmin) Return;
for i=1 To Length
{
mmax=Max(High[i+1],mmax);
mmin=Min(Low[i+1],mmin);
}
buynot=mmax;
sellnot=mmin;
downnot=buynot*0.97;
upnot= sellnot*1.03;
}
/////////////////////////////////////////////////////////////////////////////////////
If(k < Length) Return;
Commentary("buynot="+Text(buynot));
Commentary("sellnot="+Text(sellnot));
Commentary("upnot="+Text(upnot));
Commentary("downnot="+Text(downnot));
PlotNumeric("1",buynot);
PlotNumeric("2",sellnot);
//入场条件
//////////////////////////////////////////////////////////////
BuyCondition= Close[1]>buynot ;//建多
SellCondition = Close[1]<sellnot ;//建空
// 系统进场
If(MarketPosition == 0)// 当前无仓位
{
If(Buycondition) // 开多仓
{
Buy(NumPos,Open);
}Else If(SellCondition) // 开空仓
{
SellShort(NumPos,Open);
}
}
// 系统出场
//处理多仓
If(MarketPosition == 1 ) // 已经开多仓,判断是否止损
{
If(downnot>1) PlotNumeric("L",downnot);
If(Close[1] <downnot ) //止损
{
Sell(0,Open);
}
Else If(Sellcondition)
{
Sell(0,Open);
}
}
//处理空仓
If(MarketPosition == -1)// 当前有空仓
{
If(upnot<1000000) PlotNumeric("H",upnot);
If(Close[1] >upnot ) //止损
{
BuyToCover(0, Open);
}
Else If(Buycondition)
{
BuyToCover(0, Open);//平多开空
}
}
}
}
|
|