在 TradingView 上的 Pine Script 中,将 linktoseries 参数放在 strategy() 或 study() 中的什么位置有关系吗?
Does it matter where you put the linktoseries parameter in a strategy() or study() in Pine Script on TradingView?
大家好,提前致谢!
我刚刚在学习 Pine Script,并且一直在研究如何设置 strategy()
和 study()
函数。让我印象深刻的是,在文档和控制台中的错误中,它似乎没有 linktoseries
参数的位置。它确实解释了它在文档中的内容,但是当它们为您提供这两个函数时,它丢失了,并且在列出它正在寻找的重载类型的错误消息中也丢失了。
这是攻略
strategy(title, shorttitle, overlay, format, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, max_lines_count, max_labels_count, slippage, commission_type, commission_value, process_orders_on_close, close_entries_rule)
这是书房
study(title, shorttitle, overlay, format, precision, scale, max_bars_back, max_lines_count, max_labels_count, resolution, resolution_gaps)
我已经从下面的代码中删除了 linktoseries = isLinkToSeries
,因为我不确定它应该去哪里。如果我只是把它贴在函数的末尾,它似乎不会引起任何问题,但我不确定将来是否会这样,只是什么都不做,或者那是否是正确的位置。
这是我用来帮助我学习这两个函数的代码。
再次感谢您的帮助,祝您生活愉快!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lavick81
// @version=4
// ****Default Strategy Settings****
scriptLongTitle = "Lavick81's Custom RSI Strategy or Study" // Type String
scriptShortTitle = "Lavick81's Custom RSI Strategy or Study" // Type String
isOverlayEnabled = true // Type bool. If true the study will be added as an overlay for the main series. If false - it would be added on a separate chart pane. Default is false.
typeOfFormat = format.inherit // Type string. Type of formatting study values on the price axis. Possible values are: format.inherit, format.price, format.volume. Default is format.inherit.
typeOfPrecision = 4 // Type integer. Number of digits after the floating point for study values on the price axis. Must be a non negative integer and not greater than 16. Default is 4
priceScale = 2 // Type integer. Price scale that the indicator should be attached to. Possible values are: scale.right, scale.left, scale.none. Value scale.none can be applied only in combination with 'isOverlayEnabled=true' setting. If omitted, using scale from main series.
maxPyramiding = 0 // Type integer. The maximum number of entries allowed in the same direction. If the value is 0, only one entry order in the same direction can be opened, and additional entry orders are rejected. The default value is 0.
calcOnOrderFills = false // Type bool. Additional one time intrabar order calculation. If the parameter is set to 'true', then the strategy is recalculated once intrabar after an order is filled (not only at close of the bar). The default value is 'false'.
calcOnEveryTick = false // Type bool. Additional intrabar strategy calculations. If the parameter is 'true', then the strategy will calculate on every tick in real-time, rather than on bars' closes. The parameter does not affect strategy calculation on historical data. The default value is 'false'.
maxBarsBack = 1000 // Type integer. Maximum number of bars available for a strategy for historical reference.
backtestFillLimitsAssumption = 0 // Type integer. Limit order execution assumption. Limit orders are filled intrabar only if market price exceeds the limit order level by the specified number of ticks.
defaultQtyType = strategy.cash // Type string. The allowed values are: strategy.fixed (fixed quantity by default), strategy.cash (specified in currency of the symbol and the amount is converted into quantity), strategy.percent_of_equity (% of currently available equity).
defaultQtyValue = 100.00 // Type float. Number of contracts/shares/lots/units if 'defaultQtyType'=strategy.fixed is used; or amount of cash in currency of the symbol if 'defaultQtyType'=strategy.cash is used; or number of percents of currently available equity if 'defaultQtyType'=strategy.percent_of_equity is used.
defaultInitialCapital = 10000.00 // Type float. This argument sets the strategy's initial capital, which is the capital used by the script when backtesting and forward testing on real-time data.
defaultCurrency = "USD" // Type string. Possible values are: NONE, USD, EUR, AUD, GBP, NZD, CAD, CHF, HKD, JPY, NOK, SEK, SGD, TRY, ZAR
maxLinesCount = 50 // Type integer. 0 to 500
maxLabelsCount = 50 // Type integer. 0 to 500
defaultSlippage = 0 // Type integer. Slippage in ticks to be added to/subtracted from the fill price of buy/sell market or stop orders. If mintick=0.01 and slippage=5, the amount of slippage will be 5*0.01=0.05.
defaultCommissionType = strategy.commission.percent // Type string. The allowed values are: strategy.commission.percent (a percentage of the cash volume of order), strategy.commission.cash_per_contract (money displayed in the account currency per contract), strategy.commission.cash_per_order (money displayed in the account currency per order).
defaultCommissionValue = 0.075 // Type float. Can be percent or money depending on defaultCommissionType setting
processOrderOnClose = false // Type bool. Default is false
closeEntriesRule = "FIFO" // Type string. "FIFO" (First-in, First-out) or "ANY" (Any Order)
isLinkToSeries = false // Type bool. If true then the study will be always on the same pane and same price scale as the main series. Should be true only in combination with 'isOverlayEnabled = true'
// ****Strategy OR Study****
// To make this script a strategy comment out the lines between ">>>>Study Settings Begains<<<<" and ">>>>Study Settings Ends<<<<"
// To make this script a study comment out the lines between ">>>>Strategy Settings Begains<<<<" and ">>>>Strategy Settings Ends<<<<"
// >>>>Strategy Settings Begains<<<<
strategy(title = scriptLongTitle, shorttitle = scriptShortTitle, overlay = isOverlayEnabled, format = typeOfFormat, precision = typeOfPrecision, scale = priceScale, pyramiding = maxPyramiding, calc_on_order_fills = calcOnOrderFills, calc_on_every_tick = calcOnEveryTick, max_bars_back = maxBarsBack, backtest_fill_limits_assumption = backtestFillLimitsAssumption, default_qty_type = defaultQtyType, default_qty_value = defaultQtyValue, initial_capital = defaultInitialCapital, currency = defaultCurrency, max_lines_count = maxLinesCount, max_labels_count = maxLabelsCount, slippage = defaultSlippage, commission_type = defaultCommissionType, commission_value = defaultCommissionValue, process_orders_on_close = processOrderOnClose, close_entries_rule = closeEntriesRule, linktoseries = isLinkToSeries)
// linktoseries = isLinkToSeries
// >>>>Strategy Settings Ends<<<<
// >>>>Study Settings Begains<<<<
// >>>>Study Settings Ends<<<<
length = input( 14 )
overSold = input( 40 )
overBought = input( 70 )
price = close
vrsi = rsi(price, length)
co = crossover(vrsi, overSold)
cu = crossunder(vrsi, overBought)
var entryPrice = 0.0
var orderOpen = false
if (not na(vrsi))
if (co)
isOrderOpen = orderOpen ? "true" : "false"
if (not orderOpen)
entryPrice := price
strategy.entry("long", strategy.long, comment="Price: " + tostring(price) + " Entry Price: "+ tostring(entryPrice*1.001) + " Order Open?: " + isOrderOpen)
orderOpen := true
if (cu and ((entryPrice * 1.001) < price))
isOrderOpen = orderOpen ? "true" : "false"
strategy.close("long", comment="Price: " + tostring(price) + " Entry Price: "+ tostring(entryPrice*1.001) + " Order Open?: " + isOrderOpen)
orderOpen := false
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
参数放置在您的示例中无关紧要,因为您使用的是命名参数。
strategy(title = scriptLongTitle, shorttitle = scriptShortTitle, overlay = isOverlayEnabled, ...)
命名参数可以按您喜欢的任何顺序给出,所以这样也可以:
strategy(overlay = isOverlayEnabled, shorttitle = scriptShortTitle, title = scriptLongTitle, ...)
仅当您不使用命名参数时,参数顺序才重要。
在那种情况下,它们需要按照与函数定义相同的顺序输入。
所以这会起作用:
strategy(scriptLongTitle, scriptShortTitle, isOverlayEnabled, ...)
但这行不通:
strategy(isOverlayEnabled, scriptShortTitle, scriptLongTitle, ...)
不过你是对的,study()
和 strategy()
参数列表中都缺少 linktoseries
。
我认为他们只是忘记在参数列表中显示该参数,因为很明显,该参数已被 Pine 接受。
大家好,提前致谢!
我刚刚在学习 Pine Script,并且一直在研究如何设置 strategy()
和 study()
函数。让我印象深刻的是,在文档和控制台中的错误中,它似乎没有 linktoseries
参数的位置。它确实解释了它在文档中的内容,但是当它们为您提供这两个函数时,它丢失了,并且在列出它正在寻找的重载类型的错误消息中也丢失了。
这是攻略
strategy(title, shorttitle, overlay, format, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, max_lines_count, max_labels_count, slippage, commission_type, commission_value, process_orders_on_close, close_entries_rule)
这是书房
study(title, shorttitle, overlay, format, precision, scale, max_bars_back, max_lines_count, max_labels_count, resolution, resolution_gaps)
我已经从下面的代码中删除了 linktoseries = isLinkToSeries
,因为我不确定它应该去哪里。如果我只是把它贴在函数的末尾,它似乎不会引起任何问题,但我不确定将来是否会这样,只是什么都不做,或者那是否是正确的位置。
这是我用来帮助我学习这两个函数的代码。
再次感谢您的帮助,祝您生活愉快!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lavick81
// @version=4
// ****Default Strategy Settings****
scriptLongTitle = "Lavick81's Custom RSI Strategy or Study" // Type String
scriptShortTitle = "Lavick81's Custom RSI Strategy or Study" // Type String
isOverlayEnabled = true // Type bool. If true the study will be added as an overlay for the main series. If false - it would be added on a separate chart pane. Default is false.
typeOfFormat = format.inherit // Type string. Type of formatting study values on the price axis. Possible values are: format.inherit, format.price, format.volume. Default is format.inherit.
typeOfPrecision = 4 // Type integer. Number of digits after the floating point for study values on the price axis. Must be a non negative integer and not greater than 16. Default is 4
priceScale = 2 // Type integer. Price scale that the indicator should be attached to. Possible values are: scale.right, scale.left, scale.none. Value scale.none can be applied only in combination with 'isOverlayEnabled=true' setting. If omitted, using scale from main series.
maxPyramiding = 0 // Type integer. The maximum number of entries allowed in the same direction. If the value is 0, only one entry order in the same direction can be opened, and additional entry orders are rejected. The default value is 0.
calcOnOrderFills = false // Type bool. Additional one time intrabar order calculation. If the parameter is set to 'true', then the strategy is recalculated once intrabar after an order is filled (not only at close of the bar). The default value is 'false'.
calcOnEveryTick = false // Type bool. Additional intrabar strategy calculations. If the parameter is 'true', then the strategy will calculate on every tick in real-time, rather than on bars' closes. The parameter does not affect strategy calculation on historical data. The default value is 'false'.
maxBarsBack = 1000 // Type integer. Maximum number of bars available for a strategy for historical reference.
backtestFillLimitsAssumption = 0 // Type integer. Limit order execution assumption. Limit orders are filled intrabar only if market price exceeds the limit order level by the specified number of ticks.
defaultQtyType = strategy.cash // Type string. The allowed values are: strategy.fixed (fixed quantity by default), strategy.cash (specified in currency of the symbol and the amount is converted into quantity), strategy.percent_of_equity (% of currently available equity).
defaultQtyValue = 100.00 // Type float. Number of contracts/shares/lots/units if 'defaultQtyType'=strategy.fixed is used; or amount of cash in currency of the symbol if 'defaultQtyType'=strategy.cash is used; or number of percents of currently available equity if 'defaultQtyType'=strategy.percent_of_equity is used.
defaultInitialCapital = 10000.00 // Type float. This argument sets the strategy's initial capital, which is the capital used by the script when backtesting and forward testing on real-time data.
defaultCurrency = "USD" // Type string. Possible values are: NONE, USD, EUR, AUD, GBP, NZD, CAD, CHF, HKD, JPY, NOK, SEK, SGD, TRY, ZAR
maxLinesCount = 50 // Type integer. 0 to 500
maxLabelsCount = 50 // Type integer. 0 to 500
defaultSlippage = 0 // Type integer. Slippage in ticks to be added to/subtracted from the fill price of buy/sell market or stop orders. If mintick=0.01 and slippage=5, the amount of slippage will be 5*0.01=0.05.
defaultCommissionType = strategy.commission.percent // Type string. The allowed values are: strategy.commission.percent (a percentage of the cash volume of order), strategy.commission.cash_per_contract (money displayed in the account currency per contract), strategy.commission.cash_per_order (money displayed in the account currency per order).
defaultCommissionValue = 0.075 // Type float. Can be percent or money depending on defaultCommissionType setting
processOrderOnClose = false // Type bool. Default is false
closeEntriesRule = "FIFO" // Type string. "FIFO" (First-in, First-out) or "ANY" (Any Order)
isLinkToSeries = false // Type bool. If true then the study will be always on the same pane and same price scale as the main series. Should be true only in combination with 'isOverlayEnabled = true'
// ****Strategy OR Study****
// To make this script a strategy comment out the lines between ">>>>Study Settings Begains<<<<" and ">>>>Study Settings Ends<<<<"
// To make this script a study comment out the lines between ">>>>Strategy Settings Begains<<<<" and ">>>>Strategy Settings Ends<<<<"
// >>>>Strategy Settings Begains<<<<
strategy(title = scriptLongTitle, shorttitle = scriptShortTitle, overlay = isOverlayEnabled, format = typeOfFormat, precision = typeOfPrecision, scale = priceScale, pyramiding = maxPyramiding, calc_on_order_fills = calcOnOrderFills, calc_on_every_tick = calcOnEveryTick, max_bars_back = maxBarsBack, backtest_fill_limits_assumption = backtestFillLimitsAssumption, default_qty_type = defaultQtyType, default_qty_value = defaultQtyValue, initial_capital = defaultInitialCapital, currency = defaultCurrency, max_lines_count = maxLinesCount, max_labels_count = maxLabelsCount, slippage = defaultSlippage, commission_type = defaultCommissionType, commission_value = defaultCommissionValue, process_orders_on_close = processOrderOnClose, close_entries_rule = closeEntriesRule, linktoseries = isLinkToSeries)
// linktoseries = isLinkToSeries
// >>>>Strategy Settings Ends<<<<
// >>>>Study Settings Begains<<<<
// >>>>Study Settings Ends<<<<
length = input( 14 )
overSold = input( 40 )
overBought = input( 70 )
price = close
vrsi = rsi(price, length)
co = crossover(vrsi, overSold)
cu = crossunder(vrsi, overBought)
var entryPrice = 0.0
var orderOpen = false
if (not na(vrsi))
if (co)
isOrderOpen = orderOpen ? "true" : "false"
if (not orderOpen)
entryPrice := price
strategy.entry("long", strategy.long, comment="Price: " + tostring(price) + " Entry Price: "+ tostring(entryPrice*1.001) + " Order Open?: " + isOrderOpen)
orderOpen := true
if (cu and ((entryPrice * 1.001) < price))
isOrderOpen = orderOpen ? "true" : "false"
strategy.close("long", comment="Price: " + tostring(price) + " Entry Price: "+ tostring(entryPrice*1.001) + " Order Open?: " + isOrderOpen)
orderOpen := false
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
参数放置在您的示例中无关紧要,因为您使用的是命名参数。
strategy(title = scriptLongTitle, shorttitle = scriptShortTitle, overlay = isOverlayEnabled, ...)
命名参数可以按您喜欢的任何顺序给出,所以这样也可以:
strategy(overlay = isOverlayEnabled, shorttitle = scriptShortTitle, title = scriptLongTitle, ...)
仅当您不使用命名参数时,参数顺序才重要。
在那种情况下,它们需要按照与函数定义相同的顺序输入。
所以这会起作用:
strategy(scriptLongTitle, scriptShortTitle, isOverlayEnabled, ...)
但这行不通:
strategy(isOverlayEnabled, scriptShortTitle, scriptLongTitle, ...)
不过你是对的,study()
和 strategy()
参数列表中都缺少 linktoseries
。
我认为他们只是忘记在参数列表中显示该参数,因为很明显,该参数已被 Pine 接受。