- 精华
- 0
- 在线时间
- 38 小时
- UID
- 223939
- 积分
- 20
- 帖子
- 20
- 阅读权限
- 10
- 注册时间
- 2015-11-26
- 最后登录
- 2019-8-17
- 精华
- 0
- UID
- 223939
- 积分
- 20
- 帖子
- 20
- 主题
- 0
- 阅读权限
- 10
- 注册时间
- 2015-11-26
- 最后登录
- 2019-8-17
|
本帖最后由 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
复制代码 |
|