一个简单日内30分钟高低点突破系统bt源码 [开拓者 TB]
- 咨询内容:
//------------------------------------------------------------------------
// 简称: a_1fenrn4
// 名称: a_1fenrn4
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
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
BoolSeries bDuoStoped(false);
BoolSeries bKongStoped(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] < nLowPrice)
nLowPrice = low[i];
}
SetGlobalVar(0,nLowPrice);
}
//3、当超过length,即30个周期k线时才启动实际的程序运行
If(Time>=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 MarketPosition<>1 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,"<<<<<<<<买入开仓Buy entry"+TimeToString(Time)
+"多单价格:"+Text(MyPrice)
+" 目前持仓量:"+Text(OpenInt)
+" 前一个持仓量:"+Text(OpenInt[1])
);
//设置止损条件
SetGlobalVar(5,0);
}
If(!bKongStoped and MarketPosition<>-1 and low<nLowPrice and OpenInt>OpenInt[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<High[1] and Low<Low[1])//创新低
{
nDuoZhiS=getGlobalVar(5);
SetGlobalVar(5,nDuoZhiS+1); //多单止损
FileAppend(FileName,"<<<<<<<<多仓止损条件判断"+TimeToString(Time)
+"nDuoZhiS:"+Text(nDuoZhiS)
+" 更新后是getGlobalVar(5):"+Text(getGlobalVar(5))
);
}
//If(Low < nTodayAP)
If(getGlobalVar(5)==3)
{
//myExitPrice = max(Low,Low[1] - OffsetMargin);
myExitPrice = Low;
myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); // 大跳空的时候用开盘价代替
Sell(0,myExitPrice); // 数量用0的情况下将全部平仓
bDuoStoped=True;
FileAppend(FileName,"<<<<<<<<多仓卖出平仓"+TimeToString(Time)
+"多单价格:"+Text(myExitPrice)
+" getGlobalVar(5):"+Text(getGlobalVar(5))
);
}
}Else If(MarketPosition ==-1) // 有空仓的情况
{
//低点转折
If(High>High[1] and Low>Low[1])//创新低
{
nKongZhiS=getGlobalVar(6);
SetGlobalVar(6,nKongZhiS+1); //多单止损
FileAppend(FileName,"<<<<<<<<空仓止损条件判断"+TimeToString(Time)
+"nDuoZhiS:"+Text(nKongZhiS)
+" 更新后是getGlobalVar(6):"+Text(getGlobalVar(6))
);
}
//If(High > nTodayAP)
If(getGlobalVar(6)==3)
{
//myExitPrice = Min(High,nTodayAP + nTodayAP);
myExitPrice = High;
myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); // 大跳空的时候用开盘价代替
BuyToCover(0,myExitPrice); // 数量用0的情况下将全部平仓
bKongStoped=True;
FileAppend(FileName,"<<<<<<<<空仓买入平仓"+TimeToString(Time)
+" 价格:"+Text(myExitPrice)
+" getGlobalVar(6):"+Text(getGlobalVar(6))
);
}
}
//6、尾盘多空全部平仓
If((Date[-1]!=InvalidInteger and Date!=Date[-1]) Or (Date[-1]==InvalidInteger and Date<CurrentDate))
{
Sell(0,Close-Offset*MinMove*PriceScale);
BuyToCover(0,Close+Offset*MinMove*PriceScale);
FileAppend(FileName,"******************历史尾盘平仓");
}
//Else If(Date==CurrentDate and Time==0.1455 and CurrentTime>=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
- TB技术人员: 不知公式的出处在哪里?
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 1145508240 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容