- 精华
- 0
- 在线时间
- 32 小时
- UID
- 86702
- 积分
- 130
- 帖子
- 24
- 阅读权限
- 40
- 注册时间
- 2011-12-15
- 最后登录
- 2012-4-5
- 精华
- 0
- UID
- 86702
- 积分
- 130
- 帖子
- 24
- 主题
- 3
- 阅读权限
- 40
- 注册时间
- 2011-12-15
- 最后登录
- 2012-4-5
|
改了一下,就好多了!哈哈。
Params
numeric buyAmount(1);
numeric sellAmount(1);
Vars
NumericSeries myOpen;
NumericSeries myClose;
NumericSeries myHigh;
NumericSeries myLow;
NumericSeries myCloseAverage;
numeric length;
numeric timeInterval(5);
Begin
// GetGlobalVar(4)表示相邻3次平仓的时间间隔
// 1min线调用的条件是在前两次平仓,或则在连续三次平仓的时间间隔>0.0030时
SetGlobalVar(1,999999);
SetGlobalVar(2,999999);
SetGlobalVar(3,999999);
SetGlobalVar(4,999999);
if (GetGlobalVar(4)>0.0030)
{
// 建仓条件
if (BarStatus==2 && MarketPosition>=0 && open>high[1])
{
Buy(buyAmount,Q_AskPrice);
}else if(BarStatus==2 && MarketPosition<=0 && open<low[1])
{
SellShort(sellAmount,Q_BidPrice);
}else if (BarStatus==2 && marketposition>=0 && High>Average(close,600) && ( GreenOrRed(12,26,9)==1 || CrossOver(Average(close,12),Average(close,26))))
{
buy(buyAmount,high);
}else if (BarStatus==2 && MarketPosition<=0 && low<Average(close,600) && (GreenOrRed(12,26,9)==-1 || Crossunder(Average(close,12),Average(close,26))))
{
SellShort(sellAmount,low);
}
// 建仓完毕
// 平仓条件
if (MarketPosition==1 && close<Average(close,600))
{
Sell();
if (GetGlobalVar(1)==999999)
{
SetGlobalVar(1,time);
}else
{
if (GetGlobalVar(2)==999999)
{
SetGlobalVar(2,time);
}else
{
if (GetGlobalVar(3)==999999)
{
SetGlobalVar(3,time);
}else
{
SetGlobalVar(1,GetGlobalVar(2));
SetGlobalVar(2,GetGlobalVar(3));
SetGlobalVar(3,time);
}
}
} // 连续三次平仓时间的滚动记录.
}else if (MarketPosition==-1 && close>Average(close,600))
{
BuyToCover();
if (GetGlobalVar(1)==999999)
{
SetGlobalVar(1,time);
}else
{
if (GetGlobalVar(2)==999999)
{
SetGlobalVar(2,time);
}else
{
if (GetGlobalVar(3)==999999)
{
SetGlobalVar(3,time);
}else
{
SetGlobalVar(1,GetGlobalVar(2));
SetGlobalVar(2,GetGlobalVar(3));
SetGlobalVar(3,time);
}
}
}
}
// 平仓完毕
if (GetGlobalVar(3)!=999999)
{
SetGlobalVar(4,GetGlobalVar(3)-GetGlobalVar(1)); //用全局变量GetGlobalVar(4)来记录连续三次平
// 仓时间的间隔:若GetGlobalVar(4)>0.0030,前部分程序块不会运行
}
}else
{
// 若前面if的程序不被执行,说明连续三次平仓的时间间隔小于0,003;避免市场拉锯,调用更长周期的数据
// 更长周期的数据调用,在下面的代吗里面类似一个逐步开锁的过程,锁便是全局数GetGlobalVar(5) 和 GetGlobalVar(15)
SetGlobalVar(5,999999);
SetGlobalVar(6,999999);
SetGlobalVar(7,999999);
SetGlobalVar(8,999999);
SetGlobalVar(15,999999);
SetGlobalVar(16,999999);
SetGlobalVar(17,999999);
SetGlobalVar(18,999999);
SetGlobalVar(30,999999);
SetGlobalVar(31,999999);
SetGlobalVar(32,999999);
SetGlobalVar(33,999999);
if (GetGlobalVar(5)==999999)
{
timeInterval=5;
}else
{
if (GetGlobalVar(15)==999999)
{
timeInterval=15;
}else
{
timeInterval=30; // 最大调用30min线
}
}
// 开锁结束
// 调用5min的时间线,数据转换
myOpen=DataConvert(open,"min",timeInterval,"open");
myClose=DataConvert(close,"min",timeInterval,"close");
myHigh=DataConvert(high,"min",timeInterval,"high");
myLow=DataConvert(low,"min",timeInterval,"low");
// 跨周期计算均值,跨周期判断穿破,跨周期判断红绿放大,见函数Average_transTimeInterval,
// GreenOrRed_transTimeInterval,以及crossOver_transTimeIntrval,CrossUnder_transTimeInterval
// 先计算跨周期收盘价的均值,为后面的判断准备
myCloseAverage=average_transMinData(myClose,100); //选择平均周期是100次,对于5min而言,就是5min总共500分钟的100次收盘价格
// 跨周期调用数据,并判断是否开仓
if (BarStatus==2 && MarketPosition>=0 && transMinsData(myOpen,timeInterval,0)>transMinsData(myHigh,timeInterval,1))
{
Buy(buyAmount,Q_AskPrice);
}else if (BarStatus==2 && MarketPosition<=0 && transMinsData(myOpen,timeInterval,0)<transMinsData(myLow,timeInterval,1))
{
SellShort(sellAmount,Q_BidPrice);
}else if (BarStatus==2 && MarketPosition>=0 && transMinsData(myHigh)>average_transMinData(myclose,100) && (GreenOrRed_transTimeInterval(myclose,timeInterval,12,26,9)==1 || crossOver_transTimeIntrval(average_transMinData(myclose,12),average_transMinData(myclose,26))==true))
{
Buy(buyAmount,high);
}else if (BarStatus==2 && MarketPosition<=0 && transMinsData(myHigh)<average_transMinData(myclose,100) && (GreenOrRed_transTimeInterval(myclose,timeInterval,12,26,9)==-1 || CrossUnder_transTimeInterval(average_transMinData(myclose,12),average_transMinData(myclose,26))==true))
{
SellShort(sellAmount,low);
}
// 跨周期建仓完毕
// 跨周期平仓条件
if (MarketPosition==1 && close<average_transMinData(myClose,100))
{
Sell();
if (GetGlobalVar(timeInterval)==999999)
{
SetGlobalVar(timeInterval+1,time);
}else
{
if (GetGlobalVar(timeInterval+2)==999999)
{
SetGlobalVar(timeInterval+2,time);
}else
{
if (GetGlobalVar(timeInterval+3)==999999)
{
SetGlobalVar(timeInterval+3,time);
}else
{
SetGlobalVar(timeInterval+1,GetGlobalVar(timeInterval+2));
SetGlobalVar(timeInterval+2,GetGlobalVar(timeInterval+3));
SetGlobalVar(timeInterval+3,time);
}
}
} // 连续三次平仓时间的滚动记录.
}else if (MarketPosition==-1 && close>average_transMinData(myclose,600))
{
BuyToCover();
if (GetGlobalVar(timeInterval)==999999)
{
SetGlobalVar(timeInterval+1,time);
}else
{
if (GetGlobalVar(timeInterval+2)==999999)
{
SetGlobalVar(timeInterval+2,time);
}else
{
if (GetGlobalVar(timeInterval+3)==999999)
{
SetGlobalVar(timeInterval+3,time);
}else
{
SetGlobalVar(timeInterval+1,GetGlobalVar(timeInterval+2));
SetGlobalVar(timeInterval+2,GetGlobalVar(timeInterval+3));
SetGlobalVar(timeInterval+3,time);
}
}
} // 连续三次平仓时间的滚动记录.
}
// 跨周期平仓结束
// 计算跨周期连续三次平仓的时间,若连续平仓时间大于30*周期长度,则赋予相应全局变量值,达到开锁的作用
// 总而启动更长周期的数据调用
if (GetGlobalVar(timeInterval+3)!=999999)
{
if (GetGlobalVar(timeInterval+3)-GetGlobalVar(timeInterval+1)<timeInterval*30)
{
SetGlobalVar(timeInterval,1); // 给开锁变量赋值
}
}
}
End |
|