AFL Code requirement for scanning divergences between 2 Symbols for Pair trading opportunities.


Well-Known Member
Request if any AFL coding experts can check on below requirement -

I need a code for scanning divergences between 2 Symbols for Pair trading opportunities. -

Please find below the Trading idea and followed by the Afl code required so that you can get a overall idea of requirement -

Basically, for stock's pair trading - We take identical moving stocks and plot them on chart and then look for divergences between them.
For example : (REC and PFC) ( HDFC and HDFC Bank ) ( ICICI bank and HDFC bank ) etc.. say we have 20 pairs.

Now the premise is that stocks in each pair move similar way. That is when REC make new high, even PFC would also make the day high. But when one stock makes new high, where as other stock does not make new high, I consider this as divergence. I want an afl to scan such divergences between the 2 symbols in each pair.

Visually we cannot manage to track more than one pair, hence an afl and scan can come to help to give results matching our conditions.

Stock pair - REC and PFC

Buy: When REC make new day low AND Pfc is above its day low..
Sell: When REC make new day high AND Pfc is below its day high.

So this way the code should scan and deliver the results on 20 pairs.

Please let me know, here or inbox. Thank you.

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Are you a day trader?