求助:模式交易只能开仓,不能平仓是什么问题?
求助:模式交易只能开仓,不能平仓是什么问题? 自编的模式 开多开空都可以 平仓没有反应,这是为什么? 这个没代码,我只能瞎猜,估计是平仓没有先虚拟开仓。建议您参考一下我们系统内置的平仓模式是怎么生成的 追涨杀跌 发表于 2020-7-2 23:17 static/image/common/back.gif这个没代码,我只能瞎猜,估计是平仓没有先虚拟开仓。建议您参考一下我们系统内置的平仓模式是怎么生成的 ...
//------------------------------------------------------------------------
// 简称: 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;
}
return Open;
}
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)
{
Return False;
}
sVarCondition_sell_1_right = GetPlotNumericValue("KDJ","D");
If(InvalidNumeric() == sVarCondition_sell_1_right)
{
Return False;
}
If(sVarCondition_sell_1_left>sVarCondition_sell_1_right)
{
sVarCondition_sell_upOrDown1 = 1;
}
Else If(sVarCondition_sell_1_left<sVarCondition_sell_1_right)
{
sVarCondition_sell_upOrDown1 = -1;
}
Else
{
sVarCondition_sell_upOrDown1 = sVarCondition_sell_upOrDown1;
}
Return sVarCondition_sell_upOrDown1 == 1 && sVarCondition_sell_upOrDown1 == -1;
}
Bool sell_condition_2()
{
sVarCondition_sell_2 = GetPlotNumericValue("KDJ","D");
If(InvalidNumeric() == sVarCondition_sell_2)
{
Return False;
}
Return sVarCondition_sell_2 > 50.000000;
}
Bool time_condition_Sell_1()
{
Return Cond_LocalTimeLimit(0, 20200803.220907);
}
Events
OnInit()
{
SetConsecEntries(3);
SetBeginBarMaxCount(signalBeginBar);
Range
{
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
{
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公式修改和重写的权利
//------------------------------------------------------------------------
zzy2020 发表于 2020-7-9 16:00 static/image/common/back.gif
//------------------------------------------------------------------------
// 简称: KDPB
// 名称: ...
从代码里,可以看到只有Sell,没有开仓的Buy指令。所以要加上虚拟开仓 追涨杀跌 发表于 2020-7-9 18:03 static/image/common/back.gif
从代码里,可以看到只有Sell,没有开仓的Buy指令。所以要加上虚拟开仓
非常感谢,问题已经解决。 新问题是 :非交易时间,委托被拒绝, 这个如何解决呢? zzy2020 发表于 2020-7-15 15:38 static/image/common/back.gif
非常感谢,问题已经解决。 新问题是 :非交易时间,委托被拒绝, 这个如何解决呢? ...
非交易时间,委托被拒绝,没啥问题啊
页:
[1]