Pine Script Video Lessons

Here’s a list of my YouTube Pine Script video lessons and the source code for each of them!


Pine Script Basics Course Pine Script Mastery Course

Lesson 1: Hello World!


//@version=4
study("Lesson 1")
plot(close)

Lesson 2: Drawing Data to the Chart


//@version=4
study("Lesson 2", overlay=true)
lookback = input(title="Lookback Period", type=input.integer, defval=50, minval=1)
highestHigh = highest(high, lookback)
lowestLow = lowest(low, lookback)
plot(highestHigh, color=color.red, transp=0, linewidth=2)
plot(lowestLow, color=color.blue, transp=0, linewidth=2)

Lesson 3: Getting Basic User Input


//@version=4
study("Lesson 3")

booleanInput = input(title="Boolean", type=input.bool, defval=true)
integerInput = input(title="Integer", type=input.integer, defval=2)
floatInput = input(title="Float", type=input.float, defval=1.5)
stringInput = input(title="String", type=input.string, defval="Some text")

plot(booleanInput ? 1 : 0, color=color.red)
plot(integerInput, color=color.blue)
plot(floatInput, color=color.purple)

// Draw label
if(barstate.islast)
    labelExample = label.new(bar_index, na, stringInput, color=color.green, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar)

Lesson 4: Generating RSI Signals


//@version=4
study("Lesson 4", overlay=true)

// Get user input
rsiSource = input(title="RSI Source", type=input.source, defval=close)
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=80)
rsiOversold = input(title="RSI Oversold Level", type=input.integer, defval=20)

// Get RSI Value
rsiValue = rsi(rsiSource, rsiLength)
isRsiOB = rsiValue >= rsiOverbought
isRsiOS = rsiValue <= rsiOversold

// Plot signals to chart
plotshape(isRsiOB, title="Overbought", location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, text="Sell")
plotshape(isRsiOS, title="Oversold", location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, text="Buy")

Lesson 5: TradingView Script Alerts


//@version=4
study("Lesson 5", overlay=true)

// Get user input
rsiSource = input(title="RSI Source", type=input.source, defval=close)
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=80)
rsiOversold = input(title="RSI Oversold Level", type=input.integer, defval=20)

// Get RSI Value
rsiValue = rsi(rsiSource, rsiLength)
isRsiOB = rsiValue >= rsiOverbought
isRsiOS = rsiValue <= rsiOversold

// Plot signals to chart
plotshape(isRsiOB, title="Overbought", location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, text="Sell")
plotshape(isRsiOS, title="Oversold", location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, text="Buy")

// Send out an alert if this candle meets our conditions
alertcondition(isRsiOB or isRsiOS, title="RSI Signal!", message="RSI Signal Detected for {{ticker}}")    

Lesson 6: Detecting Engulfing Candles


//@version=4
study("Lesson 6", overlay=true)

// Get user input
rsiSource = input(title="RSI Source", type=input.source, defval=close)
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=80)
rsiOversold = input(title="RSI Oversold Level", type=input.integer, defval=20)

// Get RSI Value
rsiValue = rsi(rsiSource, rsiLength)
isRsiOB = rsiValue >= rsiOverbought
isRsiOS = rsiValue <= rsiOversold

// Identify engulfing candles
bullishEC = close >= open[1] and close[1] < open[1]
bearishEC = close <= open[1] and close[1] > open[1]
tradeSignal = ((isRsiOS or isRsiOS[1]) and bullishEC) or ((isRsiOB or isRsiOB[1]) and bearishEC)

// Plot signals to chart
plotshape(tradeSignal and bearishEC, title="Overbought", location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, text="Sell")
plotshape(tradeSignal and bullishEC, title="Oversold", location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, text="Buy")

// Send out an alert if this candle meets our conditions
alertcondition(tradeSignal, title="RSI Signal!", message="RSI Signal Detected for {{ticker}}")


Free Premium Charts!