OPEN-SOURCE SCRIPT

My Strategy11111

//version=5
strategy("My Strategy", overlay=true)

// Input parameters
smaPeriod = input(50, title="SMA Period")
rsiPeriod = input(14, title="RSI Period")
overbought = input(70, title="Overbought Level")
oversold = input(30, title="Oversold Level")
stopLossPct = input(1, title="Stop Loss (%)") / 100
takeProfitPct = input(2, title="Take Profit (%)") / 100

// Indicators
sma = ta.sma(close, smaPeriod)
rsi = ta.rsi(close, rsiPeriod)
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

// Plot indicators on the chart
plot(sma, color=color.blue, title="SMA")
hline(overbought, "Overbought", color=color.red)
hline(oversold, "Oversold", color=color.green)

// Calculate Stop Loss and Take Profit levels
longStopLoss = close * (1 - stopLossPct)
longTakeProfit = close * (1 + takeProfitPct)
shortStopLoss = close * (1 + stopLossPct)
shortTakeProfit = close * (1 - takeProfitPct)

// Buy Condition
longCondition = ta.crossover(close, sma) and rsi < oversold and macdLine > signalLine
if longCondition
strategy.entry("Long", strategy.long, stop=longStopLoss, limit=longTakeProfit)

// Sell Condition
shortCondition = ta.crossunder(close, sma) and rsi > overbought and macdLine < signalLine
if shortCondition
strategy.entry("Short", strategy.short, stop=shortStopLoss, limit=shortTakeProfit)
Candlestick analysisChart patternsCycles

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明