老师请问一下
止损价=EntryPrice*(1-0.01) 图中k线是自动移仓换月 手数不同为什么会导致止损价格发生变化
这个恐怕是要分析你代码里的详细计算过程才知道了
老师我能发出来帮我看看吗
Params
//此处添加参数
Numeric Found(10000);//固定保证金
Numeric ZS(0.01);//止损比率
Numeric BB(10);//ATR倍数
Numeric FastLength(12);
Numeric SlowLength(26);
Numeric MACDLength(9);
Numeric ATRLength(14);
Vars
//此处添加变量
Numeric Lots;
Numeric ATR;
Series<Numeric> DIFF;
Series<Numeric> DEA;
Numeric flag;
Series<Bool> Uptrue;
Series<Bool> Downtrue;
Series<Numeric> Counts;
Series<Numeric> MyentryPrice;
Global Integer id(0);
Defs
//此处添加公式函数
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次
OnInit()
{
//=========除权换月相关设置==============
AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权
AddDataFlag(Enum_Data_RolloverRealPrice()); //设置映射真实价格
AddDataFlag(Enum_Data_AutoSwapPosition()); //设置自动换仓
AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //设置忽略换仓信号计算
AddDataFlag(Enum_Data_ActivePeriod ); //设置K线分割为有效交易时段
SetOrderMap2MainSymbol(); //设置委托映射到主力
id = SubscribeBar(ContinuousSymbol(), "1d", 20180101);
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
Lots = 20*Max(1,IntPart(Found/(O/rollover*ContractUnit*BigPointValue*0.1)));
ATR = Data[1].AvgTrueRange(ATRLength);
Commentary("ATR:"+Text(ATR));
Commentary("ATR止盈:"+Text(EntryPrice+ATR*BB));
Commentary("止损次数:"+Text(Counts));
Commentary("基准价:"+Text(MyentryPrice));
Commentary("止损价:"+Text(EntryPrice*(1-ZS)));
Commentary("Counts:"+Text(Counts));
If(MarketPosition==0 && CurrentBar==0)
{
Buy(Lots);
MyentryPrice = EntryPrice;
Counts=0;
Commentary("第一根K开仓");
}
If(MarketPosition==0 && Year != Year[1] )
{
Buy(Lots);
MyentryPrice = EntryPrice;
Counts=0;
Commentary("当前位置初次开仓");
}
If(MarketPosition==0 && Month==7 && Month[1]==6 )
{
Buy(Lots);
MyentryPrice = EntryPrice;
Counts=0;
Commentary("半年后初次开仓");
}
If(MarketPosition != 0 && Close<EntryPrice*(1-ZS))
{
Sell(0);//1%止损
Counts=Counts+1;
Commentary("当前位置1%止损");
}
If(MarketPosition == 0 && CrossOver(Close,MyentryPrice) && Counts>0 && Year==Year[1])
{
Buy(Lots);
Commentary("当前位置再次上穿");
}
If(MarketPosition != 0 && Close>EntryPrice+ATR*BB)
{
Sell(0);//ATR止盈
//Counts=0;
Commentary("当前ATR止盈");
}
Numeric sp1 = data[id].PreTradingDay((year+1)*10000+0101);
Numeric sp2 = data[id].PreTradingDay(year*10000+0701);
If(MarketPosition!=0 && (Date()==sp1 || Date()==sp2))
{
Sell(0);//止盈止损
Counts=0;
Commentary("当前半年止盈止损");
}
这个函数不要放在if语句中,可能会有序列函数问题。你说的不同手数导致止损点不同的,最好提供下应用场景,我不知道怎么复现你的问题