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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| // 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 indicator(title="my RSI", overlay = true)
// Inputs useRSI = input.bool(defval = true, title = "Use Rsi") useMACD = input.bool(defval = true, title = "Use Macd") useBB = input.bool(defval = true, title = "Use BB") i_showPLots = input.bool(defval = true, title = "Show Plots")
rsi = ta.rsi(close, 14) // MACD [macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9) // BB i_bb_isrc = input.source(defval = close, title = "BB input source") i_bb_length = input.int(defval = 10, title = "BB Length") [middle, upper, lower] = ta.bb(i_bb_isrc, i_bb_length, 2)
// Rsi strategy risbuyCondition = ta.crossover(rsi, 30) and useRSI rsisellCondition = ta.crossunder(rsi, 70) and useRSI plotshape(risbuyCondition ? low : na, text = "rsi buy", style = shape.arrowup, location = location.belowbar, color = color.green, textcolor = color.green, size = size.large) plotshape(rsisellCondition ? high : na, text = "rsi sell", style = shape.arrowdown, location = location.abovebar, color = color.red, textcolor = color.red, size = size.large)
// Macd strategy // 2. 将交叉信号存入全局变量(确保每根K线都计算) crossOverSignal = ta.crossover(macdLine, signalLine) crossUnderSignal = ta.crossunder(macdLine, signalLine) macdbuyCondition = histLine > 0 and crossOverSignal and useMACD macdsellCondition = histLine < 0 and crossUnderSignal and useMACD plotshape(macdbuyCondition ? close : na, text = "macd buy", style = shape.arrowup, location = location.belowbar, color = color.green, textcolor = color.green, size = size.large) plotshape(macdsellCondition ? close : na, text = "macd sell", style = shape.arrowdown, location = location.abovebar, color = color.red, textcolor = color.red, size = size.large)
// Bb strategy i_bbsrc = input.source(defval = close, title = "BB strategy source") bbbuyCondition = i_bbsrc < lower and useBB bbsellCondition = i_bbsrc > upper and useBB plotshape(bbbuyCondition ? close : na, text = "bb buy", style = shape.arrowup, location = location.belowbar, color = color.green, textcolor = color.green, size = size.large) plotshape(bbsellCondition ? close : na, text = "bb sell", style = shape.arrowdown, location = location.abovebar, color = color.red, textcolor = color.red, size = size.large)
// PLOTS // rsi plot plot(i_showPLots ? rsi : na, title = "rsi", color = color.purple) // macd plot plot(i_showPLots ? histLine : na, title = "Histogram", style = plot.style_columns, color = histLine > 0 ? color.green : color.red) plot(i_showPLots ? macdLine : na, title = "MACD", color = color.new(color.red, 50)) plot(i_showPLots ? signalLine : na, title = "Signal", color = color.new(color.blue, 50)) // bb plot plot(i_showPLots ? middle : na, title = "bb middle", color=color.yellow) plot(i_showPLots ? upper : na, title = "bb upper", color=color.red) plot(i_showPLots ? lower : na, title = "bb lower", color=color.green)
// alert conditions sellAlertConditons = bbsellCondition or macdsellCondition or rsisellCondition alertcondition(sellAlertConditons, title = "sell alert")
|