设为首页收藏本站

 找回密码
 注册
查看: 2483|回复: 1
打印 上一主题 下一主题

有点问题,老师改下。 [复制链接]

精华
0
UID
240347
积分
128
帖子
84
主题
10
阅读权限
0
注册时间
2016-9-13
最后登录
2023-8-14
跳转到指定楼层
1#
发表于 2016-10-10 09:04:37 |只看该作者 |倒序浏览
Params
        //此处添加参数
        Numeric Length(14);                        ////参照KDJ指标
        Numeric SlowLength(3);                ////参照KDJ指标
        Numeric SmoothLength(3);     ////参照KDJ指标
        Numeric MaxProfit(20);                  ////最大盈利
        Numeric MaxBack(10);                   ////最大盈利回撤
        Numeric StopLoss(10);                  /////止损
Vars
        //此处添加变量
        NumericSeries HighestValue;        ////参照KDJ指标                       
        NumericSeries LowestValue;        ////参照KDJ指标       
        NumericSeries KValue;                ////参照KDJ指标
        Numeric SumHLValue;                ////参照KDJ指标
        Numeric SumCLValue;                ////参照KDJ指标
        Numeric DValue;                                ////参照KDJ指标
        NumericSeries LossCount(0);                    //亏损次数
        Numeric MinPoint;                       // 最小变动单位
        Numeric shares(1) ;                     //开仓手数
        NumericSeries openPrice(0);
        NumericSeries StopPrice1(0);           //止损价
        NumericSeries MyPrice(0);
        NumericSeries HighSinceEntry(0);
        NumericSeries LowSinceEntry(0);
        NumericSeries MaxN(0);
        Numeric N;
        NumericSeries Lcount(0);              //多头次数
        NumericSeries Scount(0);                          //空头次数

        BoolSeries condition11;
        BoolSeries condition21;

Begin
        //////begin KD计算公式,参照KDJ指标
        HighestValue = HighestFC(High, Length);
        LowestValue = LowestFC(Low, Length);
        SumHLValue = SummationFC(HighestValue-LowestValue,SlowLength);
        SumCLValue = SummationFC(Close - LowestValue,SlowLength);
        If(SumHLValue <> 0)
        {
                KValue = SumCLValue/SumHLValue*100;
        }Else
        {
                KValue = 0;
        }
        DValue = AverageFC(KValue,SmoothLength);
/*        PlotNumeric("K",KValue);
        PlotNumeric("D",DValue);*/
        //PlotNumeric("J",3*KValue - 2*DValue);
       
        //////End KD计算公式,参照KDJ指标       
        If(CurrentBar <= Length) Return;
               
        MinPoint = MinMove*PriceScale;
        shares = LossCount + 1 ;   ////开仓手数
        condition11 =   CrossOver(KValue,DValue) ;
        condition21 =   CrossUnder(KValue,DValue) ;
       
        /////////多头开仓
        If(MarketPosition <> 1 && condition11 && Lcount==0 )
        {
                Buy(shares,Close);
                Lcount =1;
                Scount = 0;
                MaxN = 0;
                HighSinceEntry = EntryPrice;
                openPrice = EntryPrice;
        }
       
        /////////多头平仓
        If(MarketPosition == 1 && BarsSinceEntry >=1 )
        {        ////////止损部分
                StopPrice1 = openPrice - StopLoss * MinPoint ;  /////止损价
                MyPrice = dealprice2(12,Open,High,Low,StopPrice1,MinPoint,0);  ////对价格进行特殊处理的函数
                Commentary("MyPrice444="+Text(MyPrice));
                If( MyPrice != 0 )
                {
                        Sell(0,MyPrice);
                        LossCount = LossCount + 1;
                }
               
                /////止盈部分
                If (High > HighSinceEntry ) HighSinceEntry = High;
                N = IntPart( (HighSinceEntry - openPrice) / (MaxProfit * MinPoint) );
                If(MaxN < N ) MaxN = N;
                If(MaxN > 0 )
                {
                        If(Low <= HighSinceEntry -MaxN * MaxBack * MinPoint )
                        {
                                Sell(0,HighSinceEntry -  MaxN * MaxBack * MinPoint );
                                LossCount = 0;
                        }
                }       
        }
       
        /////////空头开仓
        If(MarketPosition <> -1 && condition21 && Scount==0)
        {
                SellShort(shares,Close);
                Lcount = 0;
                Scount = 1;
                MaxN = 0;
                LowSinceEntry = EntryPrice;
                openPrice = EntryPrice;
        }
       
        /////////空头平仓
        If(MarketPosition == -1 && BarsSinceEntry >=1 )
        {
                StopPrice1 = openPrice + StopLoss * MinPoint ;  /////止损价
                MyPrice = dealprice2(22,Open,High,Low,StopPrice1,MinPoint,0);  ////对价格进行特殊处理的函数
                If(MyPrice != 0)
                {
                        BuyToCover(0,MyPrice);
                        LossCount = LossCount + 1;
                }
               
                /////止盈部分
                If (Low < LowSinceEntry ) LowSinceEntry = High;
                N = IntPart( (openPrice - LowSinceEntry ) / (MaxProfit * MinPoint) );
                If(MaxN < N ) MaxN = N;
                If(MaxN > 0 )
                {
                        If(High >= LowSinceEntry + MaxN * MaxBack * MinPoint )
                        {
                                BuyToCover(0,LowSinceEntry +  MaxN * MaxBack * MinPoint );
                                LossCount = 0;
                        }
                }       
        }
       
        Commentary("EntryPrice="+Text(EntryPrice));
        Commentary("MinPoint="+Text(MinPoint));
        Commentary("shares="+Text(shares));
        Commentary("HighSinceEntry="+Text(HighSinceEntry));
        Commentary("LowSinceEntry="+Text(LowSinceEntry));
        Commentary("StopPrice1="+Text(StopPrice1));
        Commentary("MaxN="+Text(MaxN));
        Commentary("openPrice="+Text(openPrice));
        Commentary("Lcount="+Text(Lcount));
        Commentary("Scount="+Text(Scount));
       
End
还有下边这个代码,也有点问题,老师帮我看下。
//------------------------------------------------------------------------
// 简称: dealprice2
// 名称: dealprice2
// 类别: 用户函数
// 类型: 用户函数
// 输出: Numeric
//------------------------------------------------------------------------
Params
        Numeric DType(11); //11多开 12 多平 21空开 22空平
        Numeric OpenPrice(0);
        Numeric HighPrice(0);
        Numeric LowPrice(0);
        Numeric NewPrice(0);
        Numeric MinPoint(0);
        Numeric LossPoint(0);   ////滑点
       
Vars
        //此处添加变量

Begin
    //此处添加代码正文
    If(DType == 11)
    {
                If(OpenPrice > NewPrice)
                {
                        Return OpenPrice + LossPoint*MinPoint;
                }Else If(High >=NewPrice)
                {
                        Return NewPrice;
                }Else
                     Return 0;
   
    }
   
    If(DType == 12)
    {
                If(Open < NewPrice)
                {
                        Return OpenPrice - LossPoint*MinPoint;
                }Else If(Low <= NewPrice)
                {
                        Return NewPrice;
                }Else
                        Return 0;
    }
   
     If(DType == 21)
     {
                If(Open < NewPrice)
                {
                        Return OpenPrice - LossPoint*MinPoint;               
                }Else If(Low <= NewPrice)
                {
                        Return NewPrice;
                }Else
                        Return 0;
     }
   
    If(DType == 22)
    {
                If(Open > NewPrice)
                {
                        Return Open + LossPoint*MinPoint;       
                }Else If(High > NewPrice)
                {
                        Return NewPrice;
                }Else
                        Return 0 ;  
    }
   
   
  
End



//------------------------------------------------------------------------
// 编译版本:        2016-09-13 170352
// 内核版本:        V2.1.2.8
// 版权所有        yaohoo
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                        每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------

Rank: 2

精华
0
UID
251604
积分
64
帖子
53
主题
3
阅读权限
30
注册时间
2017-5-23
最后登录
2021-3-31
2#
发表于 2017-7-11 16:29:17 |只看该作者
代码是没问题的,就是交易效果不好。dealprice2当用户函数加载,

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-4-20 06:01

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部