今天没什么可以说的,就是根据SAR跟移动均线的配合做了三个系统,当然还是先声明,这三个系统也是今天随手写出来的,测试结果看着还行,但实盘如何,还没仔细研究过。
第一个很简单的规则,5均线在20均线上方,并且前一个收盘价在200均线上方,并且SAR点位前一个点比再前一个点高,进场开多。做空就是反过来了。
出场位置,就是要么5均线与20均线交叉,要么就是SAR点位前一个比再前一个低。
代码及结果,如下:
Params
Numeric FastLength(5);
Numeric SlowLength(20);
Numeric DslowLength(200);
Numeric AfStep( 0.02);
Numeric AfLimit( 0.2 ) ;
Vars
NumericSeries AvgValue1;
NumericSeries AvgValue2;
NumericSeries AvgValue3;
Numeric oParCl( 0 );
Numeric oParOp( 0 );
Numeric oPosition( 0 );
Numeric oTransition( 0 );
NumericSeries hk;
Begin
ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) ;
hk = oParCl;
AvgValue1 = AverageFC(Close,FastLength);
AvgValue2 = AverageFC(Close,SlowLength);
AvgValue3 = AverageFC(Close,DslowLength);
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);
PlotNumeric("MA3",AvgValue3);
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
If(MarketPosition <>1 && AvgValue1[1] > AvgValue2[1] && Close[1] > AvgValue3[1] And hk[1] > hk[2])
{
Buy(1,Open);
}
If(MarketPosition ==1 && AvgValue1[1] < AvgValue2[1] Or hk[1]
{
Sell(1,Open);
}
If(MarketPosition <>-1 && AvgValue1[1] < AvgValue2[1] && Close[1] < AvgValue3[1] And hk[1]
{
SellShort(1,Open);
}
If(MarketPosition ==-1 && AvgValue1[1] > AvgValue2[1] Or hk[1]>hk[2])
{
BuyToCover(1,open);
}
End
第二个,进场规则跟上边的一样,就是出场价格我给变成固定的1:4,就是添加之前写的固定止损止盈。代码及结果如下:
Params
Numeric FastLength(5);
Numeric SlowLength(20);
Numeric DslowLength(200);
Numeric AfStep( 0.02);
Numeric AfLimit( 0.2 ) ;
Vars
NumericSeries AvgValue1;
NumericSeries AvgValue2;
NumericSeries AvgValue3;
Numeric oParCl( 0 );
Numeric oParOp( 0 );
Numeric oPosition( 0 );
Numeric oTransition( 0 );
NumericSeries hk;
Numeric MinPoint;
Numeric MyEntryPrice;
Numeric TakeProfitSet(120);
Numeric StopLossSet(30);
Numeric MyExitPrice;
Begin
ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) ;
hk = oParCl;
AvgValue1 = AverageFC(Close,FastLength);
AvgValue2 = AverageFC(Close,SlowLength);
AvgValue3 = AverageFC(Close,DslowLength);
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);
PlotNumeric("MA3",AvgValue3);
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
If(MarketPosition <>1 && AvgValue1[1] > AvgValue2[1] && Close[1] > AvgValue3[1] And hk[1] > hk[2])
{
Buy(1,Open);
}
If(MarketPosition <>-1 && AvgValue1[1] < AvgValue2[1] && Close[1] < AvgValue3[1] And hk[1]
{
SellShort(1,Open);
}
If(!CallAuctionFilter()) Return;
MinPoint = MinMove*PriceScale;
MyEntryPrice = AvgEntryPrice;
if(MarketPosition <> 1 And Close[1] > Close[2] And Close[1]>AvgValue3)
{
Buy(1,Open);
}
If(MarketPosition <> -1 And Close[1] < Close[2] And Close[1]
{
SellShort(1,Open);
}
If(!CallAuctionFilter()) Return;
MinPoint = MinMove*PriceScale;
MyEntryPrice = AvgEntryPrice;
If(MarketPosition==1)
{
If(High >= MyEntryPrice + TakeProfitSet*MinPoint)
{
MyExitPrice = MyEntryPrice + TakeProfitSet*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open;
Sell(0,MyExitPrice);
}else if(Low <= MyEntryPrice - StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open;
Sell(0,MyExitPrice);
}
}else if(MarketPosition==-1)
{
If(Low <= MyEntryPrice - TakeProfitSet*MinPoint)
{
MyExitPrice = MyEntryPrice - TakeProfitSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open;
BuyToCover(0,MyExitPrice);
}else if(High >= MyEntryPrice + StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open;
BuyToCover(0,MyExitPrice);
}
}
End
第三个就是跟踪止盈止损的,当然不是依据SAR点,还是用之前写的那个止盈止损了,代码及结果如下:
Params
Numeric FastLength(5);
Numeric SlowLength(20);
Numeric DslowLength(200);
Numeric StopPoint(45);
Numeric ProfitPoint(100);
Numeric AfStep( 0.02);
Numeric AfLimit( 0.2 ) ;
Numeric TrailingStart1(50);
Numeric TrailingStart2(80);
Numeric TrailingStop1(30);
Numeric TrailingStop2(20);
Numeric StopLossSet(30);
Vars
NumericSeries AvgValue1;
NumericSeries AvgValue2;
NumericSeries AvgValue3;
Numeric oParCl( 0 );
Numeric oParOp( 0 );
Numeric oPosition( 0 );
Numeric oTransition( 0 );
NumericSeries hk;
Numeric MinPoint;
NumericSeries HighestAfterEntry;
NumericSeries LowestAfterEntry;
Numeric MyEntryPrice;
Numeric MyExitPrice;
Numeric myprice;
Begin
AvgValue1 = AverageFC(Close,FastLength);
AvgValue2 = AverageFC(Close,SlowLength);
AvgValue3 = AverageFC(Close,DslowLength);
ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) ;
hk = oParCl;
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);
PlotNumeric("MA3",AvgValue3);
If(!CallAuctionFilter()) Return;
If(MarketPosition <>1 && AvgValue1[1] > AvgValue2[1] && Close[1] > AvgValue3[1] And hk[1] > hk[2])
{
Buy(1,Open);
}
If(MarketPosition <>-1 && AvgValue1[1] < AvgValue2[1] && Close[1] < AvgValue3[1] And hk[1]
{
SellShort(1,Open);
}
MinPoint = MinMove*PriceScale;
If(BarsSinceentry == 0)
{
HighestAfterEntry = Close;
LowestAfterEntry = Close;
If(MarketPosition <> 0)
{
HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice);
LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice);
}
}else
{
HighestAfterEntry = Max(HighestAfterEntry,High);
LowestAfterEntry = Min(LowestAfterEntry,Low);
}
Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
Commentary("MyEntryPrice="+Text(MyEntryPrice));
MinPoint = MinMove*PriceScale;
MyEntryPrice = AvgEntryPrice;
If(MarketPosition==1)
{
If(HighestAfterEntry[1] >= MyEntryPrice + TrailingStart2*MinPoint)
{
If(Low <= HighestAfterEntry[1] - TrailingStop2*MinPoint)
{
MyExitPrice = HighestAfterEntry[1] - TrailingStop2*MinPoint;
Sell(0,MyExitPrice);
}
}else if(HighestAfterEntry[1] >= MyEntryPrice + TrailingStart1*MinPoint)
{
If(Low <= HighestAfterEntry[1] - TrailingStop1*MinPoint)
{
MyExitPrice = HighestAfterEntry[1] - TrailingStop1*MinPoint ;
Sell(0,MyExitPrice);
}
}else if(Low <= MyEntryPrice - StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
Sell(0,MyExitPrice);
}
}else if(MarketPosition==-1)
{
If(LowestAfterEntry[1] <= MyEntryPrice - TrailingStart2*MinPoint)
{
If(High >= LowestAfterEntry[1] + TrailingStop2*MinPoint)
{
MyExitPrice = LowestAfterEntry[1] + TrailingStop2*MinPoint;
BuyToCover(0,MyExitPrice);
}
}else if(LowestAfterEntry[1] <= MyEntryPrice - TrailingStart1*MinPoint)
{
If(High >= LowestAfterEntry[1] + TrailingStop1*MinPoint)
{
MyExitPrice = LowestAfterEntry[1] + TrailingStop1*MinPoint;
BuyToCover(0,MyExitPrice);
}
}else If(High >= MyEntryPrice + StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
BuyToCover(0,MyExitPrice);
}
}
End
三个看着都还行,当然这些我都没经过什么优化的,就是很随意写的参数,测试的都是焦炭的30min周期,想用的就自己观察一段时间看看,不喜欢的就跳过了。