大師們幫我看看如何修改策略(RSI做多策略) [開拓者 TB]
- 咨詢內容:
策略思路:
RSI 多頭策略
1 多頭入場: RSI 上破55, 在下一根Bar開盤價入場。
2 多頭出場: RSI下破45,在下一根bar 開盤價出場。
3 保護性止損: 當價格下破 進場價減一定倍數(初始值為1)的ATR時,止損出場。
4 跟蹤止盈(止損): 多頭入場后,記錄入場后最高點,然后在價格下破 最高點減 一定倍數ATR( 初始值設定為1時) 止盈(止損)出場
另外,如果策略想加上一個再進場,止損后,如果價格突破10日高點,再進場,要怎么寫。。。
初學階段,自己改了幾次,越改越不對路了。 只好向大師求教。。。
Params
Numeric Length(14) ;
Numeric DnTrend(45) ;
Numeric UpTrend(55);
Numeric Lots(0);
Numeric CoATR(1);
Numeric ATRLength(14);
Numeric TrailStopCoATR(1);
Vars
NumericSeries NetChgAvg( 0 );
NumericSeries TotChgAvg( 0 );
Numeric SF( 0 );
NumericSeries Change( 0 );
NumericSeries ChgRatio( 0 ) ;
NumericSeries RSIValue;
NumericSeries ProtectStopLoss(0);
NumericSeries HighestAfterEntry(0);
NumericSeries TrailStopLine(0);
Begin
// 集合競價和小節休息過濾
If(!CallAuctionFilter()) Return;
If(CurrentBar <= Length - 1)
{
NetChgAvg = ( Close - Close[Length] ) / Length ;
TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
}Else
{
SF = 1/Length;
Change = Close - Close[1] ;
NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;
}
If( TotChgAvg <> 0 )
{
ChgRatio = NetChgAvg / TotChgAvg;
}else
{
ChgRatio = 0 ;
}
RSIValue = 50 * ( ChgRatio + 1 );
PlotNumeric("RSI",RSIValue);
PlotNumeric("UpTrend",UpTrend);
PlotNumeric("DnTrend",DnTrend);
If (MarketPosition<>1&& RSIValue[1]>UpTrend)
{
Buy(Lots,Open);
ProtectStopLoss=LastEntryPrice-CoATR*AvgTrueRange(ATRLength);
}
Commentary("rotectStopLoss"+Text(ProtectStopLoss));
If(MarketPosition==1&&BarsSinceEntry>0)
{
If (Low<=ProtectStopLoss)
{
Sell(0,Min(Open,ProtectStopLoss));
Commentary("rotectStop");
}
}
If (BarsSinceEntry==0)
HighestAfterEntry=High;
Else
HighestAfterEntry=Max(HighestAfterEntry[1],High);
TrailStopLine=HighestAfterEntry-TrailStopCoATR*AvgTrueRange(ATRLength);
Commentary("TrailStopLine"+Text(TrailStopLine));
If (MarketPosition==1&&BarsSinceEntry>0)
{
If(Low<=TrailStopLine[1])
{
Sell(0,Min(Open,TrailStopLine[1]));
Commentary("TrailStop");
}
}
If(MarketPosition==1&&BarsSinceEntry>0)
{
If(RSIValue[1]<DnTrend)
{
Sell(0,Open);
Commentary("反手出場");
}
}
End
- TB技術人員:
本帖最后由 Allin9999 于 2016-1-25 16:21 編輯
在你的代碼基礎上做了一些修改,供你參考。再進場部分我就按照方便處理的原則簡化處理了,假定RSI跌破UpTrend,就不算再進場了。這個具體寫的時候還是要根據自己的策略進行調整。- Params
- Numeric Length(14) ;
- Numeric DnTrend(45) ;
- Numeric UpTrend(55);
- Numeric Lots(0);
- Numeric CoATR(1);
- Numeric ATRLength(14);
- Numeric TrailStopCoATR(1);
-
- Vars
- NumericSeries NetChgAvg( 0 );
- NumericSeries TotChgAvg( 0 );
- Numeric SF( 0 );
- NumericSeries Change( 0 );
- NumericSeries ChgRatio( 0 ) ;
- NumericSeries RSIValue;
- NumericSeries ProtectStopLoss(0);
- NumericSeries HighestAfterEntry(0);
- NumericSeries TrailStopLine(0);
- NumericSeries AtrValue;
- Numeric RangeHigh;
-
- Begin
- // 集合競價和小節休息過濾
- If(!CallAuctionFilter()) Return;
-
- If(CurrentBar <= Length - 1)
- {
- NetChgAvg = ( Close - Close[Length] ) / Length ;
- TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
- }Else
- {
- SF = 1/Length;
- Change = Close - Close[1] ;
- NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
- TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;
- }
-
- If( TotChgAvg <> 0 )
- {
- ChgRatio = NetChgAvg / TotChgAvg;
- }else
- {
- ChgRatio = 0 ;
- }
- RSIValue = 50 * ( ChgRatio + 1 );
- PlotNumeric("RSI",RSIValue);
- PlotNumeric("UpTrend",UpTrend);
- PlotNumeric("DnTrend",DnTrend);
-
- AtrValue = AvgTrueRange(ATRLength);
- Commentary("AtrValue="+Text(AtrValue));
- RangeHigh = Highest(H[1],10);
-
- If(MarketPosition<>1 && RSIValue[2] < UpTrend And RSIValue[1]>UpTrend)
- {
- Buy(Lots,Open);
- ProtectStopLoss=LastEntryPrice-CoATR*AtrValue;
- }
- Else If(MarketPosition<>1 And High >= RangeHigh And RSIValue[1]>UpTrend)
- {
- Buy(Lots,Max(Open,RangeHigh));
- ProtectStopLoss=LastEntryPrice-CoATR*AtrValue;
- }
- Commentary("ProtectStopLoss"+Text(ProtectStopLoss));
- If(MarketPosition==1 && BarsSinceEntry>0)
- {
- If(RSIValue[1]<DnTrend)
- {
- Sell(0,Open);
- Commentary("反手出場");
- }
- }
-
- If(MarketPosition==1 && BarsSinceEntry>0)
- {
- If (Low<=ProtectStopLoss)
- {
- Sell(0,Min(Open,ProtectStopLoss));
- Commentary("ProtectStop");
- }
- }
-
- If (BarsSinceEntry==0)
- HighestAfterEntry=High;
- Else
- HighestAfterEntry=Max(HighestAfterEntry[1],High);
-
- TrailStopLine = HighestAfterEntry - TrailStopCoATR*AtrValue;
- Commentary("TrailStopLine"+Text(TrailStopLine));
- If(MarketPosition==1&&BarsSinceEntry>0)
- {
- If(Low<=TrailStopLine[1])
- {
- Sell(0,Min(Open,TrailStopLine[1]));
- Commentary("TrailStop");
- }
- }
-
- End
- Params
- TB客服:
Allin9999 發表于 2016-1-25 16:19
在你的代碼基礎上做了一些修改,供你參考。再進場部分我就按照方便處理的原則簡化處理了,假定RSI跌破UpTre ...
非常感謝!!
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 511411198 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容