该策略是一个基于200日移动平均线和随机振子指标的趋势追踪策略。策略的主要思路是利用200日移动平均线来判断当前市场的长期趋势,同时使用随机振子指标来捕捉市场的短期波动和超买超卖信号。当价格位于200日移动平均线之下,且随机振子从超卖区域向上穿越20时,策略开多头仓位;当价格位于200日移动平均线之上,且随机振子从超买区域向下穿越80时,策略开空头仓位。该策略旨在捕捉市场的长期趋势,同时利用短期波动获取额外收益。
该策略通过结合200日移动平均线和随机振子指标,在捕捉市场长期趋势的同时,利用短期波动获取额外收益。策略具有明确的进出场信号和风险控制措施,但同时也面临假信号、趋势转折和参数优化等风险。未来可以通过动态调整参数、引入其他指标、优化风险管理和考虑交易成本等方面对策略进行优化,以提高其稳定性和盈利能力。
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("WWCD Bot", overlay=true)
// Calculate the 200-day moving average
ema200 = ta.ema(close, 200)
// Calculate Stochastic Oscillator
length = input(2, title="Stochastic Length")
smoothK = input(3, title="Stochastic Smoothing")
smoothD = input(3, title="Stochastic D Smoothing")
k = ta.stoch(close, high, low, length)
d = ta.ema(k, smoothD)
// Variable to store previous value of k
var float prev_k = na
// Check if current k is above 20 and previous k was below 20
crossed_above_20 = k >= 20 and prev_k < 20
crossed_above_80 = k <= 80 and prev_k > 80
// Condition for buy and sell signals
buy_signal_condition = close < ema200 and crossed_above_20
sell_signal_condition = close > ema200 and crossed_above_80
// Store current k for the next bar
prev_k := k
// Strategy
lot_size = 1 // Position size
if (buy_signal_condition)
strategy.entry("Buy", strategy.long, qty=lot_size)
strategy.exit("Take Profit/Stop Loss", "Buy", stop=close - 1.00, limit=close + 16)
if (sell_signal_condition)
strategy.entry("Sell", strategy.short, qty=lot_size)
strategy.exit("Take Profit/Stop Loss", "Sell", stop=close + 1.00, limit=close - 16)