This educational strategy uses a confirmed higher-timeframe EMA and a bracket measured in ticks from the simulated entry fill. Its 0.05% commission and two-tick slippage are illustrative inputs, not broker benchmarks. Use a standard time-based chart below the filter timeframe. Check affordability and tradable quantity for the chosen symbol. This page reports no measured returns or live-fill comparison.
Pine Script v6: fixed assumptions for an audit runpinescript
//@version=6
strategy("Backtest assumption audit", overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity, default_qty_value=10,
margin_long=100, pyramiding=0,
commission_type=strategy.commission.percent, commission_value=0.05,
slippage=2, process_orders_on_close=false,
calc_on_every_tick=false, calc_on_order_fills=false,
use_bar_magnifier=false)
string filterTf = input.timeframe("1D", "Higher timeframe")
int fastLen = input.int(10, "Fast EMA", minval=1)
int slowLen = input.int(30, "Slow EMA", minval=1)
int stopTicks = input.int(100, "Stop distance in ticks", minval=1)
int targetTicks = input.int(150, "Target distance in ticks", minval=1)
if timeframe.in_seconds() >= timeframe.in_seconds(filterTf)
runtime.error("Choose a filter timeframe higher than the chart timeframe.")
float confirmedEma = request.security(syminfo.tickerid, filterTf,
ta.ema(close, 50)[1], lookahead=barmerge.lookahead_on)
float fastEma = ta.ema(close, fastLen)
float slowEma = ta.ema(close, slowLen)
bool crossedUp = ta.crossover(fastEma, slowEma)
if barstate.isconfirmed and crossedUp and close > confirmedEma and strategy.position_size == 0
strategy.entry("Long", strategy.long)
strategy.exit("Bracket", "Long", loss=stopTicks, profit=targetTicks)
plot(fastEma, "Fast EMA", color=color.teal)
plot(slowEma, "Slow EMA", color=color.orange)
plot(confirmedEma, "Confirmed higher-timeframe EMA", color=color.purple)