本策略是一个基于简单移动平均线的跨均线反转策略。它会使用长度为1和长度为5的简单移动平均线,当短周期移动平均线从下方上穿长周期移动平均线时做多,当从上方下穿时做空,属于典型的趋势跟踪策略。
本策略通过计算close价格的1日简单移动平均线sma1和5日简单移动平均线sma5,在sma1上穿sma5时做多入场,在sma1下穿sma5时做空入场。做多后设置止损为入场价下方5美元,止盈为入场价上方150美元;做空后设置止损为入场价上方5美元,止盈为入场价下方150美元。
优化方向:
本策略作为一个简单的双均线策略,具有操作简单、易于实现的特点,可以快速验证策略想法。但其承受能力和获利空间都比较有限,需要对参数和过滤条件进行优化,使之适应更多市场环境。作为初学者的第一份量化策略,它包含了基本的组成要素,可作为简单的框架进行 iterable 改进。
/*backtest start: 2023-02-19 00:00:00 end: 2024-02-19 00:00:00 period: 2d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Valeria 181 Bot Strategy Mejorado 2.21", overlay=true, margin_long=100, margin_short=100) var float lastLongOrderPrice = na var float lastShortOrderPrice = na longCondition = ta.crossover(ta.sma(close, 1), ta.sma(close, 5)) if (longCondition) strategy.entry("Long Entry", strategy.long) // Enter long shortCondition = ta.crossunder(ta.sma(close, 1), ta.sma(close, 5)) if (shortCondition) strategy.entry("Short Entry", strategy.short) // Enter short if (longCondition) lastLongOrderPrice := close if (shortCondition) lastShortOrderPrice := close // Calculate stop loss and take profit based on the last executed order's price stopLossLong = lastLongOrderPrice - 5 // 10 USDT lower than the last long order price takeProfitLong = lastLongOrderPrice + 151 // 100 USDT higher than the last long order price stopLossShort = lastShortOrderPrice + 5 // 10 USDT higher than the last short order price takeProfitShort = lastShortOrderPrice - 150 // 100 USDT lower than the last short order price // Apply stop loss and take profit to long positions strategy.exit("Long Exit", from_entry="Long Entry", stop=stopLossLong, limit=takeProfitLong) // Apply stop loss and take profit to short positions strategy.exit("Short Exit", from_entry="Short Entry", stop=stopLossShort, limit=takeProfitShort)