- 精华
- 0
- 在线时间
- 64 小时
- UID
- 107268
- 积分
- 33
- 帖子
- 16
- 阅读权限
- 10
- 注册时间
- 2012-3-26
- 最后登录
- 2012-5-31
- 精华
- 0
- UID
- 107268
- 积分
- 33
- 帖子
- 16
- 主题
- 6
- 阅读权限
- 10
- 注册时间
- 2012-3-26
- 最后登录
- 2012-5-31
|
本帖最后由 nini123 于 2012-4-20 17:08 编辑
本人是新手,刚接触TB编程不久,语法没有问题但是跟要得到的结果不一样,希望各位前辈帮忙指正修改下
程序:
Params
Numeric TradeEndTime(150500);
Numeric Lots(1);
Numeric Stoploss(5);
Numeric Length1(5);
Numeric Length2(10);
Numeric Length3(20);
Numeric Length4(60);
Vars
NumericSeries MA5;
NumericSeries MA10;
NumericSeries MA20;
NumericSeries MA60;
NumericSeries EntryPrice;
NumericSeries ExitPrice;
NumericSeries high;
NumericSeries Low;
NumericSeries MidLine;
Numeric TargetPrice(0);
Numeric StopPrice(0);
Bool Buycondition(False);
Bool Sellcondition(False);
Bool condition(False);
Bool flag(False);
Begin
MA5=AverageFC(Close,Length1);
MA10=AverageFC(Close,Length2);
MA20=AverageFC(Close,Length3);
MA60=AverageFC(Close,Length4);
PlotNumeric("MA5",MA5);
PlotNumeric("MA10",MA10);
PlotNumeric("MA20",MA20);
PlotNumeric("MA60",MA60);
StopPrice=MA60-Stoploss*minmove*PriceScale;
if(date==date[1]&&Time<TradeEndTime*0.000001)
{if(CrossOver(MA5[1],MA20[1]))
{Buycondition=True;
EntryPrice=Open;
Buy(Lots,EntryPrice);
}//5日均线上穿20日均线,多头进场一手
if(Buycondition&&Close[1]<MA60[1])//进场后,如果价格仍然处于MA60之下
{TargetPrice=EntryPrice+2*minmove*priceScale;
if(CrossUnder(MA5[1],MA20[1]))//5日均线下20日均线时平仓止损
{Sell(lots,Open);
Buycondition=False;
Sellcondition=False;
}
else if(Open-EntryPrice>=5*minmove*PriceScale&&High>=TargetPrice)//有盈利超过五点,则跟踪止盈设在进场点上方两个点
{ExitPrice=Max(TargetPrice,Open);
Sell(Lots,ExitPrice);
}
}
/*B条件*/if(Buycondition&&CrossOver(Close[1],MA60[1]))//进场后价格上穿MA60
{EntryPrice=MA60+MinMove*3*PriceScale;
Buy(Lots,EntryPrice);//在MA60上方3点处加仓一手
if(Low<=MidLine)//止损设于布林通道中轨处
{ExitPrice=min(MidLine,Open);
sell(lots,Exitprice);
Buycondition=False;//多单进场条件清零
condition=True;
}
}
/*C条件*/if(condition&&CrossUnder(MA5[1],MA20[1]))
{SellShort(Lots,open);
StopPrice=MA60-Stoploss*minmove*PriceScale;
flag=true;
if(high>=StopPrice)
{ExitPrice=Min(StopPrice,open);
Buytocover(lots,ExitPrice);
Buycondition=False;
Sellcondition=False;
}
else
{if(CrossOver(MA5[1],MA10[1]))
buytocover(lots,open);
else if(Close<=midline)
{Buytocover(lots,open);
}
}
}
if(condition&&flag&&CrossOver(MA5[1],MA20[1]))
{buy(lots,open);
TargetPrice=open+10*minmove*PriceScale;
if(High>=TargetPrice)
sell(lots,min(TargetPrice,open));
else if(CrossUnder(MA5[1],MA10[1]))
sell(lots,open);
}
}
else
{Sell(0,open);
Buytocover(0,open);
Buycondition=False;
Sellcondition=False;
}
End |
|