top of page
Design sem nome (14).png

Introduction to Pine Script

Pine-script-logo.png

Pine Script® is TradingView’s programming language. It allows traders to create their own trading tools and run them on TradingView’s servers. TradingView designed Pine Script® as a lightweight, yet powerful, language for developing indicators and strategies that you can then backtest. Most of TradingView’s built-in indicators are written in Pine Script®

Lesson 1 - Creating Stochastic Indicator

//@version=4
study(title = "stochastic", overlay = false)
stochastic = ((close - lowest(low,5)) / (highest(high,5) - lowest(low,5))) * 100
plot(stochastic)

Lesson 2 - Inputs for Stochastic Indicator

//@version=4
study(title = "stochastic", overlay = false)
k = input(5, title = "k")
stochastic = ((close - lowest(low,k)) / (highest(high,k) - lowest(low,k))) * 100
plot(stochastic)
plot(70)
plot(30)

Lesson 3 - Plotting a Moving Average

//@version=4
study(title = "name", overlay = true)
MovingAverageSource = input(close, title = "Source")
MovingAverageLength = input(20, title = "Length")
a = sma(MovingAverageSource,MovingAverageLength)
plot(a)

Lesson 4 - Variable declaration and variable assignment

//@version=4
study(title = "name", overlay = false)

//variable declaration
var int a = na
var float b = na
var bool c = na
var color d = na

// variable assignment
a := 7
b := 7.77
c := true
d := color.lime

plot(a, color = d)
plot(b, color = d)

Instagram post para marketing digital ousado azul (1).png

Lesson 5 - Creating Macd

//@version = 4
study("MACD")
FastLenght = ema(close,12)
SlowLenght = ema(close,26)
macd = FastLenght - SlowLenght
signal = ema(macd,12)

plot(macd, color=color.blue)
plot(signal, color=color.red)

Lesson 6 - If else

//@version=4
study(title = "if else", overlay = true)

var color c = na

a = 7
b = 3

if (a < b)
    c := color.blue
else
    c := color.yellow

    
barcolor(c)

Lesson 7 - Identifying the market trend with if statements

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

var color x = na

a = close
b = sma(close,50)

if (a > b)
    x := color.lime
    
if (a < b)
    x := color.red
    
barcolor(x)
plot(b, color = x)

Lesson 8 - How to Program a Moving Average Cloud Indicator

//@version=4

study(title = "MOVING AVERAGE CLOUD 1.0", overlay = true)

 

source = ema(close,12)

upper = source * 1.03

lower = source / 1.03

 

plot(source)

plot(upper)

plot(lower)

Lesson 9 -  Creating Your First Strategy!!!

//@version=5

strategy(title="strategy",overlay=true,process_orders_on_close = true)

buysignal=(close<open/1.02)

exitsignal=(close>open)

 

if (strategy.position_size==0)

    if (buysignal)

        strategy.entry("buy",strategy.long)

 

if (strategy.position_size>0)

    if (exitsignal)

        strategy.close("buy")

Lesson 10 -  Programming a buy and sell strategy

//@version=5

strategy(title="strategy",overlay=true,process_orders_on_close = true)

m = ta.sma(close,20)

buysignal=(close<open/1.02) and (close>m)

exitbuysignal=(close>open)

sellsignal=(close>open*1.02) and (close<m)

exitsellsignal=(close<open)

 

if (strategy.position_size==0)

    if (buysignal)

        strategy.entry("buy",strategy.long)

    if (sellsignal)

        strategy.entry("sell",strategy.short)        

if (strategy.position_size>0)

    if (exitbuysignal)

        strategy.close("buy")

if (strategy.position_size<0)

    if (exitsellsignal)

        strategy.close("sell")      

plot(m)        

Lesson 11 -  Programming an input for the strategy!!!

//@version=5

strategy(title="strategy",overlay=true,process_orders_on_close = true)

m = ta.sma(close,20)

buysignal=(close<open/1.02) and (close>m)

exitbuysignal=(close>open)

sellsignal=(close>open*1.02) and (close<m)

exitsellsignal=(close<open)

 

if (strategy.position_size==0)

    if (buysignal)

        strategy.entry("buy",strategy.long)

    if (sellsignal)

        strategy.entry("sell",strategy.short)        

if (strategy.position_size>0)

    if (exitbuysignal)

        strategy.close("buy")

if (strategy.position_size<0)

    if (exitsellsignal)

        strategy.close("sell")      

plot(m)        

Lesson 12 -  Programming a strategy using moving average

Cópia de Instagram post para marketing digital ousado azul (2) (1).png

Lesson 13 -  Programming a Stop loss!!!

Cópia de Instagram post para marketing digital ousado azul (2) (1).png

Lesson 14 -  How to Program 3 Green Candles Strategy

Cópia de Instagram post para marketing digital ousado azul (2) (1).png

More Lessons Coming Soon!

bottom of page