Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TradingView - How to set commission in percent?

Tags:

pine-script

How do I set strategy.commission.percent in Pine script?

I know how to set commission as a percentage in the manual settings. But is there also a way to set commission with code?

This is my strategy script:

strategy("Working 55 & 200 EMA strategy", overlay = true, initial_capital=1000)

fast = input(defval = 55, step = 5)
slow = input(200)

ma1 = ema(close, fast)
ma2 = ema(close, slow)

plot(ma1, title = "Fast MA", color = lime, style = line, linewidth = 3)
plot(ma2, title = "Slow MA", color = black, style = line, linewidth = 3)

// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2018, title = "From Year", minval = 2010)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

// === FUNCTION EXAMPLE ===
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false // create function "within window of time"

strategy.entry("Buy", strategy.long, when = window() and crossover(ma1, ma2))
strategy.entry("Sell", strategy.short, when = window() and crossover(ma2, ma1))
strategy.exit("Buy")
strategy.exit("Sell")
like image 611
whitesiroi Avatar asked Dec 11 '22 06:12

whitesiroi


1 Answers

I found how to do this here:

strategy("Working 55 & 200 EMA strategy", overlay=true, 
     initial_capital=1000, 
     commission_type=strategy.commission.percent, 
     commission_value=0.2)
like image 190
whitesiroi Avatar answered Feb 19 '23 05:02

whitesiroi