- 精华
- 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
|
代码如下,全局变量似乎只保存了最后一支股票的结果
Global Numeric buynot;
Global Numeric sellnot;
Global Numeric downnot;
Global Numeric upnot;
Bool Buycondition;
Bool Sellcondition;
Events
onBar(ArrayRef<Integer> indexs)
{
Range[0:4]
{
k=CurrentBar;
Commentary("k="+Text(CurrentBar));
Length=NDay*n0;//NDay内的分钟线的个数
NumPos=1;
aa=(1+a0/100);
bb=(1-a0/100);
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=aa*mmax;
sellnot=bb*mmin;
downnot=buynot*0.97;
upnot= sellnot*1.03;
}
/////////////////////////////////////////////////////////////////////////////////////
If(k < Length) Return;
Commentary("buynot="+Text(buynot));
Commentary("sellnot="+Text(sellnot));
Commentary("afa="+Text(afa));
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 AND Close[1]>downnot) // 开多仓
{
Buy(NumPos,Open);
}Else If(SellCondition AND Close[1]<upnot) // 开空仓
{
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);//平多开空
}
}
} |
|