设为首页收藏本站

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

求助:模式交易只能开仓,不能平仓是什么问题? [复制链接]

Rank: 1

精华
0
UID
292927
积分
4
帖子
3
主题
1
阅读权限
10
注册时间
2020-6-13
最后登录
2020-7-19
跳转到指定楼层
1#
发表于 2020-7-2 22:43:05 |只看该作者 |倒序浏览
求助:模式交易只能开仓,不能平仓是什么问题?  自编的模式    开多开空都可以   平仓没有反应,这是为什么?

Rank: 10Rank: 10Rank: 10

精华
0
UID
20842
积分
931
帖子
382
主题
2
阅读权限
255
注册时间
2010-12-3
最后登录
2022-2-15
2#
发表于 2020-7-2 23:17:59 |只看该作者
这个没代码,我只能瞎猜,估计是平仓没有先虚拟开仓。建议您参考一下我们系统内置的平仓模式是怎么生成的

使用道具 举报

Rank: 1

精华
0
UID
292927
积分
4
帖子
3
主题
1
阅读权限
10
注册时间
2020-6-13
最后登录
2020-7-19
3#
发表于 2020-7-9 16:00:44 |只看该作者
追涨杀跌 发表于 2020-7-2 23:17
这个没代码,我只能瞎猜,估计是平仓没有先虚拟开仓。建议您参考一下我们系统内置的平仓模式是怎么生成的 ...

//------------------------------------------------------------------------
// 简称: KDPB
// 名称: KD平多
// 类型: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------

Params
        Numeric pTradeVolume(1);  //下单数量_按数量
        Integer signalBeginBar(30);  //信号起始Bar数
        Bool isRollover(False);//是否后复权
        Bool isRolloverRealPrice(False);//是否映射真实价格
        Bool isAutoSwapPosition(False);//是否自动换仓
        Bool ignoreSwapSiganlCalc(False); //是否忽略换仓信号计算
Vars
        Bool bVarCondition_sell_1;
        Series<Numeric> sVarCondition_sell_1_left(0,2);
        Series<Numeric> sVarCondition_sell_1_right(0,2);
        Series<Integer> sVarCondition_sell_upOrDown1(0,2);
        Bool bVarCondition_sell_2;
        Series<Numeric> sVarCondition_sell_2(0,2);
        Integer iVarSignal_Flag_Sell_1(0);
        Numeric dVarPrice_sell_1;
        Numeric dVarPrice_sell_1_volume;
Defs
        Numeric Cond_Open(Integer barback = 0)
        {
                if(Frequency == "tick")
                {
                        return Close[barback];
                }
                return Open[barback];
        }
        Integer Cond_round_volume(Numeric volume, Numeric price = 0)
        {
                Return IntPart(Round(volume / BaseShares(), 0))*BaseShares();
        }
        Bool Cond_LocalTimeLimit(Numeric bTime, Numeric eTime)
        {
                If(MakeDateTime(Date(),Time()) >= bTime And MakeDateTime(Date(),Time()) <= eTime)
                {
                        Return True;
                }
                Return False;
        }
        Bool sell_condition_1()
        {
                sVarCondition_sell_1_left = GetPlotNumericValue("KDJ","K");
                If(InvalidNumeric() == sVarCondition_sell_1_left[1])
                {
                        Return False;
                }
                sVarCondition_sell_1_right = GetPlotNumericValue("KDJ","D");
                If(InvalidNumeric() == sVarCondition_sell_1_right[1])
                {
                        Return False;
                }
                If(sVarCondition_sell_1_left[1]>sVarCondition_sell_1_right[1])
                {
                        sVarCondition_sell_upOrDown1 = 1;
                }
                Else If(sVarCondition_sell_1_left[1]<sVarCondition_sell_1_right[1])
                {
                        sVarCondition_sell_upOrDown1 = -1;
                }
                Else
                {
                        sVarCondition_sell_upOrDown1 = sVarCondition_sell_upOrDown1[1];
                }
                Return sVarCondition_sell_upOrDown1[1] == 1 && sVarCondition_sell_upOrDown1[0] == -1;
        }
        Bool sell_condition_2()
        {
                sVarCondition_sell_2 = GetPlotNumericValue("KDJ","D");
                If(InvalidNumeric() == sVarCondition_sell_2[1])
                {
                        Return False;
                }
                Return sVarCondition_sell_2[1] > 50.000000;
        }
        Bool time_condition_Sell_1()
        {
                Return Cond_LocalTimeLimit(0, 20200803.220907);
        }
Events
        OnInit()
        {
                SetConsecEntries(3);
                SetBeginBarMaxCount(signalBeginBar);
                Range[0ataCount()-1]
                {
                        If(isRollover)
                        {
                                AddDataFlag(Enum_Data_RolloverBackWard());
                        }
                        If(isRolloverRealPrice)
                        {
                                AddDataFlag(Enum_Data_RolloverRealPrice());
                        }
                        If(isAutoSwapPosition)
                        {
                                AddDataFlag(Enum_Data_AutoSwapPosition());
                        }
                        If(ignoreSwapSiganlCalc)
                        {
                                AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());
                        }
                }
        }

        OnBar(ArrayRef<Integer> indexs)
        {
                Range[0ataCount()-1]
                {
                        bVarCondition_sell_1 = sell_condition_1();
                        bVarCondition_sell_2 = sell_condition_2();
                        dVarPrice_sell_1 = Cond_Open();
                        dVarPrice_sell_1_volume = Cond_round_volume(pTradeVolume,dVarPrice_sell_1);
                        if(time_condition_Sell_1() and (bVarCondition_sell_1 and bVarCondition_sell_2))
                        {
                                Sell(dVarPrice_sell_1_volume,dVarPrice_sell_1,iVarSignal_Flag_Sell_1);
                        }
                       
                }
        }

//------------------------------------------------------------------------
// 编译版本:        2020/07/03 221002
// 版权所有        zzy2020
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                         每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
0
UID
20842
积分
931
帖子
382
主题
2
阅读权限
255
注册时间
2010-12-3
最后登录
2022-2-15
4#
发表于 2020-7-9 18:03:59 |只看该作者
zzy2020 发表于 2020-7-9 16:00
//------------------------------------------------------------------------
// 简称: KDPB
// 名称:  ...

从代码里,可以看到只有Sell,没有开仓的Buy指令。所以要加上虚拟开仓

使用道具 举报

Rank: 1

精华
0
UID
292927
积分
4
帖子
3
主题
1
阅读权限
10
注册时间
2020-6-13
最后登录
2020-7-19
5#
发表于 2020-7-15 15:38:36 |只看该作者
追涨杀跌 发表于 2020-7-9 18:03
从代码里,可以看到只有Sell,没有开仓的Buy指令。所以要加上虚拟开仓

非常感谢,问题已经解决。      新问题是  :非交易时间,委托被拒绝,    这个如何解决呢?[img][/img]

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
0
UID
20842
积分
931
帖子
382
主题
2
阅读权限
255
注册时间
2010-12-3
最后登录
2022-2-15
6#
发表于 2020-7-15 22:23:52 |只看该作者
zzy2020 发表于 2020-7-15 15:38
非常感谢,问题已经解决。      新问题是  :非交易时间,委托被拒绝,    这个如何解决呢?[/img] ...

非交易时间,委托被拒绝,没啥问题啊

使用道具 举报

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

bottom

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

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

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部