Architecture: Seven Helper Functions

This AFL is architected as a function library โ€” seven reusable helper functions (HAI_F1 through HAI_F7) that each handle a specific market condition check. This modular design makes it easy to combine conditions and customize your entry/exit rules.

FunctionDescriptionReturns
HAI_F1(no)HHV/LLV trailing channel โ€” dynamic S/R levelPrice level (tsl)
HAI_F2(no)Cross of Close above the HAI_F1 channelBuy signal (0/1)
HAI_F3(no)Cross of Close below the HAI_F1 channelSell signal (0/1)
HAI_F4(no)AMA2-based dynamic S/R state โ€” is price above/below dynamic level?State (0 or 1)
HAI_F5(no)Detects if AMA2 state is unchanged (sideways confirmation)Boolean
HAI_F6(p,n,s,m)Bullish directional filter: PDI > MDI AND MACD > SignalBoolean
HAI_F7(p,n,s,m)Bearish directional filter: MDI > PDI AND Signal > MACDBoolean

How the Signals are Generated

The AFL combines outputs from multiple functions to build high-confidence signals:

๐ŸŸข

Buy Condition

HAI_F2 (HHV breakout) triggers AND HAI_F6 confirms bullish direction (PDI > MDI AND MACD > Signal). Both conditions must be true simultaneously.

๐Ÿ”ด

Sell Condition

HAI_F3 (LLV breakdown) triggers AND HAI_F7 confirms bearish direction (MDI > PDI AND Signal > MACD). Confluence of breakout + momentum.

IntradayAFL.afl โ€” HAI_F4 Dynamic S/R
function HAI_F4(no) { prev = AMA2(C, 1, 0); // Dynamic S/R: switches between 20-bar H and L d = IIf(C > Ref(Max(Max(H, Ref(H,-20)), Max(Ref(H,-10), Ref(H,-15))), -1), Min(Min(L, Ref(L,-20)), Min(Ref(L,-10), Ref(L,-15))), IIf(C < Ref(Min(...), -1), Max(...), PREV)); a = Cross(Close, d); b = Cross(d, Close); return(IIf(BarsSince(a) < BarsSince(b), 1, 0)); }

Technical Specifications

HHV/LLV Period
22 bars
MACD Fast
Configurable
PDI/MDI Period
Configurable
AMA2 S/R Lookback
10, 15, 20 bars
Sections
2 (Intraday + Swing)
Explorer Support
Yes

Installation & Setup

Download & Copy

Save IntradayAFL.afl to your AmiBroker Formulas\Custom folder.

Set Timeframe

Apply on a 5-minute chart for aggressive intraday entries, or 15-minute for less noise. Ensure live data is connected via AmiFeeder or Amidata.

Apply to Chart

Insert โ†’ Indicators โ†’ find Intraday AFL. The system draws the trailing S/R staircase line and plots arrows at signal points.

Use Explorer for Scanning

For scanning multiple NSE stocks simultaneously, run in AmiBroker Explorer. Filter column will mark stocks with active buy/sell conditions.

โš ๏ธ
The Intraday AFL uses multiple simultaneous filters โ€” in a strong trending market, you may miss some early entries. Consider loosening the MACD confirmation filter (HAI_F6/F7) if you want earlier entries at the cost of more false signals.
๐Ÿ’ก
Recommended workflow: Use HAI_F1/F2/F3 for the primary signal, and HAI_F6/F7 as a final gate. This gives you 2-condition confluence โ€” similar to a trend + momentum confirmation approach used in professional intraday systems.