TradingView - 如何以百分比设置佣金?

时间:2018-05-26 06:21:39

标签: tradingview-api pine-script

如何在Pine脚本中设置strategy.commission.percent

我知道如何在手动设置中将佣金设置为百分比。但是还有一种方法可以用代码设置佣金吗?

这是我的策略脚本:

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")

1 个答案:

答案 0 :(得分:1)

我找到了如何执行此操作here

strategy("Working 55 & 200 EMA strategy", overlay=true, 
     initial_capital=1000, 
     commission_type=strategy.commission.percent, 
     commission_value=0.2)