开拓者期货期权程序化系统交易论坛

标题: 求助:模式交易只能开仓,不能平仓是什么问题? [打印本页]

作者: zzy2020    时间: 2020-7-2 22:43:05     标题: 求助:模式交易只能开仓,不能平仓是什么问题?

求助:模式交易只能开仓,不能平仓是什么问题?  自编的模式    开多开空都可以   平仓没有反应,这是为什么?
作者: 追涨杀跌    时间: 2020-7-2 23:17:59

这个没代码,我只能瞎猜,估计是平仓没有先虚拟开仓。建议您参考一下我们系统内置的平仓模式是怎么生成的
作者: zzy2020    时间: 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公式修改和重写的权利
//------------------------------------------------------------------------

作者: 追涨杀跌    时间: 2020-7-9 18:03:59

zzy2020 发表于 2020-7-9 16:00
//------------------------------------------------------------------------
// 简称: KDPB
// 名称:  ...

从代码里,可以看到只有Sell,没有开仓的Buy指令。所以要加上虚拟开仓
作者: zzy2020    时间: 2020-7-15 15:38:36

追涨杀跌 发表于 2020-7-9 18:03
从代码里,可以看到只有Sell,没有开仓的Buy指令。所以要加上虚拟开仓

非常感谢,问题已经解决。      新问题是  :非交易时间,委托被拒绝,    这个如何解决呢?[img][/img]
作者: 追涨杀跌    时间: 2020-7-15 22:23:52

zzy2020 发表于 2020-7-15 15:38
非常感谢,问题已经解决。      新问题是  :非交易时间,委托被拒绝,    这个如何解决呢?[/img] ...

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




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2