Booz Strategy is a price-chart strategy that opens longs when a fast EMA crosses above a slow EMA and shorts when it crosses below, provided an optional longer moving-average trend filter agrees.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
61 lines of Pine Script v4 from Bozz Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Bozz Strategy.pine
////////////////////////////////////////////////////////////////////////////////
// Booz Strategy
// Developed for Godstime
// Version 1.1
// 11/28/2021
////////////////////////////////////////////////////////////////////////////////
//@version=4
strategy("Booz Strategy", "", true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, margin_long=0, margin_short=0)
// ----------------------------- Inputs ------------------------------------- //
source_ma_type = input("EMA", "Source MA Type", options=["SMA", "EMA"])
source_ma_length = input(50, "Source MA Length")
fast_ma_length = input(20, "Fast MA Length")
slow_ma_length = input(50, "Slow MA Length")
use_trend_filter = input(true, "Trend Filter")
trend_filter_ma_type = input("EMA", "Trend Filter MA Type", options=["SMA", "EMA"])
trend_filter_ma_length = input(200, "Trend Filter MA Period")
show_mas = input(true, "Show MAs")
swing_trading_mode = input(false, "Swing Trading")
// -------------------------- 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, "Fast MA", color.green)
plot(show_mas? slow_ma: na, "Slow MA", color.red)
plot(show_mas? source_ma: na, "Source MA", color.purple)
plot(show_mas? trend_filter_ma: na, "Trend Filter MA", color.blue)
// ---------------------------- Trading ------------------------------------ //
// Inputs
sl_perc = input(1.0, "Stop Loss (in %)", group="Backtest Control")/100
tp_perc = input(1.0, "Take Profit (in %)", group="Backtest Control")/100
leverage = input(10, "Leverage", maxval=100, group="Backtest Control")
bt_start_time = input(timestamp("2021 01 01"), "Backtest Start Time", input.time, group="Backtest Control")
bt_end_time = input(timestamp("2021 12 31"), "Backtest End Time", input.time, group="Backtest Control")
// Trading Window
in_trading_window = time >= bt_start_time and time <= bt_end_time
trade_qty = (strategy.equity * leverage) / close
// Long Side
strategy.entry("Long Entry", 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("Long Exit", "Long Entry", limit=long_tp, stop=long_sl)
// Short Side
strategy.entry("Short Entry", 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("Short Exit", "Short Entry", limit=short_tp, stop=short_sl)
// End of trading window close
strategy.close_all(when=not in_trading_window)
Expand (72 lines)
Overview
SMA or EMA choices and lengths change the filter and a plotted source average; the source average is not used in entries. Default exits use percentage stop loss and take profit, while swing mode skips those exits. Position size scales with equity and a leverage input, and orders are limited to a backtest date window.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Source MA Type
string
EMA
source_ma_type
Source MA Length
int
50
source_ma_length
Fast MA Length
int
20
fast_ma_length
Slow MA Length
int
50
slow_ma_length
Trend Filter
bool
true
use_trend_filter
Trend Filter MA Type
string
EMA
trend_filter_ma_type
Trend Filter MA Period
int
200
trend_filter_ma_length
Show MAs
bool
true
show_mas
Swing Trading
bool
false
swing_trading_mode
Stop Loss (in %)
float
1.0
sl_perc
Take Profit (in %)
float
1.0
tp_perc
Leverage
int
10
leverage
Show all 14 settings
Setting
Type
Default
Variable
Backtest Start Time
time
timestamp("2021 01 01")
bt_start_time
Backtest End Time
time
timestamp("2021 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.
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
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
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
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
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
This educational strategy demonstrates how to configure and handle user input parameters in Pine Script. It calculates two Simple Moving Averages (SMAs) for fast and slow periods, plotting both directly on the price chart. The strategy initiates a long positio