Params
Numeric Threshold(14);//均线建仓阀值,14跳
Numeric NewMAlength(30);//均线周期
Numeric BeginTime(945);//开始交易时间
Numeric EndTime(1435);//停止交易时间
Numeric TrailingStopRate(1); //跟踪止损比例.
Vars
Numeric MinPoint;//一个最小变动单位,也就是一跳
NumericSeries MiddleLine;//中线
NumericSeries NewMA;//新移动平均线
NumericSeries MA_Middle;//计算均线和中轨的距离
NumericSeries MyPrice;//开仓价格
NumericSeries Count;
NumericSeries HigherAfterEntry;//开仓后出现的最高价
NumericSeries LowerAfterEntry;//开仓后出现的最低价
Begin
If(Date != Date[1])
{
Count = 0;
}Else
{
Count = Count[1];
}
//一个最小变动单位,也就是一跳
MinPoint = MinMove*PriceScale;
//计算中均线
NewMA=Average((High + Low + Close)/3,NewMAlength);
//PlotNumeric("新移动平均线",NewMA);
//计算中线
If(CurrentBar==0)
{
MiddleLine=(High + Low + Close)/3;
}
If(Day<>Day[1] And CurrentBar>0)
{
MiddleLine=(High + Low + Close)/3;
}
Else
{
MiddleLine=MiddleLine[1];
}
MA_Middle=MiddleLine-NewMA;
Commentary("中线和中轨的差值="+Text(MA_Middle));
//------------------------------------------------------------------------------------------------
//入场
//------------------------------------------------------------------------------------------------
//多头首次入场
if(Count == 0 && MarketPosition==0 && Time>=BeginTime/10000 And Time<=EndTime/10000 And low[1]>=MiddleLine[1] And NewMA[1]-NewMA[3]>Threshold*MinPoint/ContractUnit )
{
MyPrice=open;
Buy(0,MyPrice);
Count = Count + 1;
Commentary("开多头头寸");
}
//空头首次入场
if(Count == 0 && MarketPosition==0 && Time>=BeginTime/10000 And Time<=EndTime/10000 And High[1]<=MiddleLine[1] And NewMA[3]-NewMA[1]>Threshold*MinPoint/ContractUnit)
{
MyPrice=Open;
SellShort(0,MyPrice);
Count = Count + 1;
Commentary("均线向下,开空头头寸");
}
//------------------------------------------------------------------------------------------------
//记录入场后的最高价和最低价
//------------------------------------------------------------------------------------------------
If(MarketPosition == 1 && BarsSinceentry == 0)
{
HigherAfterEntry = Max(MyPrice, Close);
LowerAfterEntry = LowerAfterEntry[1];
}else If(MarketPosition == -1 && BarsSinceentry == 0)
{
LowerAfterEntry = Min(MyPrice, Close);
HigherAfterEntry = HigherAfterEntry[1];
}
else if((MarketPosition != 0 && BarsSinceentry >= 1))
{
HigherAfterEntry = Max(HigherAfterEntry[1], Close[1]);
LowerAfterEntry = Min(LowerAfterEntry[1], Close[1]);
}
Commentary("Higherafterentry"+text(Higherafterentry));
Commentary("Lowerafterentry"+text(Lowerafterentry));
//------------------------------------------------------------------------------------------------
//跟踪止损
//------------------------------------------------------------------------------------------------
Myprice = HigherAfterEntry - Open*TrailingStopRate/100 ;
If(MarketPosition==1 And Low < Myprice && BarsSinceentry > 0)//多头跟踪止损
{
MyPrice = Min(Open, Myprice);
Sell(0, MyPrice);
/*Count = Count + 1;*/
Commentary("多头跟踪止损");
}
Myprice = LowerAfterEntry + Open*TrailingStopRate/100;
If(MarketPosition==-1 And High > Myprice && BarsSinceentry > 0)//空头跟踪止损
{
MyPrice = Max(Open, myprice);
BuyToCover(0, MyPrice);
/*Count = Count + 1;*/
Commentary("空头跟踪止损");
}
//PlotNumeric("低价",LowerAfterEntry);
//PlotNumeric("平仓价格",Myprice);
End
好的,不好意思
如果已经有老师回答过你的问题,而你想问另外一个问题,那你就另外发个贴。
你现在把原来的问题完全彻底的改了,于是老师的回答看起来牛头不对马嘴,显得老师象是傻的一样。
不礼貌。
有没有其它方式可以从程序上调整一下呢?
没有
你怎么把问题改了?
你这个新的问题,点工具栏的代码升级就行了
你这个改不了
这是策略思路就是错误的
If (Low<=LL) LLBar=CurrentBar;
如果在执行buy信号以后,low向下突破 导致llbar赋值 变大
If ( (CurrentBar-LLBar)>=N2 And High>=MAH)
这个开仓条件里面 llbar变大 (CurrentBar-LLBar)变小 那么条件就闪烁了