How the Buy Sell System Works

This AFL layers two confirmation conditions for every signal. A MACD crossover alone is unreliable โ€” it generates too many false signals in ranging markets. Adding a ZigZag trend filter ensures you're only taking MACD signals that agree with the broader swing direction.

๐ŸŸข

Buy Signal Conditions

Condition 1: MACD line crosses above Signal line (bullish MACD crossover)
Condition 2: ZigZag(C, z) > Ref(ZigZag(C, z), -4) โ€” the recent ZigZag pivot is rising (uptrend confirmed)

๐Ÿ”ด

Sell Signal Conditions

Condition 1: Signal line crosses above MACD line (bearish MACD crossover)
Condition 2: ZigZag(C, z) < Ref(ZigZag(C, z), -4) โ€” the recent ZigZag pivot is falling (downtrend confirmed)

Dynamic Support & Resistance Bands

Beyond the buy/sell arrows, this AFL plots two dashed dynamic levels on the chart:

  • BSR1 (Bear Resistance): Calculated from RSI-smoothed EMA data โ€” acts as upper resistance zone. Price struggling to cross this = bearish bias.
  • BSR2 (Bull Support): Derived from the same formula at a different value threshold โ€” acts as dynamic support. Price holding above this = bullish bias.

Technical Specifications

MACD Fast EMA
12
MACD Slow EMA
26
MACD Signal
9
ZigZag %
1 (default)
Bear Resistance %
60
Bull Support %
40
S/R Smoothing
EMA 13-period
Explorer
Buy / Sell Filter
BuySell_System.afl โ€” Signal Logic
// Two-condition Buy: MACD cross + ZigZag uptrend Cond1 = Cross(MACD(r1,r2), Signal(r1,r2,r3)); Cond3 = Zig(C, z) > Ref(Zig(C, z), -4); Buy = Cond1 AND Cond3; // Two-condition Sell: MACD cross + ZigZag downtrend Cond4 = Cross(Signal(r1,r2,r3), MACD(r1,r2)); Cond6 = Zig(C, z) < Ref(Zig(C, z), -4); Sell = Cond4 AND Cond6; // Arrow shapes on chart shape = Buy * shapeUpArrow + Sell * shapeDownArrow; PlotShapes(shape, IIf(Buy, colorPaleGreen, colorRose), 0, IIf(Buy, Low, High));

Best Use Cases

๐Ÿ“…

Daily Charts (Positional)

Scan NSE 500 stocks on daily charts after market close. MACD + ZigZag confluence on daily gives swing setups with 3โ€“10 day holding periods.

โฐ

60-Min Charts (Intraday Swing)

Use on 60-minute charts for intraday positions held 2โ€“4 hours. Good fit for liquid F&O stocks and Nifty index futures.

๐Ÿ”

Batch Scanning

Run in AmiBroker Explorer on your Nifty 200 watchlist to find all stocks with active Buy or Sell signals each morning.

๐Ÿ“‰

Trend Confirmation

Use BSR1/BSR2 dynamic S/R levels as additional confirmation โ€” buy signals above BSR2 have higher probability; sell signals below BSR1 are stronger.

๐Ÿ’ก
Beginner Friendly: This is the easiest AFL in our library to understand and use. The ZigZag filter is pre-optimized โ€” if you're new to AmiBroker AFLs, start here before moving to more complex systems like the Intraday AFL or Half-Trend.