双均线策略做多做空合并及拆分问题
双均线策略,做多做空合并为一个策略,跟拆分为两个时,同样的代码,开平点为怎么有差别,该怎么解决?
双均线策略,做多做空合并为一个策略,跟拆分为两个时,同样的代码,开平点为怎么有差别,该怎么解决?
MarketPosition BarsSinceEntry 放一起么,系统变量很多都是公用的咯更不要说开平逻辑的问题了,比如开空自动会平多 (互斥)
回复:我mp用的是不等于1或-1控制的,应该不会有干扰下。这种情况怎么解决,是多空分开,开两个“”交易“”,分别执行吗?,这样不会干扰了吧,还有别的办法吗?如果要放在一起,做个多空双向的策略,怎么调整?
做多做空合并://------------------------------------------------------------------------------------------------------------ // 简称: LS_DualMoving// 入场: 1、以5、10周期均线金叉为入场点,点位为逆解点值和开盘价的较大的点位;// 2、如果前一根K线盘中死叉,但收盘未死叉,出现假死叉,则开盘补回仓位;// 3、如果前一根K线均线空头排列,当根K线成交量大于5周期均量,且价格向上突破前一根K线10周期均线价格时,盘中开仓。// 出场: 1、以近20周期最低点*0.998为止损;// 2、如果死叉点小于等于开仓点位*1.002,需5、10周期均量线金叉,可平仓;// 3、如果死叉点大于开仓点位*1.002,平仓;// 4、如果出现前一根K线盘中金叉、收盘未金叉,开盘平仓。// 5、如果前一根K线均线多头排列,当根K线成交量大于5周期均量,且价格向下突破前一根K线10周期均线价格时,盘中平仓。// 该模型适用于60分钟以下级别。//-------------------------------------------------------------------------------------------------------------- Params Numeric EFast(5); //短均线周期参数 Numeric ESlow(10); //长均线周期参数 Numeric StopLength(20); //止损统计周期数 Numeric PostionLots(1);//头寸 Vars Series<Numeric> MAEFast; //短均线 Series<Numeric> MAESlow; //长均线 Series<Numeric> MAVOLEFast; //短均量 Series<Numeric> MAVOLESlow; //长均量 Series<Numeric> Opint1; // 逆解交叉点值 Series<Numeric> AvgTR; Series<Numeric> PreProtectStopPrice_L; //保护性止损价初值 Series<Numeric> ProtectStopPrice_L; //保护性止损价 Series<Numeric> PreTrailStopPrice_L; //跟踪性止损价初值 Series<Numeric> TrailStopPrice_L; //跟踪性止损价 Series<Numeric> PreMyEntryPrice_L; // 开仓价格初赋值 Series<Numeric> MyEntryPrice_L; // 开仓价格 Series<Numeric> PreProtectStopPrice_S; //保护性止损价初值 Series<Numeric> ProtectStopPrice_S; //保护性止损价 Series<Numeric> PreTrailStopPrice_S; //跟踪性止损价初值 Series<Numeric> TrailStopPrice_S; //跟踪性止损价 Series<Numeric> PreMyEntryPrice_S; // 开仓价格初赋值 Series<Numeric> MyEntryPrice_S; // 开仓价格 Series<Bool> IsPriceLimit; //涨跌停判断,保证涨跌停板不作操作 Events OnBar(ArrayRef<Integer> indexs) { MAEFast = Average(Close, EFast); //短均线 MAESlow = Average(Close, ESlow); //长均线 MAVOLEFast = Average(Vol,EFast); //短均量 MAVOLESlow = Average(Vol,ESlow);//长均量 Opint1 = ((ESlow - 1) * Average(Close[1], ESlow - 1) * EFast - (EFast - 1) * Average(Close[1], EFast - 1) * ESlow) / (ESlow - EFast); //逆解交叉点值 PreProtectStopPrice_L = Lowest(Low[1],StopLength); PreMyEntryPrice_L = Max(Open,opint1); PreProtectStopPrice_S= Highest(High[1],StopLength); TrailStopPrice_S = Highest(High[1],StopLength) * 1.002; PreMyEntryPrice_S = Min(Open,opint1); IsPriceLimit = (High[1] == Low[1]) Or (High[2] == Low[2]); Range[0:DataSourceSize() - 1] { PlotNumeric("MAEFast", MAEFast); PlotNumeric("MAESlow", MAESlow); } If(MarketPosition <> 1 and MAEFast[1]<MAESlow[1] and High >= Opint1 And !IsPriceLimit) //金叉 { Buy(PostionLots, Max(Open, Opint1)); //金叉开多单 ProtectStopPrice_L = PreProtectStopPrice_L; MyEntryPrice_L = PreMyEntryPrice_L; } If(MarketPosition <> 1 And Low[1] <= Opint1[1] And Close[1] >= Opint1[1] And High >= Opint1 And !IsPriceLimit) //过滤假死叉(考虑收盘价最低的情况) { Buy(PostionLots, Max(Open, Opint1)); ProtectStopPrice_L = PreProtectStopPrice_L; MyEntryPrice_L = PreMyEntryPrice_L; } If(MarketPosition == 1 And BarsSinceEntry > 0 And !IsPriceLimit) { If(Low <= ProtectStopPrice_L) { Sell(PostionLots, ProtectStopPrice_L); //止损 PlotString("损","损",Low,Red); } If(Low > ProtectStopPrice_L And MAEFast[1] > MAESlow[1] And Low < Opint1) //死叉 { If(Opint1 <= MyEntryPrice_L * 1.002 And MAVOLEFast > MAVOLESlow) { Sell(PostionLots, Min(Open, Opint1)); PlotString("平1","平1",Low,Red); } If(Opint1 > MyEntryPrice_L * 1.002) { Sell(PostionLots, Min(Open, Opint1)); PlotString("平2","平2",Low,Red); } } If(Opint1 >= MyEntryPrice_L * 1.0002 and High[1] >= Opint1[1] And Close[1] < Opint1[1] And Low <= Opint1 And MAVOLEFast > MAVOLESlow ) //过滤假金叉 { Sell(PostionLots, Min(Open, opint1)); PlotString("假金","假金",Low,Red); } } If(MarketPosition <> -1 and MAEFast[1]>MAESlow[1] and Low <= Opint1 And !IsPriceLimit) //死叉 { SellShort(PostionLots, Min(Open, Opint1)); //死叉开空单 ProtectStopPrice_S = PreProtectStopPrice_S; MyEntryPrice_S = PreMyEntryPrice_S; } If(MarketPosition <> -1 And High[1] >= Opint1[1] And Close[1] <= Opint1[1] And Low <= Opint1 And !IsPriceLimit) //过滤假金叉(考虑收盘价最低的情况) { SellShort(PostionLots, Min(Open, Opint1)); ProtectStopPrice_S = PreProtectStopPrice_S; MyEntryPrice_S = PreMyEntryPrice_S; PlotString("L2","L2",High,Red); } If(MarketPosition == -1 And BarsSinceEntry > 0 And !IsPriceLimit) { If(High >= ProtectStopPrice_S) { BuyToCover(PostionLots, ProtectStopPrice_S); //止损 PlotString("损","损",Low,Red); } If(High < ProtectStopPrice_S And MAEFast[1] < MAESlow[1] And High > Opint1) //金叉 { If(Opint1 >= MyEntryPrice_S * 0.998 And MAVOLEFast > MAVOLESlow) { Buytocover(PostionLots, Max(Open, Opint1)); PlotString("x","x",High,Blue); } If(Opint1 < MyEntryPrice_S * 0.998) { Buytocover(PostionLots, Max(Open, Opint1)); } } If(Opint1 < MyEntryPrice_S * 0.998 and Low[1] <= Opint1[1] And Close[1] > Opint1[1] And High >= Opint1 And MAVOLEFast > MAVOLESlow) //过滤假死叉 { Buytocover(PostionLots, Max(Open, opint1)); } } } //------------------------------------------------------------------------// 编译版本 2025/3/28 202727// 版权所有 winter110// 更改声明 TradeBlazer Software保留对TradeBlazer平台
回复:仅做多://------------------------------------------------------------------------------------------------------------ // 简称: L_DualMoveing // 入场: 1、以5、10周期均线金叉为入场点,点位为逆解点值和开盘价的较大的点位; // 2、如果前一根K线盘中死叉,但收盘未死叉,出现假死叉,则开盘补回仓位; // 3、如果前一根K线均线空头排列,当根K线成交量大于5周期均量,且价格向上突破前一根K线10周期均线价格时,盘中开仓。 // 出场: 1、以近20周期最低点*0.998为止损; // 2、如果死叉点小于等于开仓点位*1.002,需5、10周期均量线金叉,可平仓; // 3、如果死叉点大于开仓点位*1.002,平仓; // 4、如果出现前一根K线盘中金叉、收盘未金叉,开盘平仓。 // 5、如果前一根K线均线多头排列,当根K线成交量大于5周期均量,且价格向下突破前一根K线10周期均线价格时,盘中平仓。 // 该模型适用于60分钟以下级别。 //-------------------------------------------------------------------------------------------------------------- Params Numeric EFast(5); //短均线周期参数 Numeric ESlow(10); //长均线周期参数 Numeric StopLength(20); //止损统计周期数 Numeric PostionLots(1);//头寸 Vars Series<Numeric> MAEFast; //短均线 Series<Numeric> MAESlow; //长均线 Series<Numeric> MAVOLEFast; //短均量 Series<Numeric> MAVOLESlow; //长均量 Series<Numeric> Opint1; // 逆解交叉点值 Series<Numeric> AvgTR; Series<Numeric> PreProtectStopPrice_L; //保护性止损价初值 Series<Numeric> ProtectStopPrice_L; //保护性止损价 Series<Numeric> PreTrailStopPrice_L; //跟踪性止损价初值 Series<Numeric> TrailStopPrice_L; //跟踪性止损价 Series<Numeric> PreMyEntryPrice_L; // 开仓价格初赋值 Series<Numeric> MyEntryPrice_L; // 开仓价格 Series<Bool> IsPriceLimit; //涨跌停判断,保证涨跌停板不作操作 Events OnBar(ArrayRef<Integer> indexs) { MAEFast = Average(Close, EFast); //短均线 MAESlow = Average(Close, ESlow); //长均线 MAVOLEFast = Average(Vol,EFast); //短均量 MAVOLESlow = Average(Vol,ESlow);//长均量 Opint1 = ((ESlow - 1) * Average(Close[1], ESlow - 1) * EFast - (EFast - 1) * Average(Close[1], EFast - 1) * ESlow) / (ESlow - EFast); //逆解交叉点值 PreProtectStopPrice_L = Lowest(Low[1],StopLength); PreMyEntryPrice_L = Max(Open,opint1); IsPriceLimit = (High[1] == Low[1]) Or (High[2] == Low[2]); Range[0:DataSourceSize() - 1] { PlotNumeric("MAEFast", MAEFast); PlotNumeric("MAESlow", MAESlow); } If(MarketPosition <> 1 and MAEFast[1]<MAESlow[1] and High >= Opint1 And !IsPriceLimit) //金叉 { Buy(PostionLots, Max(Open, Opint1)); //金叉开多单 ProtectStopPrice_L = PreProtectStopPrice_L; MyEntryPrice_L = PreMyEntryPrice_L; } If(MarketPosition <> 1 And Low[1] <= Opint1[1] And Close[1] >= Opint1[1] And High >= Opint1 And !IsPriceLimit) //过滤假死叉(考虑收盘价最低的情况) { Buy(PostionLots, Max(Open, Opint1)); ProtectStopPrice_L = PreProtectStopPrice_L; MyEntryPrice_L = PreMyEntryPrice_L; } If(MarketPosition == 1 And BarsSinceEntry > 0 And !IsPriceLimit) { If(Low <= ProtectStopPrice_L) { Sell(PostionLots, ProtectStopPrice_L); //止损 PlotString("损","损",Low,Red); } If(Low > ProtectStopPrice_L And MAEFast[1] > MAESlow[1] And Low < Opint1) //死叉 { If(Opint1 <= MyEntryPrice_L * 1.002 And MAVOLEFast > MAVOLESlow) { Sell(PostionLots, Min(Open, Opint1)); PlotString("平1","平1",Low,Red); } If(Opint1 > MyEntryPrice_L * 1.002) { Sell(PostionLots, Min(Open, Opint1)); PlotString("平2","平2",Low,Red); } } If(Opint1 >= MyEntryPrice_L * 1.0002 and High[1] >= Opint1[1] And Close[1] < Opint1[1] And Low <= Opint1 And MAVOLEFast > MAVOLESlow ) //过滤假金叉 { Sell(PostionLots, Min(Open, opint1)); PlotString("假金","假金",Low,Red); } } } //------------------------------------------------------------------------ // 编译版本 2025/3/28 202727 // 版权所有 winter110 // 更改声明 TradeBlazer Software保留对TradeBlazer平台