mercredi 14 septembre 2022

Coding a strategy with PineScript v5

 Here are the very basics that will help you get started with coding a strategy in PineScript v5 (The programming language on Tradingview) :


//@version=5

strategy("test", initial_capital=500)

if open>close[1]

    strategy.entry("Long", strategy.long, 1000)

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

    strategy.exit("Exit", "Long", profit = 100, loss = 100)

plot(strategy.equity)


For those who are interested of the details of this very simple strategy : It checks if the current close price is greater than the previous open price and in that case it buy a quantity of 1000 and will sell when the price is 100 points higher.

Eg. on CHZUSDT in 15-minutes timeframe, it could open the following trade :