//@version=5 // quantfly strategy "momentum": EMA(12/26) crossover, buys only when RSI(14) < 70 // Exported by quantfly.research.pine with parameters fast=12, slow=26, rsi_n=14, rsi_max=70.0. // Execution as in quantfly's backtester: long-only, one position at a time, signals at the bar close, orders filled // at the next bar's open (process_orders_on_close=false), commission 0.1% of each fill. // Known differences from quantfly: // - Warm-up: ta.ema seeds its first values differently from quantfly's SMA-seeded ema_series, so a crossover near the // start of the chart's history can differ; the averages converge after warm-up. ta.rsi is Wilder's RSI, seeded like // quantfly's rsi_series. // - quantfly's candle index i is bar_index here, so warm-up guards count bars from the first bar TradingView loaded. // - Slippage: quantfly charges 0.05% of each fill; TradingView counts slippage in ticks (slippage=0 here). // - Sizing: default_qty_value is a share of equity; quantfly's position_pct is a share of free cash, with the fee // taken out of the quantity. // - quantfly force-closes a trade still open on the last candle; TradingView leaves it open. // Checked with quantfly's pine_lint only, not compiled here: paste it into TradingView's Pine Editor to confirm it // compiles. strategy("quantfly momentum", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=95, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0, process_orders_on_close=false) // Inputs: quantfly's parameters, defaulting to the exported values fast = input.int(12, "fast", minval=1) slow = input.int(26, "slow", minval=1) rsi_n = input.int(14, "rsi_n", minval=1) rsi_max = input.float(70.0, "rsi_max") // Indicators and warm-up guards (quantfly: prepare, signal_at) fast_ema = ta.ema(close, fast) slow_ema = ta.ema(close, slow) rsi_value = ta.rsi(close, rsi_n) crossed_up = ta.crossover(fast_ema, slow_ema) crossed_down = ta.crossunder(fast_ema, slow_ema) ready = bar_index > slow and not na(fast_ema) and not na(fast_ema[1]) // Orders: decided at the bar close, filled at the next bar's open (quantfly: signal_at, then the next open) long_entry = ready and crossed_up and not na(rsi_value) and rsi_value < rsi_max long_exit = ready and crossed_down if strategy.position_size == 0 and long_entry strategy.entry("Long", strategy.long) if strategy.position_size > 0 and long_exit strategy.close("Long") plot(fast_ema, "fast EMA", color=color.teal) plot(slow_ema, "slow EMA", color=color.orange) plot(rsi_value, "RSI", display=display.data_window)