Params
Numeric Length1(20);
Numeric Length2(60);
Numeric Length3(180);
Numeric BreakMin(2);
Numeric BreakMax(20);
Numeric Lots(1);
Vars
Series<Numeric> MA1;
Series<Numeric> MA2;
Series<Numeric> MA3;
Series<Numeric> MADiff;
Series<Numeric> LowPrice;
Series<Numeric> HighPrice;
Series<Numeric> LowPrice2;
Series<Numeric> HighPrice2;
Events
//此处实现事件函数
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<integer> indexs)
{
//计算三条均线
MA1=AverageFC(Close,Length1);
MA2=AverageFC(Close,Length2);
MA3=AverageFC(Close,Length3);
PlotNumeric(\"MA1\",MA1);
PlotNumeric(\"MA2\",MA2);
PlotNumeric(\"MA3\",MA3);
//Commentary(\"利用上根均线计算下根均线MA1:“+Text( (MA1[1]*(Length1-1)+Close)/Length1 ));
//判断均线上穿情况
MADiff= Abs(MA1[1]-MA2[1]) ;
LowPrice=(BreakMin*Length1*Length2+Length1*Summation(Close,Length2-1) -Length2*Summation(Close,Length1-1))/(Length2-Length1);
HighPrice=(BreakMax*Length1*Length2+length1*Summation(Close,Length2-1)-Length2*Summation(Close,Length1-1))/(Length2-Length1);
HighPrice2=(BreakMax*Length1*Length2+length1*Summation(Close,Length2-1)+Length2*Summation(Close,Length1-1))/(Length2-Length1);
LowPrice2=(Breakmax*Length1*Length2-Length1*Summation(Close,Length2-1)+Length2*Summation(Close,Length1-1))/(Length1-Length2);
Commentary(\"下根K线可以成交的最低价:\"-Text(LowPrice2));
Commentary(\"下根K线可以成交的最高价:\"+Text(HighPrice2));
Commentary(\"两条均线上次之差:\"+Text(Abs(MA1[1]-MA2[1])));
Commentary(\"两条均续本次之差:\"+Text(Abs(MA1-MA2)));
//开仓
If (MarketPosition == 0 And Vol> 0 And MA1>MA2)
{
If (Open>=LowPrice[1] And Open<HighPrice[1])
{
Buy(Lots,Open);
}Else If (Open>=HighPrice[1] And Low<HighPrice[1])
{
Buy(Lots,HighPrice[1]);
}Else If (Open<LowPrice[1] And High>=LowPrice[1])
{
Buy(Lots,LowPrice[1]);
}
}
If (MarketPosition == 0 And Vol>0 And MA1<MA2)
{
If (Open>=LowPrice2[1] And Open<HighPrice2[1])
{
Sellshort(Lots,Open);
}Else If (Open>=HighPrice2[1] And Low<HighPrice2[1])
{
SellShort(Lots,HighPrice2[1]);
}Else If (Open<LowPrice2[1] And High>=LowPrice2[1])
{
SellShort(Lots,LowPrice2[1]);
}
}
if(MarketPosition==1 And Vol> 0 And MA1[1]<MA2[1] And MADiff>10)
{
Sell(0,Open);
}
If (MarketPosition==-1 And Vol>0 And ma1>MA2[1] And MADiff>10)
{
Sell(0,Open);
}
If(MarketPosition==-1 And Vol>0 And MA1[1]>MA2[1] And MADiff>10)
{
BuyToCover(0,Open);
}
}
改成+号
Commentary(下根K线可以成交的最低价:+Text(LowPrice2));