Trading view Pine Editor, hello world

Reading the book Machine Trading from Ernie P. Chang, on the first chapter it offers different oppinions about environments to gather historical data, do backtesting…

I started to analyze which one of the solutions was better to cover the whole picture proposed in the book. My analysis was basically to compare Tradingview and Ninja Trader.

I started to evaluate Quantopian, as it covers backtesting and the environment to develop is Perl on Notebook (which I am familar with), but I discarded it.

As conclusion, for my initial steps on backtesting I have selected Tradingview as tool to start building backtests scripts.

This one is the first one. It combines a simple strategy between RSI and MACD.

//@version=3
strategy(“Test-1 RSI”, overlay=true, initial_capital=1000, currency=’USD’)
/////////// inputs //////////
// RSI
Length = input(14, minval=1)
Oversold = input(25, minval=1)
Overbought = input(70, minval=1)
// MACD
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
/////////// individual long conditions //////////
// RSI
rsiLongCondition = rsi(close, Length) < Oversold
// MACD
MACD = ema(close, fastLength) – ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
macdDelta = MACD – aMACD
macdLongCondition = crossover(macdDelta, 0)
/////////// long condition //////////
// RSI and MACD
if (rsiLongCondition and macdLongCondition)
strategy.entry(“Long 1”, strategy.long)
/////////// individual short conditions //////////
// RSI
rsiShortCondition = rsi(close, Length) > Overbought
// MACD
macdShortCondition = crossunder(macdDelta, 0)
/////////// short condition //////////
if (macdShortCondition)
strategy.close(“Short 1”)

Leave a Comment