求助个移动止损的策略
自己找豆包编写的策略老是出错,求助大神!!!!!!!!!!!!
自己找豆包编写的策略老是出错,求助大神!!!!!!!!!!!!
移动止损策略有很多,你要哪种?
回复:比如做多开仓后以上根K线最低点减一跳设置止损,如果当根K线走完没止损,则以当根K线最低点减一跳作为止损点,以此类推。
回复:var1 = low[1] - 1; If(MarketPosition > 0 And BarsSinceEntry > 0) { If(Low < var1) { Sell(0,var1); } }
回复:谢谢 我试下
回复://==================== 无持仓:信号K走完,收盘价开仓 ==================== If(MarketPosition == 0) { ReachOneToOne = false; If(Cond_Long) { Buy(1, Close); EntryPrice = Close; InitStopTmp = Low - MinPoint; Numeric riskStop = EntryPrice * (1 - MaxRiskPct / 100.0); TrailLine = Max(InitStopTmp, riskStop); StopRange = EntryPrice - InitStopTmp; } Else If(Cond_Short) { SellShort(1, Close); EntryPrice = Close; InitStopTmp = High + MinPoint; Numeric riskStop = EntryPrice * (1 + MaxRiskPct / 100.0); TrailLine = Min(InitStopTmp, riskStop); StopRange = InitStopTmp - EntryPrice; } } Else If(MarketPosition == 1) // 多头持仓 { Numeric riskStop = EntryPrice * (1 - MaxRiskPct / 100.0); // 全程更新移动止损,只向上移动 Numeric newTrail = Low - MinPoint; If(newTrail > TrailLine) { TrailLine = newTrail; } TrailLine = Max(TrailLine, riskStop); // 判断是否到达1:1盈亏 If(ReachOneToOne == false && High >= EntryPrice + StopRange) { ReachOneToOne = true; } // 离场条件:保护性止损触发 或者 1:1后反向一跳止盈 Bool ExitProtect = Low <= TrailLine; Bool ExitProfit = ReachOneToOne && (High - Low >= MinPoint); If(ExitProtect || ExitProfit) { Sell(0, Close); EntryPrice = InvalidNumeric; InitStopTmp = InvalidNumeric; TrailLine = InvalidNumeric; StopRange = InvalidNumeric; ReachOneToOne = false; } } Else If(MarketPosition == -1) // 空头持仓 { Numeric riskStop = EntryPrice * (1 + MaxRiskPct / 100.0); // 全程更新移动止损,只向下移动 Numeric newTrail = High + MinPoint; If(newTrail < TrailLine) { TrailLine = newTrail; } TrailLine = Min(TrailLine, riskStop); // 判断是否到达1:1盈亏 If(ReachOneToOne == false && Low <= EntryPrice - StopRange) { ReachOneToOne = true; } // 离场条件:保护性止损触发 或者 1:1后反向一跳止盈 Bool ExitProtect = High >= TrailLine; Bool ExitProfit = ReachOneToOne && (High - Low >= MinPoint); If(ExitProtect || ExitProfit) { BuyToCover(0, Close); EntryPrice = InvalidNumeric; InitStopTmp = InvalidNumeric; TrailLine = InvalidNumeric; StopRange = InvalidNumeric; ReachOneToOne = false; } } Commentary("开仓价:" + Text(EntryPrice) + " 跟踪止损:" + Text(TrailLine) + " 到达1:1:" + IIFString(ReachOneToOne,"是","否")); } //------------------------------------------------------------------------这是我编写的,但是不能移动止损,盘中也不触发止损。能帮忙看看吗?
回复://==================== 无持仓:信号K走完,收盘价开仓 ==================== If(MarketPosition == 0) { ReachOneToOne = false; If(Cond_Long) { Buy(1, Close); EntryPrice = Close; InitStopTmp = Low - MinPoint; Numeric riskStop = EntryPrice * (1 - MaxRiskPct / 100.0); TrailLine = Max(InitStopTmp, riskStop); StopRange = EntryPrice - InitStopTmp; } Else If(Cond_Short) { SellShort(1, Close); EntryPrice = Close; InitStopTmp = High + MinPoint; Numeric riskStop = EntryPrice * (1 + MaxRiskPct / 100.0); TrailLine = Min(InitStopTmp, riskStop); StopRange = InitStopTmp - EntryPrice; } } Else If(MarketPosition == 1) // 多头持仓 { Numeric riskStop = EntryPrice * (1 - MaxRiskPct / 100.0); // 全程更新移动止损,只向上移动 Numeric newTrail = Low - MinPoint; If(newTrail > TrailLine) { TrailLine = newTrail; } TrailLine = Max(TrailLine, riskStop); // 判断是否到达1:1盈亏 If(ReachOneToOne == false && High >= EntryPrice + StopRange) { ReachOneToOne = true; } // 离场条件:保护性止损触发 或者 1:1后反向一跳止盈 Bool ExitProtect = Low <= TrailLine; Bool ExitProfit = ReachOneToOne && (High - Low >= MinPoint); If(ExitProtect || ExitProfit) { Sell(0, Close); EntryPrice = InvalidNumeric; InitStopTmp = InvalidNumeric; TrailLine = InvalidNumeric; StopRange = InvalidNumeric; ReachOneToOne = false; } } Else If(MarketPosition == -1) // 空头持仓 { Numeric riskStop = EntryPrice * (1 + MaxRiskPct / 100.0); // 全程更新移动止损,只向下移动 Numeric newTrail = High + MinPoint; If(newTrail < TrailLine) { TrailLine = newTrail; } TrailLine = Min(TrailLine, riskStop); // 判断是否到达1:1盈亏 If(ReachOneToOne == false && Low <= EntryPrice - StopRange) { ReachOneToOne = true; } // 离场条件:保护性止损触发 或者 1:1后反向一跳止盈 Bool ExitProtect = High >= TrailLine; Bool ExitProfit = ReachOneToOne && (High - Low >= MinPoint); If(ExitProtect || ExitProfit) { BuyToCover(0, Close); EntryPrice = InvalidNumeric; InitStopTmp = InvalidNumeric; TrailLine = InvalidNumeric; StopRange = InvalidNumeric; ReachOneToOne = false; } } Commentary("开仓价:" + Text(EntryPrice) + " 跟踪止损:" + Text(TrailLine) + " 到达1:1:" + IIFString(ReachOneToOne,"是","否")); } //------------------------------------------------------------------------这是我编写的,但是不能移动止损,盘中也不触发止损。能帮忙看看吗?