Params
// Numeric nYestCloseInput(2210);
Vars
String FileName("d:\\log\\log.txt");
Numeric Offset(3);
Numeric OffsetMargin(0);
Bool bUp(false);
Bool bDown(false);
Numeric lots(1);
Numeric length(10);
NumericSeries MyPrice;
NumericSeries myExitPrice;
Bool SendOrderThisBar(False);
Bool bStart(False);
Numeric i(0);
Numeric nHighPrice(0);
//全局变量的1
Numeric nLowPrice(0);
//全局变量的0
Numeric nDuoZhiS(0);
//全局变量的5
Numeric nKongZhiS(0);
//全局变量的6
Numeric nYestClose(0);
//全局变量的7
BoolSeriesbDuoStoped(false);
BoolSeriesbKongStoped(false);
Begin
/*
FileAppend(FileName,"Bartime="+DateTimeToString(Date+Time)
+" currentTime= "+TimeToString(currentTime)
+" MarketPosition="+Text(MarketPosition)
+" CurrentDate="+DateTimeToString(CurrentDate)
);
*/
OffsetMargin=Offset*MinMove*PriceScale;
//1
//If(Time==0.090000) //商品
If(Time==0.091500) //股指
{
//每天初始化开仓条件
bDuoStoped=false;
bKongStoped=false;
}//
//2、当走完length,即10个周期k线时才判断高低点
//If(Time==0.091000) 商品
If(Time==0.094500)
{
nHighPrice=High[1];
for i=1 To 30
{
If(High[i] > nHighPrice)
nHighPrice = High[i];
}
SetGlobalVar(1,nHighPrice);
nLowPrice=low[1];
for i=1 To 30
{
If(low[i] =0.094500)
{
bStart=True;
nHighPrice=getGlobalVar(1);
nLowPrice=getGlobalVar(0);
FileAppend(FileName,"10日最高价="+Text( nHighPrice)
+" 10日最低价="+Text(nLowPrice)
);
Commentary("10日最高价="+Text(nHighPrice));
Commentary("10日最低价="+Text(nLowPrice));
}
FileAppend(FileName,"昨天收盘价="+Text(CloseD(1))
);
//4、开仓操作
If(!bDuoStoped and MarketPosition1 and High>nHighPrice and OpenInt>OpenInt[1] and Time>=0.0945 and bStart)//从11:21开始启动自动交易
{
MyPrice = Max(Open,nHighPrice)+OffsetMargin;
Buy(Lots,MyPrice);
SendOrderThisBar = true;
FileAppend(FileName,"-1 and lowOpenInt[1] and Time>=0.0945 and bStart)
{
MyPrice = Min(Open,nLowPrice)-OffsetMargin;
SellShort(Lots,MyPrice);
SendOrderThisBar = true;
FileAppend(FileName," >>>>>>>卖出开仓Sell entry"+TimeToString(Time)
+"空单单价格:"+Text(MyPrice)
+" 目前持仓量:"+Text(OpenInt)
+" 前一个持仓量:"+Text(OpenInt[1])
);
//设置止损条件
SetGlobalVar(6,0);
}
//5、正常平仓操作
If(MarketPosition == 1) // 有多仓的情况
{
If(High Open, Open,myExitPrice);
// 大跳空的时候用开盘价代替
Sell(0,myExitPrice);
// 数量用0的情况下将全部平仓
bDuoStoped=True;
FileAppend(FileName,"High[1] and Low>Low[1])//创新低
{
nKongZhiS=getGlobalVar(6);
SetGlobalVar(6,nKongZhiS+1);
//多单止损
FileAppend(FileName," nTodayAP)
If(getGlobalVar(6)==3)
{
//myExitPrice = Min(High,nTodayAP + nTodayAP);
myExitPrice = High;
myExitPrice = IIF(myExitPrice =0.1459)//5分钟周期
Else If(Date==CurrentDate and Time==0.1514 and CurrentTime>=0.151430)//1分钟周期
{
FileAppend(FileName,"******************今天尾盘平仓");
Sell(0,Close-Offset*MinMove*PriceScale);
BuyToCover(0,Close+Offset*MinMove*PriceScale);
}
End