Franco trade 0.0

48
//version=5
strategy("OBV + Moving Averages Strategy", overlay=true)

// 參數設置
length_OBV = input(1, "OBV 增量") // OBV的變動閥值
length_maVolume = input(50, "50日均量") // 50日均量
length_maShort = input(5, "5日均線") // 5日均線
length_maLong = input(13, "13日均線") // 13日均線
take_profit = input(0.1, "止盈比例 (10%)") // 10%止盈
stop_loss = input(0.05, "止損比例 (5%)") // 5%止損

// 計算技術指標
obvValue = ta.cum(ta.volume * math.sign(ta.change(close))) // OBV指標
maVolume = ta.sma(volume, length_maVolume) // 50日均量
maShort = ta.sma(close, length_maShort) // 5日均線
maLong = ta.sma(close, length_maLong) // 13日均線

// 買入條件
buy_condition = ta.crossover(maShort, maLong) and // 5日均線上穿13日均線
obvValue > ta.highest(obvValue[1], length_OBV) and // OBV創新高
volume > maVolume // 成交量大於50日均量

// 賣出條件
sell_condition = ta.crossunder(maShort, maLong) or // 5日均線跌破13日均線
obvValue < ta.lowest(obvValue[1], length_OBV) or // OBV走弱
strategy.position_size > 0 and (strategy.position_avg_price * (1 + take_profit) < close or // 達到止盈目標
strategy.position_avg_price * (1 - stop_loss) > close) // 達到止損目標

// 執行交易策略
if buy_condition
strategy.entry("Long", strategy.long)

if sell_condition
strategy.close("Long")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.