Hola a todos y gracias de antemano!

Estoy aprendiendo Pine Script y he estado repasando cómo configurar las funciones strategy() y study(). Una que me ha atrapado es que en la documentación y los errores en la consola no parece tener un lugar para el parámetro linktoseries. Explica qué hay en la documentación, pero cuando le dan ambas funciones, falta y también falta en el mensaje de error que enumera los tipos en la sobrecarga que está buscando.

Esta es la estrategia 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)

Aqui esta el estudio study(title, shorttitle, overlay, format, precision, scale, max_bars_back, max_lines_count, max_labels_count, resolution, resolution_gaps)

He eliminado linktoseries = isLinkToSeries de mi código a continuación porque no estoy seguro de dónde debería ir. Si lo pego al final de las funciones, no parece causar ningún problema, pero no estoy seguro de si eso ocurrirá en el futuro, simplemente no hace nada, o si ese es el lugar correcto para ello.

Aquí está mi código que usé para ayudarme a aprender estas dos funciones.

¡Gracias de nuevo por la ayuda y que tengas una buena!

// 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)
0
Lavick81 14 mar. 2021 a las 03:36

1 respuesta

La mejor respuesta

La ubicación de los parámetros no importa en su ejemplo, porque está usando parámetros con nombre.

strategy(title = scriptLongTitle, shorttitle = scriptShortTitle, overlay = isOverlayEnabled, ...)

Los parámetros con nombre se pueden proporcionar en cualquier secuencia que desee, por lo que esto también estaría bien:

strategy(overlay = isOverlayEnabled, shorttitle = scriptShortTitle, title = scriptLongTitle, ...)

La secuencia de parámetros solo importa cuando no usa parámetros con nombre.
En ese caso, deben ingresarse en la misma secuencia que la definición de la función.
Entonces esto funcionaría:

strategy(scriptLongTitle, scriptShortTitle, isOverlayEnabled, ...)

Pero esto no funcionaría:

strategy(isOverlayEnabled, scriptShortTitle, scriptLongTitle, ...)

Sin embargo, tiene razón, que linktoseries falta en la lista de parámetros study() y strategy().
Creo que simplemente se olvidaron de hacer eso visible en la lista de parámetros porque claramente, ese parámetro es aceptado por Pine.

0
Bjorn Mistiaen 14 mar. 2021 a las 09:22