开拓者期货期权程序化系统交易论坛
标题:
大师们帮我看看如何修改策略(RSI做多策略)
[打印本页]
作者:
lionwang888
时间:
2016-1-25 14:43:54
标题:
大师们帮我看看如何修改策略(RSI做多策略)
策略思路:
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
作者:
Allin9999
时间:
2016-1-25 16:19:10
本帖最后由 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
复制代码
作者:
lionwang888
时间:
2016-1-25 21:05:54
Allin9999 发表于 2016-1-25 16:19
在你的代码基础上做了一些修改,供你参考。再进场部分我就按照方便处理的原则简化处理了,假定RSI跌破UpTre ...
非常感谢!!
欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/)
Powered by Discuz! X2