1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| // This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=6 strategy(title="my RSI", overlay = true)
// Inputs i_stratSelect = input.string(defval = "rsi", title = "Select Strategy", options = ["rsi", "macd", "bb"]) i_bbsrc = input.source(defval = close, title = "BB strategy source")
f_strategySelector(_strat) => if _strat == "rsi" // RSI rsi = ta.rsi(close, 14) // Rsi strategy risbuyCondition = ta.crossover(rsi, 30) rsisellCondition = ta.crossunder(rsi, 70) [risbuyCondition, rsisellCondition] else if _strat == "macd" // MACD [macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9) crossOverSignal = ta.crossover(macdLine, signalLine) crossUnderSignal = ta.crossunder(macdLine, signalLine) macdbuyCondition = histLine > 0 and crossOverSignal macdsellCondition = histLine < 0 and crossUnderSignal [macdbuyCondition, macdsellCondition] else if _strat == "bb" // BB [middle, upper, lower] = ta.bb(close, 10, 2) bbbuyCondition = i_bbsrc < lower bbsellCondition = i_bbsrc > upper [bbbuyCondition, bbsellCondition] else na
[buy, sell] = f_strategySelector(i_stratSelect) plotshape(buy ? low : na, text = "buy", style = shape.arrowup, location = location.belowbar, color = color.green, textcolor = color.green, size = size.large) plotshape(sell ? high : na, text = "sell", style = shape.arrowdown, location = location.abovebar, color = color.red, textcolor = color.red, size = size.large)
if buy strategy.entry("golang", strategy.long)
if sell strategy.entry("goshort", strategy.short)
|