今天沒什么可以說的朴译,就是根據(jù)SAR跟移動均線的配合做了三個系統(tǒng)蟆融,當然還是先聲明草巡,這三個系統(tǒng)也是今天隨手寫出來的,測試結果看著還行型酥,但實盤如何山憨,還沒仔細研究過查乒。
第一個很簡單的規(guī)則,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);
// 集合競價和小節(jié)休息過濾
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
第二個攻询,進場規(guī)則跟上邊的一樣从撼,就是出場價格我給變成固定的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);
// 集合競價和小節(jié)休息過濾
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
第三個就是跟蹤止盈止損的低零,當然不是依據(jù)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
三個看著都還行掏婶,當然這些我都沒經(jīng)過什么優(yōu)化的,就是很隨意寫的參數(shù)潭陪,測試的都是焦炭的30min周期雄妥,想用的就自己觀察一段時間看看,不喜歡的就跳過了依溯。