//@version=6 strategy("MACD Lab: does signal-lag scaling explain buffer activity", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=99, process_orders_on_close=false) fast_length = input.int(12, "Fast length", minval=1) slow_length = input.int(26, "Slow length", minval=2) signal_length = input.int(9, "Signal length", minval=2) buffer_bps = input.float(5.0, "Histogram buffer (price basis points)", minval=0.0) buffer_mode = input.int(0, "Buffer mode: 0 original, 1 scale by signal lag", minval=0, maxval=1) [macd_line, signal_line, histogram] = ta.macd(close, fast_length, slow_length, signal_length) lag_scale = buffer_mode == 0 ? 1.0 : (signal_length - 1.0) / 8.0 threshold = close * buffer_bps / 10000.0 * lag_scale valid = fast_length < slow_length and bar_index >= 500 enter_long = valid and histogram > threshold exit_long = valid and histogram < -threshold plot(macd_line, "MACD", color=color.blue) plot(signal_line, "Signal", color=color.orange) plot(histogram, "MACD minus signal", color=color.green, style=plot.style_histogram) plot(threshold, "Positive buffer", color=color.gray) plot(-threshold, "Negative buffer", color=color.gray) hline(0, "Zero", color=color.gray) if strategy.position_size > 0 and exit_long strategy.close("Long") if strategy.position_size == 0 and enter_long strategy.entry("Long", strategy.long)