Bullish & Bearish Divergence in OBV and ADL

What will be the afl code for the following type of scans with plot & exploration:
Other than daily time how it can be modified accordingly (with suitable parameter) to be plotted and explored on lower time frame also like 5 min, 15 min, 1 hour, 4 hour

(Ref: This scan starts with a base of stocks that are averaging at least $10 in price and 100,000 daily volume over the last 60 days. Potential bullish divergences are found by looking for stocks where price is BELOW the 65-day SMA and 20-day SMA, but OBV and the Accumulation Distribution Line are ABOVE the 65-day SMA and 20-day SMA.
This scan starts with a base of stocks that are averaging at least $10 in price and 100,000 daily volume over the last 60 days. Potential bearish divergences are found by looking for stocks where price is ABOVE the 65-day SMA and 20-day SMA, but OBV and the Accumulation Distribution Line are BELOW the 65-day SMA and 20-day SMA.
On Balance Volume (OBV) [ChartSchool])

[Daily SMA(60,Daily Volume) > 100000] 
[Daily SMA(60,Daily Close) > 10] 
[Daily Close < Daily SMA(65,Daily Close)] 
[Daily AccDist > Daily AccDist Signal (65)] 
[Daily OBV > Daily OBV Signal(65)] 
[Daily Close < Daily SMA(20,Daily Close)] 
[Daily AccDist > Daily AccDist Signal (20)] 
[Daily OBV > Daily OBV Signal(20)]

[Daily SMA(60,Daily Volume) > 100000] 
[Daily SMA(60,Daily Close) > 10] 
[Daily Close > Daily SMA(65,Daily Close)] 
[Daily AccDist < Daily AccDist Signal (65)] 
[Daily OBV < Daily OBV Signal(65)] 
Daily Close > Daily SMA(20,Daily Close)] 
[Daily AccDist < Daily AccDist Signal (20)] 
[Daily OBV < Daily OBV Signal(20)]

Regards

Will it be like this for Bullish Divergence?

Filter = MA(V,60) > 100000;
Filter = MA(C,60) > 500;
Filter = C < MA(C,65);
Filter = C < MA(C,20);
Filter = OBV () > MA(C,65);
Filter = OBV () > MA(C,20);
Filter = ADX () > MA(C,65);
Filter = ADX () > MA(C,20);
AddColumn (Filter, "1");

However desired result up-to satisfactory level is not coming to explore stocks with Bullish Divergence

@prasadaraokarri

You are working in the right direction, but instead of redefining Filter for each row, you should be AND ing them together.

I personally separate the conditions, so I can more easily edit them, or make part of them parameters.

So here is a truncated version:

//   Looking for Bullish Divergence

condvolume = MA( Volume, 60 ) > 100000;
condprice = MA( C, 60 ) > 10;
condclose65 = C < MA( C, 65 );
condclose20 = C < MA( C, 20 );
condOBV65 = OBV() > MA( OBV(), 65 ); // not sure if this is what you want
condOBV25 = OBV() > MA( OBV(), 25 );
condADX65 = ADX() > MA( ADX(), 65 );
condADX25 = ADX() > MA( ADX(), 25 );

Filter = condvolume AND condprice AND condclose65 AND condclose20 AND condOBV65 AND condOBV25 AND condADX65 AND condADX25;

AddColumn( C, "Close" );
AddColumn( MA( C, 65 ), "MA C 65" );
AddColumn( MA( C, 20 ), "MA C 20" );
AddColumn( OBV(), "OBV" );
AddColumn( MA( OBV() , 65 ), "OBV 65);

 // rest for you to do


4 Likes

Thanks @snoopy.pa30 for your kind support.

I am getting an error like this while going for exploration.
Error

Actually, My conditions of filtering are like this:
e.g. finding the Stocks with Bullish Divergence in terms of OBV
The stocks whose
daily price is Running above $10 and Daily Traded Volume Running above 100000 (averaging over last 60 days)
Daily Closing Price<SMA for 65 Days
Daily Closing Price < SMA for 20 Days
But OBV and the Accumulation Distribution Line are ABOVE the 65-day SMA and 20-day SMA.

Lastly, I got i the point of the error

Yes Finally I got the point - you left one condition incomplete for Column Writing and putting that the exploration happened correctly
OBV
Thanks.

@prasadaraokarri

Sorry, I missed a quote on the line that gave you the error.

And yes, I left the last bits for you. I figured it would help you learn a bit more AFL.

Glad you got it working.

2 Likes

Absolutely. See I have learned AFL coding a little bit. But becoming an expert in any subject takes a lot of time. But if you the experts help sometimes - we do not get frustrated.

However if you think you can explore it with further better logic parameter - please suggest me

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.