Documentos / Primeros pasos

Primeros pasos

Configure PineBag una vez y luego prepare su primera prueba en unos minutos.

Informe de cartera PineBag junto al panel lateral de extensión
Un verdadero espacio de trabajo de PineBag: la extensión prepara la ejecución mientras el informe completo permanece abierto a su lado.

Necesitas tres cosas

La prueba de 5 días comienza automáticamente. No requiere tarjeta. La disponibilidad de ejecución está limitada por su plan TradingView.

Instalar y abrir PineBag

  1. Instale la extensión.
    Utilice el botón de instalación de PineBag. Fija la extensión si quieres un acceso rápido.
  2. Abra un gráfico de TradingView.
    Inicie sesión primero y luego abra cualquier mercado y período admitidos.
  3. Vuelva a cargar la pestaña del gráfico.
    Haga esto después de instalar o actualizar PineBag para que el gráfico pueda conectarse.
  4. Abra PineBag.
    Seleccione el ícono PineBag. El indicador de conexión se vuelve verde cuando el gráfico está listo.

El panel lateral, control por control

Los números en la interfaz real coinciden con las explicaciones. Nada en esta imagen es una maqueta.

1 2 3 4 5 6 7 8 9 10 11
  1. 1
    Estrategia

    La estrategia cargada. Haz clic en la tarjeta para abrirla en el editor; la papelera del encabezado de la sección la elimina.

  2. 2
    Resumen de ejecución

    Plazo, capital, tamaño del pedido y comisión que se utilizará.

  3. 3
    Buscar

    Abre la búsqueda de símbolos de TradingView para que pueda agregar un símbolo calificado para el intercambio.

  4. 4
    Copiar bolsa

    Copia cada ticker, uno EXCHANGE:SYMBOL por línea.

  5. 5
    Bolsa de pasta

    Acepta líneas, comas, punto y coma o espacios e ignora duplicados.

  6. 6
    Borrar

    Pide un segundo clic, copia los tickers y luego vacía la lista; «Pegar tickers» la recupera.

  7. 7
    Etiquetas de teletipo

    Muestra la bolsa actual. Utilice × para eliminar un símbolo; suma 500.

  8. 8
    Ejecutar backtest

    Valida la configuración e inicia la ejecución secuencial de la cartera.

  9. 9
    Informes

    Guarde los 50 informes más recientes localmente y exporte JSON o CSV.

  10. 10
    Días restantes

    Active days: 05 — Días restantes.

  11. 11
    Soporte

    Hay soporte disponible para solicitudes técnicas, de facturación, de licencias y de privacidad.

Cargar una estrategia

Editor Real PineBag con estrategia Pine Script
El editor integrado utiliza números de línea y resaltado de sintaxis y guarda la fuente de trabajo automáticamente.
  1. Elige la fuente.
    Deja un .pine archivo en Estrategia, o abra el Editor y pegue el código.
  2. Corrija cualquier mensaje de validación.
    El script debe contener strategy(). PineBag muestra un error claro si no se puede utilizar.
  3. Consulta el resumen.
    Confirme el nombre del script, el plazo, el capital y el tamaño del pedido que se muestran arriba de Ejecutar.
Los scripts de indicadores no se pueden realizar pruebas retrospectivas. Si la fuente comienza con indicator(), conviértalo en una estrategia antes de ejecutar PineBag.
Listo: la conexión es verde, el resumen de la estrategia es visible y su bolsa de teletipo no está vacía.

Plantilla de estrategia

Cada campo de la pestaña Properties de TradingView corresponde a un argumento de strategy(). Guarda los valores como constantes con nombre al inicio del script: con prioridad del script, cada ticker se prueba con los mismos supuestos.

TIMEFRAME

Temporalidad

INITIAL_CAPITAL · CURRENCY

Capital inicial

ORDER_SIZE · ORDER_SIZE_TYPE

Tamaño de orden predeterminado

PYRAMIDING

Piramidación

BAR_MAGNIFIER

Detalle de barras

CALC_EVERY_TICK · CALC_ON_FILLS

Ejecución del script

COMMISSION · COMMISSION_TYPE

Comisión

MARGIN_LONG · MARGIN_SHORT

Apalancamiento largo y corto

SLIPPAGE

Deslizamiento

LIMIT_FILL_TICKS

Ejecución de órdenes límite

FILL_ON_BAR_CLOSE

Retraso de ejecución de órdenes

runtime.error()

Detiene el script en cualquier otro marco temporal.

Pine Script® v6trend-breakout-atr-risk.pine
//@version=6
// ============================================================================
// Trend breakout · ATR risk — PineBag strategy template
// ============================================================================

// ----------------------------------------------------------------------------
// STRATEGY PROPERTIES (TradingView: Settings → Properties)
// ----------------------------------------------------------------------------
// TIMEFRAME takes a standard TradingView interval. Paste one of these, by the
// lowest TradingView plan that has it (tradingview.com/pricing, Charts):
//   Basic      days      "1D" "1W" "1M" "3M" "6M" "12M"
//   Essential  minutes   "1" "3" "5" "15" "30" "45"
//              hours     "60" "120" "180" "240"
//              ranges    "1R" "10R" "100R" "1000R"
//   Premium    seconds   "1S" "5S" "10S" "15S" "30S" "45S"
//   Ultimate   ticks     "1T" "10T" "100T" "1000T"
// Other intervals are custom and not used: a week is "1W", not "7D".
const string TIMEFRAME         = "1D"                         // Chart timeframe
const float  INITIAL_CAPITAL   = 100000                       // Initial capital
const string CURRENCY          = currency.USD                 // Initial capital currency
const float  ORDER_SIZE        = 100                          // Default order size
const string ORDER_SIZE_TYPE   = strategy.percent_of_equity   // Order size: % of equity
const int    PYRAMIDING        = 1                            // Pyramiding
const bool   BAR_MAGNIFIER     = false                        // Bar detalization: Default (4 ticks per bar)
const bool   CALC_EVERY_TICK   = false                        // Script execution: On bar close
const bool   CALC_ON_FILLS     = false                        // Script execution: no recalculation after fills
const float  COMMISSION        = 0                            // Commission
const string COMMISSION_TYPE   = strategy.commission.percent  // Commission: Percent
const float  MARGIN_LONG       = 100                          // Long leverage 1x (leverage = 100 / margin)
const float  MARGIN_SHORT      = 100                          // Short leverage 1x
const int    SLIPPAGE          = 0                            // Slippage, ticks
const int    LIMIT_FILL_TICKS  = 0                            // Limit order execution: Requested price
const bool   FILL_ON_BAR_CLOSE = false                        // Order execution delay: One tick

strategy("Trend breakout · ATR risk", overlay = true,
     initial_capital = INITIAL_CAPITAL,
     currency = CURRENCY,
     default_qty_type = ORDER_SIZE_TYPE,
     default_qty_value = ORDER_SIZE,
     pyramiding = PYRAMIDING,
     use_bar_magnifier = BAR_MAGNIFIER,
     calc_on_every_tick = CALC_EVERY_TICK,
     calc_on_order_fills = CALC_ON_FILLS,
     commission_type = COMMISSION_TYPE,
     commission_value = COMMISSION,
     margin_long = MARGIN_LONG,
     margin_short = MARGIN_SHORT,
     slippage = SLIPPAGE,
     backtest_fill_limits_assumption = LIMIT_FILL_TICKS,
     process_orders_on_close = FILL_ON_BAR_CLOSE)

// Stops with a clear message on any other timeframe; PineBag reads TIMEFRAME
// and selects it for the run.
if timeframe.period != TIMEFRAME
    runtime.error("Switch the chart to the " + TIMEFRAME + " timeframe.")

// ----------------------------------------------------------------------------
// INPUT SETTINGS (TradingView: Settings → Inputs)
// ----------------------------------------------------------------------------
fastLength     = input.int(20, "Fast EMA", minval = 1)
slowLength     = input.int(50, "Slow EMA", minval = 2)
breakoutLength = input.int(20, "Breakout lookback", minval = 2)
atrLength      = input.int(14, "ATR length", minval = 1)
atrStop        = input.float(2.0, "ATR stop multiplier", minval = 0.1, step = 0.1)

// ----------------------------------------------------------------------------
// CALCULATIONS
// ----------------------------------------------------------------------------
fast = ta.ema(close, fastLength)
slow = ta.ema(close, slowLength)
atr = ta.atr(atrLength)
highestBefore = ta.highest(high, breakoutLength)[1]

// ----------------------------------------------------------------------------
// ENTRIES AND EXITS
// ----------------------------------------------------------------------------
longSignal = fast > slow and close > highestBefore
if longSignal and strategy.position_size == 0
    strategy.entry("Long", strategy.long)

stopPrice = strategy.position_avg_price - atr * atrStop
strategy.exit("ATR stop", "Long", stop = stopPrice)

// ----------------------------------------------------------------------------
// PLOTS
// ----------------------------------------------------------------------------
plot(fast, "Fast EMA", color = color.rgb(0, 153, 255))
plot(slow, "Slow EMA", color = color.rgb(123, 97, 255))

Valores de TIMEFRAME

Escribe entre comillas uno de los intervalos estándar de TradingView. Cuáles se cargan depende de tu plan de TradingView, según tradingview.com/pricing.

Basic y superiores

Días, semanas y meses.

"1D" "1W" "1M" "3M" "6M" "12M"

Essential y superiores

Minutos, horas y barras de rango. Los minutos no llevan letra; una hora es 60.

"1" "3" "5" "15" "30" "45"
"60" "120" "180" "240"
"1R" "10R" "100R" "1000R"

Premium y superiores

Intervalos en segundos.

"1S" "5S" "10S" "15S" "30S" "45S"

Solo Ultimate

Intervalos en ticks.

"1T" "10T" "100T" "1000T"

Pine Script® v6TIMEFRAME
const string TIMEFRAME = "1D"     // 1 day
// const string TIMEFRAME = "1W"  // 1 week
// const string TIMEFRAME = "240" // 4 hours
// const string TIMEFRAME = "15"  // 15 minutes
// const string TIMEFRAME = "30S" // 30 seconds, Premium and higher
Una semana es "1W", no "7D". PineBag interpreta "7D" como "1W" y rechaza otros intervalos personalizados, como "2M" o "2D".

Tamaño de orden: porcentaje, importe o cantidad

ORDER_SIZE contiene el número y ORDER_SIZE_TYPE indica qué significa. Juntos completan el campo Order size de la pestaña Properties de TradingView.

strategy.percent_of_equity

Un porcentaje del capital actual. 10 significa el 10 % del capital por operación.

strategy.cash

Un importe en la moneda de la estrategia. 1000 significa 1.000 USD por operación.

strategy.fixed

Una cantidad de contratos, acciones o monedas. 0.5 significa 0,5 BTC por operación.

qty = …

El tamaño predeterminado solo se aplica a órdenes sin su propio qty. Una entrada con qty = … usa ese valor en su lugar.

Pine Script® v6ORDER SIZE
// 10% of equity per trade
const float  ORDER_SIZE        = 10
const string ORDER_SIZE_TYPE   = strategy.percent_of_equity

// 1,000 USD per trade (CURRENCY = currency.USD)
// const float  ORDER_SIZE      = 1000
// const string ORDER_SIZE_TYPE = strategy.cash

// 0.5 contracts, shares or coins per trade
// const float  ORDER_SIZE      = 0.5
// const string ORDER_SIZE_TYPE = strategy.fixed

Tus propias variables

Guarda los ajustes de tu propia lógica de estrategia en un bloque INPUT SETTINGS aparte. Cada llamada a input.int(), input.float() o input.bool() se convierte en un campo de la pestaña Inputs de TradingView, así puedes ajustarla sin editar el código.

Pine Script® v6INPUT SETTINGS
// ----------------------------------------------------------------------------
// INPUT SETTINGS (TradingView: Settings → Inputs)
// ----------------------------------------------------------------------------
fastLength     = input.int(20, "Fast EMA", minval = 1)
slowLength     = input.int(50, "Slow EMA", minval = 2)
breakoutLength = input.int(20, "Breakout lookback", minval = 2)
atrLength      = input.int(14, "ATR length", minval = 1)
atrStop        = input.float(2.0, "ATR stop multiplier", minval = 0.1, step = 0.1)
↓Descargue la plantilla .pine editable4 KB · Pine Script v6