Pine Script v5 · Strategy
Estrategia Larry Connors [JoseMetal]
A Pine Script v5 strategy built on SMA or EMA or WMA or HMA (close, 10), RSI (close, 2) and ATR (7). It has 8 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 10% of equity and pays no commission. 26 settings; defaults include Fecha inicio 0, TPSL SL ATR mult 3.1 and TPSL TP ATR mult 3.1.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Estrategia Larry Connors [JoseMetal] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
- How did Estrategia Larry Connors [JoseMetal] do on BTCUSDT 1D with default settings?
- +2.70%
- From 26 Jan 2024 to 21 Oct 2026, over 24 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Estrategia Larry Connors [JoseMetal] run in Pine Script v6?
- Yes
- Same 24 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Estrategia Larry Connors [JoseMetal] use a stop loss?
- Yes
- strategy.exit sets a stop on line 149, 159, 164, 168.
- Does Estrategia Larry Connors [JoseMetal] run in Zeal Terminal?
- Yes
- It compiles in 55 ms and runs 1,000 bars in 127 ms, in the browser.
BTCUSDT · 1D · default settings
- Media de salida
- Media tendencial
- Precio Entrada
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2.70%
- $269.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 24
- 17 won · 7 lost
- Profitable
- 70.8%
- of closed trades
- Profit factor
- 1.81
- gross profit ÷ gross loss
- Max drawdown
- 2.38%
- −$238.18
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
12 settings have no label
In the settings dialog fecha_inicio (line 32), fecha_fin (line 34), TPSL_SL_ATR_mult (line 44), TPSL_TP_ATR_mult (line 46), TPSL_break_even_mult (line 50), MA_SALIDA_fuente (line 58), MA_SALIDA_length (line 59), MA_TENDENCIA_fuente (line 62), MA_TENDENCIA_length (line 63), RSI_length (line 80), RSI_nivel_ob (line 83), ATR_length (line 87) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Período de pruebas | |||
| Fecha inicio (no label in the script)Las fechas son inclusivas | 0 | time | vela_en_fecha |
| Fecha de finalización | false | bool | vela_en_fecha |
| Fecha fin (no label in the script) | timestamp("1 Jan 2999") | time | vela_en_fecha |
| Posiciones | |||
| ¿LONGS? | true | bool | entrar_en_LONG |
| ¿SHORTS? | true | bool | entrar_en_SHORT |
| Stop Loss y Take Profit (ATR) | |||
| ¿Usar Stop Loss? / Mult. ATR | false | bool | line 141 exit Cerrar Long line 151 exit Cerrar Short |
| TPSL SL ATR mult (no label in the script)Si está activado, se usará el ATR multiplicado por éste valor como Stop Loss | 3.1 | float · min 0.1 · step 0.1 | ATR_sl |
| ¿Usar Take Profit? / Mult. ATR | false | bool | line 143 exit Cerrar Long line 153 exit Cerrar Short |
| TPSL TP ATR mult (no label in the script)Si está activado, se usará el ATR multiplicado por éste valor como Take Profit | 3.1 | float · min 0.1 · step 0.1 | ATR_tp |
| Break Even (ATR) | |||
| ¿Proteger posiciones? (Break Even) | false | bool | Nivel requerido para activar 'Break Even' Nivel de 'Break Even' line 145 line 155 line 161 |
| • Mult. para BREAK EVEN y STOP LOSSCuando el precio avance a nuestro favor y llegue éste ATR, el Stop Loss se moverá a BREAK EVEN, de modo que la operación quede protegida.\nEl 'nivel de stop loss' nos permite que el stop se mueva aún más a favor de nuestro precio de entrada para además asegurar ganancias | 1.0 | float · min 0.0 · step 0.1 | ATR_be_req |
| TPSL break even mult (no label in the script) | 0.8 | float · min 0.0 · step 0.1 | ATR_be |
| General | |||
| Colorear velas | true | bool | color_velas |
| Marcar velas neutras | true | bool | color_velas |
| MAs | |||
| • (Media de salida) Tipo / Fuente / Long. | SMA | string · options ["SMA", "EMA", "WMA", "HMA"] | line 65 line 67 line 69 |
| MA SALIDA fuente (no label in the script) | close | source | MA_SALIDA |
| MA SALIDA length (no label in the script) | 10 | int · min 1 | MA_SALIDA |
| • (Media de tendencia) Tipo / Fuente / Long. | SMA | string · options ["SMA", "EMA", "WMA", "HMA"] | line 71 line 73 line 75 |
| MA TENDENCIA fuente (no label in the script) | close | source | MA_TENDENCIA |
| MA TENDENCIA length (no label in the script) | 200 | int · min 1 | MA_TENDENCIA |
| RSI | |||
| • Fuente / Longitud | close | source | RSI |
| RSI length (no label in the script) | 2 | int · min 1 | RSI |
| • Sobreventa / Sobrecompra | 5 | int · min 0 · max 99 | RSI_en_sobreventa |
| RSI nivel ob (no label in the script) | 95 | int · min 1 · max 100 | RSI_en_sobrecompra |
| ATR | |||
| • Referencia / Longitud | close | source | ATR_LONG_sl ATR_LONG_tp ATR_SHORT_sl ATR_SHORT_tp ATR_LONG_break_even_req ATR_SHORT_break_even_req ATR_LONG_break_even ATR_SHORT_break_even |
| ATR length (no label in the script) | 7 | int · min 1 | ATR |
What it calculates
- SMA / EMA / WMA / HMAMA SALIDA fuente (close), MA SALIDA length (10)
MA_SALIDA · line 60 - SMA / EMA / WMA / HMAMA TENDENCIA fuente (close), MA TENDENCIA length (200)
MA_TENDENCIA · line 64 - RSI• Fuente / Longitud (close), RSI length (2)
RSI · line 81 - ATRATR length (7)
ATR · line 88
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
The script has 73 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Close Abrir Long | (LONG_abierto and exit_LONG_conditions) | On | 110 |
| Close Abrir Short | (SHORT_abierto and exit_SHORT_conditions) | On | 112 |
| Open Abrir Long long | (entrar_en_LONG) | On | 148 |
| Exit Cerrar Long stop and limit | (entrar_en_LONG) | On | 149 |
| Open Abrir Short short | (entrar_en_SHORT) | On | 158 |
| Exit Cerrar Short stop and limit | (entrar_en_SHORT) | On | 159 |
| Exit Cerrar Long stop and limit | (LONG_abierto and LONG_stop_loss < LONG_break_even and close > LONG_break_even_req) | On | 164 |
| Exit Cerrar Short stop and limit | (SHORT_abierto and SHORT_stop_loss > SHORT_break_even and close < SHORT_break_even_req) | On | 168 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2.7% | +102.5% | 24 | 71% | 1.81 | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.3% | +5.5% | 18 | 61% | 1.50 | 0.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.5% | +9.8% | 24 | 58% | 0.80 | 6.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.1% | +8.4% | 19 | 74% | 1.15 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −2.3% | +16.7% | 28 | 54% | 0.77 | 6.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.2% | +21.5% | 18 | 67% | 0.87 | 1.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −1.6% | +148.3% | 19 | 53% | 0.68 | 4.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.3% | +17.1% | 16 | 81% | 1.43 | 0.9% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 10 | 70% | $43.54 |
| Sideways market | 10 | 70% | $165.14 |
| Falling market | 4 | 75% | $61.21 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2.3%
The 95th percentile of the worst drawdown when the same 24 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.4% to 2.3%; the tick is what actually happened, 1.7%. Order luck alone moves it this much.
All 24 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 14 Feb 2024 49,699.60 | 23 Feb 2024 51,288.40 | 9 | −$31.97 |
| short | 1 Mar 2024 61,131.00 | 16 Mar 2024 69,499.80 | 15 | −$136.46 |
| short | 24 Apr 2024 66,414.00 | 25 Apr 2024 64,289.60 | 1 | $31.45 |
| short | 7 Jun 2024 70,799.10 | 12 Jun 2024 67,314.20 | 5 | $48.55 |
| short | 18 Jul 2024 64,088.00 | 25 Jul 2024 65,376.00 | 7 | −$19.92 |
| short | 15 Sep 2024 59,993.00 | 1 Oct 2024 63,327.60 | 16 | −$54.98 |
| long | 6 Nov 2024 69,372.00 | 7 Nov 2024 75,572.00 | 1 | $87.91 |
| long | 25 Dec 2024 98,663.60 | 26 Dec 2024 99,429.60 | 1 | $7.71 |
| long | 28 Feb 2025 84,708.60 | 3 Mar 2025 94,270.00 | 3 | $112.11 |
| long | 1 Jun 2025 104,592.00 | 8 Jun 2025 105,552.00 | 7 | $9.22 |
| long | 4 Aug 2025 114,209.00 | 8 Aug 2025 117,472.00 | 4 | $28.73 |
| long | 21 Aug 2025 114,271.00 | 23 Aug 2025 116,936.00 | 2 | $23.51 |
| long | 25 Sep 2025 113,307.00 | 30 Sep 2025 114,312.00 | 5 | $8.96 |
| long | 13 Oct 2025 114,959.00 | 24 Oct 2025 110,078.00 | 11 | −$42.94 |
| short | 7 Jan 2026 93,748.00 | 10 Jan 2026 90,641.30 | 3 | $33.38 |
| short | 16 Jan 2026 95,604.80 | 20 Jan 2026 92,631.00 | 4 | $31.43 |
| short | 18 Mar 2026 73,909.40 | 19 Mar 2026 71,246.60 | 1 | $36.52 |
| short | 9 Apr 2026 71,069.90 | 20 Apr 2026 73,801.80 | 11 | −$39.10 |
| short | 8 May 2026 80,006.00 | 13 May 2026 80,504.50 | 5 | −$6.31 |
| short | 17 Jun 2026 65,675.00 | 19 Jun 2026 62,958.00 | 2 | $41.90 |
| short | 8 Jul 2026 63,364.00 | 14 Jul 2026 62,334.50 | 6 | $16.52 |
| short | 23 Jul 2026 66,114.50 | 25 Jul 2026 64,140.00 | 2 | $30.42 |
| long | 12 Sep 2026 77,225.70 | 19 Sep 2026 80,883.90 | 7 | $48.40 |
| long | 10 Oct 2026 82,635.60 | 21 Oct 2026 83,028.10 | 11 | $4.88 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Estrategia Larry Connors [JoseMetal] this page | — | v5 strategy | +2.7% | 24 | 2.4% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma atr | v4 strategy | −42.3% | 18 | 44.8% |
| Atrend by OTS by prim722 | ema rsi sma atr | v4 strategy | +12.1% | 76 | 34.4% |
| DRSI DMA Scalping Strategy No Repaint by allenlk | sma wma ema rsi | v4 strategy | −99.5% | 44 | 137.7% |
| EMA crossover (daily TF) by tradeswithashish | ema sma rsi atr | v5 strategy | +11.0% | 12 | 11.6% |
| Delta-RSI Strategy (with filters) by tbiktag | rsi ema atr sma | v4 strategy | −28.8% | 71 | 83.8% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Same 24 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © JoseMetal-//@version=5+//@version=6// Descripción de la estrategia:⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 55 ms | Yes 1,000 bars in 127 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © JoseMetal//@version=5// Descripción de la estrategia:// + LONG:// El precio debe estar por encima de la SMA lenta.// Cuando una vela cierra en la zona de sobreventa del RSI, la siguiente vela cierra fuera de la zona de sobreventa y el precio de cierre está POR DEBAJO de la SMA rápida = abre LONG.// Se cierra cuando una vela cierra POR ENCIMA de la SMA rápida.// - SHORT:// El precio debe estar POR DEBAJO de la SMA lenta.// Cuando una vela cierra en la zona de sobrecompra del RSI, la siguiente vela cierra fuera de la zona de sobrecompra y el precio de cierre está POR ENCIMA de la SMA rápida = abre SHORT.// Se cierra cuando una vela cierra POR DEBAJO de la SMA rápida.// *La estrategia de Larry Connor NO utiliza un Stop Loss o Take Profit fijo, como él dijo, eso reduce el rendimiento significativamente//== Constantesc_blanco = color.rgb(255, 255, 255, 0)c_negro = color.rgb(0, 0, 0, 0)c_amarillo_radiactivo = color.rgb(255, 255, 0, 0)c_cian_radiactivo = color.rgb(0, 255, 255, 0)c_verde_radiactivo = color.rgb(0, 255, 0, 0)c_verde = color.rgb(0, 128, 0, 0)c_verde_oscuro = color.rgb(0, 80, 0, 0)c_rojo_radiactivo = color.rgb(255, 0, 0, 0)c_rojo = color.rgb(128, 0, 0, 0)c_rojo_oscuro = color.rgb(80, 0, 0, 0) c_naranja_oscuro = color.rgb(200, 120, 0, 0)noneColor = color.new(color.white, 100)max_float = 10000000000.0//== Funciones//== Declarar estrategia y período de testeostrategy("Larry Connors Strategy [JoseMetal]", shorttitle="Larry Connors Strategy [JoseMetal]", overlay=true, initial_capital=10000, pyramiding=0, default_qty_value=10, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.0, max_labels_count=500, max_bars_back=1000)GRUPO_per_pruebas = "Período de pruebas"fecha_inicio = input.time(0, "• Fecha de inicio", group=GRUPO_per_pruebas, tooltip="Las fechas son inclusivas") // timestamp("1 Jan 2000")fecha_fin_usar = input.bool(false, "Fecha de finalización", group=GRUPO_per_pruebas, inline="fecha_finalizacion")fecha_fin = input.time(timestamp("1 Jan 2999"), "", group=GRUPO_per_pruebas, inline="fecha_finalizacion")vela_en_fecha = time >= fecha_inicio and (fecha_fin_usar ? time <= fecha_fin : true)posicion_abierta = strategy.position_size != 0LONG_abierto = strategy.position_size > 0SHORT_abierto = strategy.position_size < 0GRUPO_P = "Posiciones"P_permitir_LONGS = input.bool(title="¿LONGS?", group=GRUPO_P, defval=true, inline="pos_activadas")P_permitir_SHORTS = input.bool(title="¿SHORTS?", group=GRUPO_P, defval=true, inline="pos_activadas")GRUPO_TPSL = "Stop Loss y Take Profit (ATR)"TPSL_SL_ATR_usar = input.bool(false, "¿Usar Stop Loss? / Mult. ATR", group=GRUPO_TPSL, inline="stop_loss")TPSL_SL_ATR_mult = input.float(3.1, "", group=GRUPO_TPSL, minval=0.1, step=0.1, inline="stop_loss", tooltip="Si está activado, se usará el ATR multiplicado por éste valor como Stop Loss")TPSL_TP_ATR_usar = input.bool(false, "¿Usar Take Profit? / Mult. ATR", group=GRUPO_TPSL, inline="take_profit")TPSL_TP_ATR_mult = input.float(3.1, "", group=GRUPO_TPSL, minval=0.1, step=0.1, inline="take_profit", tooltip="Si está activado, se usará el ATR multiplicado por éste valor como Take Profit")GRUPO_BE = "Break Even (ATR)"usar_be = input.bool(false, "¿Proteger posiciones? (Break Even)", group=GRUPO_BE)TPSL_break_even_req_mult = input.float(title="• Mult. para BREAK EVEN y STOP LOSS", group=GRUPO_BE, defval=1.0, minval=0.0, step=0.1, inline="be", tooltip="Cuando el precio avance a nuestro favor y llegue éste ATR, el Stop Loss se moverá a BREAK EVEN, de modo que la operación quede protegida.\nEl 'nivel de stop loss' nos permite que el stop se mueva aún más a favor de nuestro precio de entrada para además asegurar ganancias")TPSL_break_even_mult = input.float(title="", group=GRUPO_BE, defval=0.8, minval=0.0, step=0.1, inline="be")GRUPO_general = "General"mostrar_color_velas = input.bool(title="Colorear velas", defval=true, group=GRUPO_general)mostrar_color_velas_2 = input.bool(title="Marcar velas neutras", defval=true, group=GRUPO_general)//== Inputs de indicadores// Medias móvilesGRUPO_MAs = "MAs"MA_SALIDA_tipo = input.string(title="• (Media de salida) Tipo / Fuente / Long.", group=GRUPO_MAs, defval="SMA", options=["SMA", "EMA", "WMA", "HMA"], inline="ma_salida")MA_SALIDA_fuente = input.source(title="", group=GRUPO_MAs, defval=close, inline="ma_salida")MA_SALIDA_length = input.int(title="", group=GRUPO_MAs, defval=10, minval=1, inline="ma_salida")MA_SALIDA = ta.sma(MA_SALIDA_fuente, MA_SALIDA_length)MA_TENDENCIA_tipo = input.string(title="• (Media de tendencia) Tipo / Fuente / Long.", group=GRUPO_MAs, defval="SMA", options=["SMA", "EMA", "WMA", "HMA"], inline="ma_tendencia")MA_TENDENCIA_fuente = input.source(title="", group=GRUPO_MAs, defval=close, inline="ma_tendencia")MA_TENDENCIA_length = input.int(title="", group=GRUPO_MAs, defval=200, minval=1, inline="ma_tendencia")MA_TENDENCIA = ta.sma(MA_TENDENCIA_fuente, MA_TENDENCIA_length)if (MA_SALIDA_tipo == "EMA") MA_SALIDA := ta.ema(MA_SALIDA_fuente, MA_SALIDA_length)else if (MA_SALIDA_tipo == "WMA") MA_SALIDA := ta.wma(MA_SALIDA_fuente, MA_SALIDA_length)else if (MA_SALIDA_tipo == "HMA") MA_SALIDA := ta.hma(MA_SALIDA_fuente, MA_SALIDA_length)if (MA_TENDENCIA_tipo == "EMA") MA_TENDENCIA := ta.ema(MA_TENDENCIA_fuente, MA_TENDENCIA_length)else if (MA_TENDENCIA_tipo == "WMA") MA_TENDENCIA := ta.wma(MA_TENDENCIA_fuente, MA_TENDENCIA_length)else if (MA_TENDENCIA_tipo == "HMA") MA_TENDENCIA := ta.hma(MA_TENDENCIA_fuente, MA_TENDENCIA_length)// RSIGRUPO_RSI = "RSI"RSI_src = input.source(title="• Fuente / Longitud", group=GRUPO_RSI, defval=close, inline="rsi_calc")RSI_length = input.int(title="", group=GRUPO_RSI, defval=2, minval=1, inline="rsi_calc")RSI = ta.rsi(RSI_src, RSI_length)RSI_nivel_os = input.int(title="• Sobreventa / Sobrecompra", group=GRUPO_RSI, defval=5, minval=0, maxval=99, inline="rsi_niveles")RSI_nivel_ob = input.int(title="", group=GRUPO_RSI, defval=95, minval=1, maxval=100, inline="rsi_niveles")// ATRGRUPO_ATR = "ATR"ATR_referencia = input.source(title="• Referencia / Longitud", group=GRUPO_ATR, defval=close, inline="atr_calc") // La fuente no se aplica al cálculo del ATR, es para el posicionamiento respecto al precio en el gráficoATR_length = input.int(title="", group=GRUPO_ATR, defval=7, minval=1, inline="atr_calc")ATR = ta.atr(ATR_length)ATR_sl = ATR * TPSL_SL_ATR_multATR_tp = ATR * TPSL_TP_ATR_multATR_be_req = ATR * TPSL_break_even_req_multATR_be = ATR * TPSL_break_even_multATR_LONG_sl = ATR_referencia - ATR_sl // De forma contraria el inferior se puede usar como STOP LOSS o TRAILING STOPATR_LONG_tp = ATR_referencia + ATR_tp // El ATR sobre las velas se puede usar como TAKE PROFITATR_SHORT_sl = ATR_referencia + ATR_sl // ""ATR_SHORT_tp = ATR_referencia - ATR_tp // Para Shorts es al revésATR_LONG_break_even_req = ATR_referencia + ATR_be_reqATR_SHORT_break_even_req = ATR_referencia - ATR_be_reqATR_LONG_break_even = ATR_referencia + ATR_beATR_SHORT_break_even = ATR_referencia - ATR_be//== Cálculo de condicionescierre_sobre_MA_SALIDA = close > MA_SALIDAtendencia_alcista = close > MA_TENDENCIARSI_en_sobreventa = RSI < RSI_nivel_osRSI_en_sobrecompra = RSI > RSI_nivel_ob//== Salida de posicionesexit_LONG_conditions = cierre_sobre_MA_SALIDAexit_SHORT_conditions = not cierre_sobre_MA_SALIDAif (LONG_abierto and exit_LONG_conditions) strategy.close("Abrir Long")if (SHORT_abierto and exit_SHORT_conditions) strategy.close("Abrir Short")//== Entrada de posiciones (deben cumplirse todas para entrar)LONG_condition_1 = tendencia_alcistaLONG_condition_2 = not cierre_sobre_MA_SALIDA // Vela con cierre bajo la media rápidaLONG_condition_3 = RSI_en_sobreventa[1] and not RSI_en_sobreventa // Sobreventa en la vela anterior y ya no en la actualall_LONG_conditions = LONG_condition_1 and LONG_condition_2 and LONG_condition_3entrar_en_LONG = P_permitir_LONGS and all_LONG_conditions and vela_en_fecha and not LONG_abiertoSHORT_condition_1 = not tendencia_alcistaSHORT_condition_2 = cierre_sobre_MA_SALIDA // Vela con cierre sobre la media rápidaSHORT_condition_3 = RSI_en_sobrecompra[1] and not RSI_en_sobrecompra // Sobrecompra en la vela anterior y ya no en la actualall_SHORT_conditions = SHORT_condition_1 and SHORT_condition_2 and SHORT_condition_3entrar_en_SHORT = P_permitir_SHORTS and all_SHORT_conditions and vela_en_fecha and not SHORT_abiertovar LONG_stop_loss = 0.0var LONG_take_profit = max_floatvar LONG_break_even_req = 0.0var LONG_break_even = 0.0var SHORT_stop_loss = max_floatvar SHORT_take_profit = 0.0var SHORT_break_even_req = 0.0var SHORT_break_even = 0.0var en_be = falseif (not posicion_abierta) en_be := false LONG_stop_loss := 0.0 LONG_take_profit := max_float SHORT_stop_loss := max_float SHORT_take_profit := 0.0if (not posicion_abierta) if (entrar_en_LONG) if (TPSL_SL_ATR_usar) LONG_stop_loss := ATR_LONG_sl if (TPSL_TP_ATR_usar) LONG_take_profit := ATR_LONG_tp if (usar_be) LONG_break_even_req := ATR_LONG_break_even_req LONG_break_even := ATR_LONG_break_even strategy.entry("Abrir Long", strategy.long) strategy.exit("Cerrar Long", "Abrir Long", stop=TPSL_SL_ATR_usar ? LONG_stop_loss : na, limit=TPSL_TP_ATR_usar ? LONG_take_profit : na) else if (entrar_en_SHORT) if (TPSL_SL_ATR_usar) SHORT_stop_loss := ATR_SHORT_sl if (TPSL_TP_ATR_usar) SHORT_take_profit := ATR_SHORT_tp if (usar_be) SHORT_break_even_req := ATR_SHORT_break_even_req SHORT_break_even := ATR_SHORT_break_even strategy.entry("Abrir Short", strategy.short) strategy.exit("Cerrar Short", "Abrir Short", stop=TPSL_SL_ATR_usar ? SHORT_stop_loss : na, limit=TPSL_TP_ATR_usar ? SHORT_take_profit : na)// Proteger operativa (Break Even)if (usar_be and not en_be) if (LONG_abierto and LONG_stop_loss < LONG_break_even and close > LONG_break_even_req) LONG_stop_loss := LONG_break_even strategy.exit("Cerrar Long", "Abrir Long", stop=LONG_stop_loss, limit=TPSL_TP_ATR_usar ? LONG_take_profit : na) en_be := true else if (SHORT_abierto and SHORT_stop_loss > SHORT_break_even and close < SHORT_break_even_req) SHORT_stop_loss := SHORT_break_even strategy.exit("Cerrar Short", "Abrir Short", stop=SHORT_stop_loss, limit=TPSL_TP_ATR_usar ? SHORT_take_profit : na) en_be := true//== Ploteo en pantalla// SMAsplot(MA_SALIDA, "Media de salida", color=color.aqua, linewidth=2)plot(MA_TENDENCIA, "Media tendencial", color=tendencia_alcista ? #00a800 : #ca0000, linewidth=4)// Color de fondobgcolor = entrar_en_LONG ? color.new(color.green, 85) : entrar_en_SHORT ? color.new(color.red, 85) : color.new(color.black, 100)bgcolor(bgcolor)// Color de las velas según sobrecompra/sobreventa del RSIcolor_velas = mostrar_color_velas ? (RSI_en_sobreventa ? c_verde_radiactivo : RSI_en_sobrecompra ? c_rojo_radiactivo : mostrar_color_velas_2 ? c_negro : na) : nabarcolor(color_velas)// Precio de compra, Stop Loss, Take Profit, Break Even...avg_position_price_plot = plot(posicion_abierta ? strategy.position_avg_price : na, color=color.new(color.white, 25), style=plot.style_linebr, linewidth=2, title="Precio Entrada")break_even_req_plot = plot(posicion_abierta and usar_be and not en_be ? (LONG_abierto ? LONG_break_even_req : SHORT_break_even_req) : na, color=color.new(color.blue, 25), style=plot.style_linebr, linewidth=1, title="Nivel requerido para activar 'Break Even'")break_even_plot = plot(posicion_abierta and usar_be and not en_be ? (LONG_abierto ? LONG_break_even : SHORT_break_even) : na, color=color.new(color.aqua, 25), style=plot.style_linebr, linewidth=1, title="Nivel de 'Break Even'")LONG_sl_plot = plot(LONG_abierto and LONG_stop_loss > 0.0 ? LONG_stop_loss : na, color=en_be ? color.new(color.aqua, 25) : color.new(color.red, 25), style=plot.style_linebr, linewidth=3, title="Long Stop Loss")LONG_tp_plot = plot(LONG_abierto and LONG_take_profit < max_float ? LONG_take_profit : na, color=color.new(color.lime, 25), style=plot.style_linebr, linewidth=3, title="LONG Take Profit")fill(avg_position_price_plot, LONG_sl_plot, color=color.new(color.maroon, 85))fill(avg_position_price_plot, LONG_tp_plot, color=color.new(color.olive, 85))SHORT_sl_plot = plot(SHORT_abierto and SHORT_stop_loss < max_float ? SHORT_stop_loss : na, color=en_be ? color.new(color.aqua, 25) : color.new(color.red, 25), style=plot.style_linebr, linewidth=3, title="Short Stop Loss")SHORT_tp_plot = plot(SHORT_abierto and SHORT_take_profit > 0.0 ? SHORT_take_profit : na, color=color.new(color.lime, 25), style=plot.style_linebr, linewidth=3, title="SHORT Take Profit")fill(avg_position_price_plot, SHORT_sl_plot, color=color.new(color.maroon, 85))fill(avg_position_price_plot, SHORT_tp_plot, color=color.new(color.olive, 85))