策略咨询
以下策略全自动运行没有信号也没有执行,请老师帮我判断一下哪里出了问题并修改一下,谢谢。Params Numeric FastLength(12); // 快速移动平均线周期 Numeric SlowLength(26); // 慢速移动平均线周期 Numeric MACDSignalLength(9); // MACD 信号线周期Vars Numeric LAST; Numeric MACDValue; Numeric SignalLine; Numeric MACDDiff; Bool EnterLongCondition(False); Bool EnterShortCondition(False); Numeric MyEntryPrice; Numeric MyStopLoss; Numeric MyTakeProfit;Events OnReady() { Range[0:DataSourceSize() - 1] { MACDValue = XAverage(Close,FastLength)-XAverage(Close,SlowLength); SignalLine = XAverage(MACDValue,MACDSignalLength); MACDDiff = MACDValue - SignalLine; } { // 判断开仓条件 If (MACDValue > REF(MACDValue,1) And REF(MACDValue,1) < REF(MACDValue,2) ) { EnterLongCondition = True; } IF (MACDValue < REF(MACDValue,1) And REF(MACDValue,1) > REF(MACDValue,2) ) { EnterShortCondition = True; } // 开仓操作 If (MarketPosition == 0 And EnterLongCondition) { Buy(1,LAST); MyEntryPrice =LAST; MyStopLoss = MyEntryPrice - 10*MinMove; MyTakeProfit = 0; } Else If (MarketPosition == 0 And EnterShortCondition) { SellShort(1,LAST); MyEntryPrice = LAST; MyStopLoss = MyEntryPrice + 10*MinMove; MyTakeProfit = 0; } // 持仓不为零时的止损和止盈调整 If (MarketPosition!= 0) { If (MarketPosition == 1) { // 多头持仓 If (LAST>= MyEntryPrice + 30*MinMove) { MyStopLoss = MyEntryPrice + 20*MinMove; } Else If (LAST>= MyEntryPrice + 40*MinMove) { MyStopLoss = MyEntryPrice + 25*MinMove; } Else If (LAST>= MyEntryPrice + 50*MinMove) { MyStopLoss = MyEntryPrice + 30*MinMove; } Else If ((LAST- MyEntryPrice) >= ((IntPart((C- MyEntryPrice)/20)+1)*20*MinMove)) { MyStopLoss = MyEntryPrice + ((IntPart((C - MyEntryPrice)/20)+1)*20*MinMove); } If (LAST<= MyStopLoss) { Sell(1,MyStopLoss); } } Else If (MarketPosition == -1) { // 空头持仓 If (LAST<= MyEntryPrice - 30*MinMove) { MyStopLoss = MyEntryPrice - 20*MinMove; } Else If (LAST<= MyEntryPrice - 40*MinMove) { MyStopLoss = MyEntryPrice - 25*MinMove; } Else If (LAST<= MyEntryPrice - 50*MinMove) { MyStopLoss = MyEntryPrice - 30*MinMove; } Else If ((MyEntryPrice - LAST) >= ((IntPart((MyEntryPrice - LAST)/20)+1)*20*MinMove)) { MyStopLoss = MyEntryPrice - ((IntPart((MyEntryPrice - LAST)/20)+1)*20*MinMove); } If (LAST>= MyStopLoss) { BuyToCover(1,MyStopLoss); } } } } }2024-10-24 14:51