//@version=6
// Pine-first template: edit this file in content/, never the generated scripts/<name>.py.
// Every top-level input becomes a main() parameter of the Pyne script; the strategy()
// arguments become the @script.strategy(...) decorator; `var` becomes Persistent state.
strategy("EMA cross with ATR exits", overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity, default_qty_value=10,
commission_type=strategy.commission.percent, commission_value=0.05)
// Inputs: a default here is used until scripts/<name>.toml sets `value =` for it
fastLen = input.int(12, "Fast EMA", minval=1)
slowLen = input.int(21, "Slow EMA", minval=2)
atrLen = input.int(14, "ATR length", minval=1)
stopMult = input.float(2.0, "Stop ATR multiple", minval=0.1, step=0.1)
tpMult = input.float(3.0, "Target ATR multiple", minval=0.1, step=0.1)
useFilter = input.bool(true, "Only above 200 EMA")
// Indicators: call ta.* on every bar, at the top level, so their history is complete
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
trend = ta.ema(close, 200)
atr = ta.atr(atrLen)
longSignal = ta.crossover(fast, slow) and (not useFilter or close > trend)
exitSignal = ta.crossunder(fast, slow)
// State kept across bars
var float stopPrice = na
var float targetPrice = na
if longSignal and strategy.position_size == 0
stopPrice := close - stopMult * atr
targetPrice := close + tpMult * atr
strategy.entry("L", strategy.long)
strategy.exit("L exit", "L", stop=stopPrice, limit=targetPrice)
if exitSignal and strategy.position_size > 0
strategy.close("L", comment="cross down")
// Plots: each title becomes a column of output/<name>.csv
plot(fast, "Fast EMA", color=color.teal)
plot(slow, "Slow EMA", color=color.orange)
plot(strategy.position_size > 0 ? stopPrice : na, "Stop", color=color.red, style=plot.style_linebr)
plot(strategy.position_size > 0 ? targetPrice : na, "Target", color=color.green, style=plot.style_linebr)
Overview
An optional 200-period EMA filter restricts trades to broad uptrends. Position management relies on dynamic stop loss and take profit targets calculated from Average True Range multipliers at the time of entry. Trades can also exit early when the fast EMA crosses below the slow EMA. User inputs adjust the EMA lengths, ATR length, stop and target multipliers, and filter toggle.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Fast EMA
int
12
fastLen
Slow EMA
int
21
slowLen
ATR length
int
14
atrLen
Stop ATR multiple
float
2.0
stopMult
Target ATR multiple
float
3.0
tpMult
Only above 200 EMA
bool
true
useFilter
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.
This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries
This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades
STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions
This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros
This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po
This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri