- UID
- 2
- 积分
- 2874674
- 威望
- 1387366 布
- 龙e币
- 1487308 刀
- 在线时间
- 13156 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2024-11-24
|
一般我都懒得附上具体数据的,都是想让对这交易系有兴趣的朋友自己去看去分析,这回附上,也是让两对比看得更清楚点而已,好了,我们再接着来看有止损的,代码及结果如下:- Params
- Numeric RetracePct(2);
- Numeric StopLossSet(30);
- Vars
- NumericSeries SwingPrice;
- Numeric SwingHighPrice;
- Numeric SwingLowPrice;
- NumericSeries PreBar(0);
- NumericSeries UpDn(0);
- Bool SaveSwing(False);
- Bool NewTL(False);
- Bool UpdateTL(False);
- Numeric MinPoint;
- Numeric MyEntryPrice;
- Numeric myexitprice;
- begin
- If(CurrentBar == 0)
- SwingPrice = Close;
- SwingHighPrice = SwingHigh( 1, Close, 1,2);
- SwingLowPrice = SwingLow( 1, Close, 1, 2 );
- If (SwingHighPrice <> -1)
- {
- If(UpDn <=0 && SwingHighPrice >= SwingPrice * (1+RetracePct*0.01))
- {
- UpDn = 1;
- NewTL = True;
- SaveSwing = True;
- }Else If(UpDn == 1 && SwingHighPrice >= SwingPrice)
- {
- UpdateTL = True;
- SaveSwing = True;
- }
- If(SaveSwing)
- {
- SwingPrice = SwingHighPrice;
- PreBar = CurrentBar;
- }
- }Else If(SwingLowPrice <> -1)
- {
- If(UpDn >=0 && SwingLowPrice <= SwingPrice * (1-RetracePct*0.01))
- {
- UpDn = -1;
- NewTL = True;
- SaveSwing = True;
- }Else If(UpDn == -1 && SwingLowPrice <= SwingPrice)
- {
- UpdateTL = True;
- SaveSwing = True;
- }
- If(SaveSwing )
- {
- SwingPrice = SwingLowPrice;
- PreBar = CurrentBar;
- }
- }
- If( NewTL)
- {
- PlotNumeric("ZigZag",SwingPrice,0,-1,1);
- }Else If(UpdateTL)
- {
- If (UpDn == UpDn[1])
- {
- Unplot("ZigZag",PreBar - PreBar[1]+1);
- PlotNumeric("ZigZag",SwingPrice,0,-1,1);
- }Else
- {
- PlotNumeric("ZigZag",SwingPrice,0,-1,1);
- }
- }
- If(MarketPosition <> 1 And SwingPrice[2] < SwingPrice[1] And SwingLowPrice <> -1)
- {
- Buy(1,Open);
- }
- If(MarketPosition <> -1 And SwingPrice[2] > SwingPrice[1] And SwingHighPrice <> -1 )
- {
- SellShort(1,Open);
- }
- MinPoint = MinMove*PriceScale;
- MyEntryPrice = AvgEntryPrice;
- if( MarketPosition ==1 And Low <= MyEntryPrice - StopLossSet*MinPoint)//可以在这里写上初始的止损处理//
- {
- MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
- Sell(0,MyExitPrice);
- }
- If( MarketPosition == -1 And High >= MyEntryPrice + StopLossSet*MinPoint)//可以在这里写上初始的止损处理//
- {
- MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
- BuyToCover(0,MyExitPrice);
- }
- End
复制代码
这个可能是最接近画浪的了,也是依据这转折交易的,还记得第一次看缠论的时候,那羡慕的能画出这么好的理论线来,而且还是从小周期向大周期过渡,反正我自己画了半天,也没能画出像缠论那样的线来,最后只能放弃了,这个ZigZag指标是我挺满意的一个程序化交易系统了。我也不再去追求那缠论是如何了,对这个ZigZag指标仔细统计分析,我了解了它的优缺点,也足够了。 |
|