这是一个基于5日移动平均线(MA5)的双均线交叉开仓策略。该策略的主要思路是:在MA5上方或下方一定距离处开仓,当收盘价高于开仓价或回到开仓价时平仓。该策略旨在捕捉短期趋势,同时控制风险。
该策略使用5日简单移动平均线(SMA)作为主要指标。当新蜡烛图开盘价高于MA5时,执行买入场景1;当新蜡烛图开盘价低于MA5且距离MA5超过0.002点时,执行买入场景2。对于卖出条件,当收盘价高于开仓均价或等于开仓均价时,执行卖出场景1;当收盘价低于开仓均价0.1%时,执行卖出场景2。
该双均线交叉开仓策略是一个基于短期趋势的简单策略。通过MA5的上下穿越,以及距离阈值的设置,可以捕捉短期趋势机会。同时,固定比例止损可以控制风险。但该策略也存在一些局限性,如依赖单一指标、频繁交易等。未来可以考虑引入更多指标,优化止损止盈条件,提高策略的稳健性和适应性。
/*backtest
start: 2023-04-24 00:00:00
end: 2024-04-29 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("YBS Strategy 1.1", overlay=true)
// Moving Average Settings
ma5 = ta.sma(close, 5)
// Scenario 1: Buy when a new candle opens above the MA5
buy_condition_scenario1 = open > ma5
// Scenario 2: Buy when a new candle opens below the MA5 and is at a significant distance from the MA5
distance_from_ma5 = open - ma5
buy_condition_scenario2 = open < ma5 and distance_from_ma5 > 0.002 // Define distance in points here
// Sell: Sell at the close of the candle if it's positive above the entry price, or if the price returns to the entry price
sell_condition_scenario1 = close > strategy.position_avg_price or close == strategy.position_avg_price
sell_condition_scenario2 = close <= strategy.position_avg_price * 0.999 // Close if price drops more than 0.1% from entry price
// Execute buy and sell orders
if (buy_condition_scenario1 and not (strategy.opentrades > 0))
strategy.entry("Buy Scenario 1", strategy.long)
if (buy_condition_scenario2 and not (strategy.opentrades > 0))
strategy.entry("Buy Scenario 2", strategy.long)
if (sell_condition_scenario1)
strategy.close("Buy Scenario 1")
if (sell_condition_scenario2)
strategy.close("Buy Scenario 2")