Strategy · Pine Script v4 · On the chart

Estrategia Booz

by hasnocool

This strategy trades moving-average crossovers on the price chart.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code63
Settings14inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

63 lines of Pine Script v4 from Booz Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Booz Strategy.pine
////////////////////////////////////////////////////////////////////////////////
// ArnoldTrader - Estrategia Booz
// Creado por Arnold para la Comunidad
// Versión 1.2 - Última actualización: 2023-06-22
////////////////////////////////////////////////////////////////////////////////
//@timeframe=120
// Esta es la versión de ArnoldTrader de la Estrategia Booz, creada por Arnold para la Comunidad.
// La estrategia utiliza una combinación de promedios móviles y filtros de tendencia para identificar posibles operaciones.
// También incluye entradas personalizables para el stop loss, take profit, apalancamiento y período de backtest.
// ¡Feliz trading!
//@version=4
strategy("Estrategia Booz", "", true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, margin_long=0, margin_short=0)
// ----------------------------- Inputs ------------------------------------- //
source_ma_type = input("EMA", "Tipo de MA Fuente", options=["SMA", "EMA"])
source_ma_length = input(50, "Longitud de la MA Fuente")
fast_ma_length = input(50, "Longitud de la MA Rápida")
slow_ma_length = input(100, "Longitud de la MA Lenta")        
use_trend_filter = input(true, "Filtro de Tendencia")
trend_filter_ma_type = input("EMA", "Tipo de MA Filtro de Tendencia", options=["SMA", "EMA"])
trend_filter_ma_length = input(200, "Período de la MA Filtro de Tendencia")
show_mas = input(true, "Mostrar MAs")
swing_trading_mode = input(false, "Modo de Trading Swing")
// -------------------------- Calculations ---------------------------------- //
fast_ma = ema(close, fast_ma_length)
slow_ma = ema(close, slow_ma_length)
source_ma = source_ma_type == "EMA"? ema(close, source_ma_length): 
                                     sma(close, source_ma_length)
trend_filter_ma = trend_filter_ma_type == "EMA"? ema(close, trend_filter_ma_length): 
                                                 sma(close, trend_filter_ma_length)
// --------------------------- Conditions ----------------------------------- //
uptrend = not use_trend_filter or close > trend_filter_ma
buy_cond = crossover(fast_ma, slow_ma) and uptrend
downtrend = not use_trend_filter or close < trend_filter_ma
sell_cond = crossunder(fast_ma, slow_ma) and downtrend
// ---------------------------- Plotting ------------------------------------ //
bgcolor(use_trend_filter and downtrend? color.red: use_trend_filter? color.green: na)
plot(show_mas? fast_ma: na, "MA Rápida", color.green)
plot(show_mas? slow_ma: na, "MA Lenta", color.red)
plot(show_mas? source_ma: na, "MA Fuente", color.purple)
plot(show_mas? trend_filter_ma: na, "MA Filtro de Tendencia", color.blue)
// ---------------------------- Trading  ------------------------------------ //
// Inputs
sl_perc = input(1.0, "Stop Loss (en %)", group="Control de Backtest")/100
tp_perc = input(1.0, "Take Profit (en %)", group="Control de Backtest")/100
leverage = input(1, "Apalancamiento", maxval=100, group="Control de Backtest")
bt_start_time = input(timestamp("2021 01 01"), "Hora de inicio de Backtest", input.time, group="Control de Backtest")
bt_end_time = input(timestamp("2029 12 31"), "Hora de finalización de Backtest", input.time, group="Control de Backtest")
// Trading Window
in_trading_window = time >= bt_start_time and time <= bt_end_time
trade_qty = (strategy.equity * leverage) / close 
// Long Side
strategy.entry("Compra", strategy.long, trade_qty, when=buy_cond and in_trading_window)
long_tp = strategy.position_avg_price * (1 + tp_perc)
long_sl = strategy.position_avg_price * (1 - sl_perc)
if not swing_trading_mode
    strategy.exit("Cierre Compra", "Compra", limit=long_tp, stop=long_sl)
// Short Side
strategy.entry("Venta", strategy.short, trade_qty, when=sell_cond and in_trading_window)
short_tp = strategy.position_avg_price * (1 - tp_perc)
short_sl = strategy.position_avg_price * (1 + sl_perc)
if not swing_trading_mode
    strategy.exit("Cierre Venta", "Venta", limit=short_tp, stop=short_sl)
Expand (76 lines)

Overview

Estrategia Booz buys when a fast exponential moving average crosses above a slow one in an uptrend, and sells on the opposite cross in a downtrend. An optional source average and a longer trend filter, each selectable as SMA or EMA, can limit entries to the prevailing direction. Position size uses full equity scaled by a leverage input inside a chosen backtest window. Percentage stop-loss and take-profit levels are calculated from the average entry price. Moving averages and trend background colors can be shown or hidden.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Tipo de MA FuentestringEMAsource_ma_type
Longitud de la MA Fuenteint50source_ma_length
Longitud de la MA Rápidaint50fast_ma_length
Longitud de la MA Lentaint100slow_ma_length
Filtro de Tendenciabooltrueuse_trend_filter
Tipo de MA Filtro de TendenciastringEMAtrend_filter_ma_type
Período de la MA Filtro de Tendenciaint200trend_filter_ma_length
Mostrar MAsbooltrueshow_mas
Modo de Trading Swingboolfalseswing_trading_mode
Stop Loss (en %)float1.0sl_perc
Take Profit (en %)float1.0tp_perc
Apalancamientoint1leverage
Show all 14 settings
SettingTypeDefaultVariable
Hora de inicio de Backtesttimetimestamp("2021 01 01")bt_start_time
Hora de finalización de Backtesttimetimestamp("2029 12 31")bt_end_time
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers