//version=5
strategy("Custom Trading System - 4hr Chart", overlay=true, shorttitle="CTS")
// กำหนดค่าของสีและความหนาของเส้น
fastLength = input(12, title="Fast Length", minval=1)
slowLength = input(26, title="Slow Length", minval=1)
signalLength = input(9, title="Signal Length", minval=1)
rsiLength = input(14, title="RSI Length", minval=1)
// คำนวณ MACD
src = close
fastEMA = ema(src, fastLength)
slowEMA = ema(src, slowLength)
macdLine = fastEMA - slowEMA
signalLine = ema(macdLine, signalLength)
// คำนวณ RSI
rsiValue = rsi(close, rsiLength)
// สร้างสัญญาณการเข้าซื้อและขาย
longCondition = crossover(macdLine, signalLine) and close > sma(close, 50) and rsiValue < 30
shortCondition = crossunder(macdLine, signalLine) and close < sma(close, 50) and rsiValue > 70
// การจัดการตำแหน่ง
strategy.entry("Buy", strategy.long, when = longCondition)
strategy.entry("Sell", strategy.short, when = shortCondition)
strategy.close("Buy", when = crossunder(macdLine, signalLine) and close < sma(close, 50))
strategy.close("Sell", when = crossover(macdLine, signalLine) and close > sma(close, 50))
strategy("Custom Trading System - 4hr Chart", overlay=true, shorttitle="CTS")
// กำหนดค่าของสีและความหนาของเส้น
fastLength = input(12, title="Fast Length", minval=1)
slowLength = input(26, title="Slow Length", minval=1)
signalLength = input(9, title="Signal Length", minval=1)
rsiLength = input(14, title="RSI Length", minval=1)
// คำนวณ MACD
src = close
fastEMA = ema(src, fastLength)
slowEMA = ema(src, slowLength)
macdLine = fastEMA - slowEMA
signalLine = ema(macdLine, signalLength)
// คำนวณ RSI
rsiValue = rsi(close, rsiLength)
// สร้างสัญญาณการเข้าซื้อและขาย
longCondition = crossover(macdLine, signalLine) and close > sma(close, 50) and rsiValue < 30
shortCondition = crossunder(macdLine, signalLine) and close < sma(close, 50) and rsiValue > 70
// การจัดการตำแหน่ง
strategy.entry("Buy", strategy.long, when = longCondition)
strategy.entry("Sell", strategy.short, when = shortCondition)
strategy.close("Buy", when = crossunder(macdLine, signalLine) and close < sma(close, 50))
strategy.close("Sell", when = crossover(macdLine, signalLine) and close > sma(close, 50))
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.