# Trying to identify Distribution Days

I am trying to create a short code that will automatically flag "Distribution Days" as described on Investors.com:

"A distribution day occurs when one of the major stock indexes, namely the Nasdaq composite and the S&P 500, falls at least 0.2% or more in higher volume than the prior day. For the S&P 500, IBD uses total turnover on the New York Stock Exchange."

At this point, I am not worried about referencing the S&P 500. Eventually I will try and do that but for now, I want to just try and get it to work on a current chart first so that I can see how everything works. The below code is what I have started with. No problems are identified by "Code Check & Profile" yet for some reason, i cant seem to get it to print "D" above the candles that meet the criteria. Any suggestions as to what I may be doing wrong?

``````_SECTION_BEGIN("Distribution Days");
for (i=1;i<BarCount;i++)
{
if ((C[i] < (C[i-1] * -.002)) AND V[i] > V[i-1])
PlotTextSetFont( "D" ,"Arial", 8, i, H[i]+1, colorBlue, 42);
}
_SECTION_END();

``````

@MCassICT Are you sure you mean 0.2% and not 2%? That is a tiny move. For 0.2% (2 tenths of a percentage point) maybe something like this

``````DD = C < 0.998*Ref(C, -1) AND V > Ref(V, -1);

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

for( i = 0; i < BarCount; i++ )
{
if( DD[i] ) PlotText( "D" , i, H[ i ]*1.003, colorBlue); // I just read letter better when there is space between the letter and the bar
}
``````
2 Likes

That did it....thank you very much.

I am sure that there are much better ways to do this but this is what I have been able to come up with. Could someone with a little more experience than myself look through this real quick and make sure my logic is correct. I have annotated everything so that it makes sense. I appreciate anyone taking the time to do so.

``````_SECTION_BEGIN("Distribution Days");

//Automatic Distribution Days Identification

//A distribution day is a significant decline in a major stock index,
//namely the Nasdaq composite and the S&P 500, in higher
//trading volume than was seen in the previous session. IBD defines a
//"significant decline" as a drop of more than 0.2%, with no rounding up to
//get to 0.2% allowed.

//A distribution day indicates unusually heavy selling by institutional
//investors, the heavyweights who largely set a market's direction.

//Four or five distribution days over several weeks nearly always signal
//that stocks have topped and are heading for a downturn.

//IBD's research has determined that investors shouldn't count distribution days
//after 25 trading days have passed. At that point, those days of liquidation have
//become irrelevant.

//A distribution day also falls out of an index's count after the index climbs 5%
//above that distribution day's close. IBD has developed this rule on the premise
//that when an index rallies and extends itself from a distribution day, it's
//showing the strength to overcome high-volume selling.

SP500 = Foreign ("SPY", "C");//SPY Close
SP500vol = Foreign ("SPY", "V");//SPY Volume

Condition1 = SP500 < 0.998*Ref( SP500, -1 ) AND SP500vol > Ref( SP500vol, -1 ); //Identifies a 0.2% drop in closing price of the day before on SPY with increasing volume
Condition2 = SP500 < LLV(SP500,25)*1.05; //Adds the condition that allows a day to drop out of the count if a gain of 5% has been attained
DD = Condition1 AND Condition2;

for( i = 0; i < BarCount; i++ )
{
if( DD[i] ) PlotText( "D" , i, H[ i ]*1.003, colorBlue, colorDefault, 20); //Plots Distribution Day based on above criteria
}

//This section below adds a small orange circle to indicate the 25th day back to begin the count

StartCountPlot1 = BarIndex() == BarCount -26;
StartCount = C > 0 AND StartCountPlot1;
StartCount2 =C < 0 AND StartCountPlot1;
Shape1 = StartCount * shapeSmallCircle + StartCount2 * shapeSmallCircle;
PlotShapes(Shape1, IIf( StartCount, colorOrange, colorOrange),0, IIf(StartCount, Low, Low));

_SECTION_END();

``````
1 Like

This is the same thing but I have added the Nasdaq as well. If anyone can suggest any corrections or improvement I would really appreciate it!

``````_SECTION_BEGIN("Distribution Days");

//Automatic Distribution Days Identification

//A distribution day is a significant decline in a major stock index,
//namely the Nasdaq composite and the S&P 500, in higher
//trading volume than was seen in the previous session. IBD defines a
//"significant decline" as a drop of more than 0.2%, with no rounding up to
//get to 0.2% allowed.

//A distribution day indicates unusually heavy selling by institutional
//investors, the heavyweights who largely set a market's direction.

//Four or five distribution days over several weeks nearly always signal
//that stocks have topped and are heading for a downturn.

//IBD's research has determined that investors shouldn't count distribution days
//after 25 trading days have passed. At that point, those days of liquidation have
//become irrelevant.

//A distribution day also falls out of an index's count after the index climbs 5%
//above that distribution day's close. IBD has developed this rule on the premise
//that when an index rallies and extends itself from a distribution day, it's
//showing the strength to overcome high-volume selling.

SP500 = Foreign ("SPY", "C");//SPY Close
SP500vol = Foreign ("SPY", "V");//SPY Volume

Condition1 = SP500 < 0.998*Ref( SP500, -1 ) AND SP500vol > Ref( SP500vol, -1 ); //Identifies a 0.2% drop in closing price of the day before on SPY with increasing volume
Condition2 = SP500 < LLV(SP500,25)*1.05; //Adds the condition that allows a day to drop out of the count if a gain of 5% has been attained
DD = Condition1 AND Condition2;

for( i = 0; i < BarCount; i++ )
{
if( DD[i] ) PlotText( "D" , i, H[ i ]*1.003, colorBlue, colorDefault, 20); //Plots Distribution Day based on above criteria
}

NDX = Foreign ("^NDX", "C");//NDX Close
NDXvol = Foreign ("^NDX", "V");//SNDX Volume

Condition1 = NDX < 0.998*Ref( NDX, -1 ) AND NDXvol > Ref( NDXvol, -1 ); //Identifies a 0.2% drop in closing price of the day before on NDX with increasing volume
Condition2 = NDX < LLV(NDX,25)*1.05; //Adds the condition that allows a day to drop out of the count if a gain of 5% has been attained
NDXDD = Condition1 AND Condition2;

for( i = 0; i < BarCount; i++ )
{
if( NDXDD[i] ) PlotText( "D" , i, H[ i ]*1.003, colorBlueGrey, colorDefault, 30); //Plots Distribution Day based on above criteria
}

//This section below adds a small orange circle to indicate the 25th day back to begin the count

StartCountPlot1 = BarIndex() == BarCount -26;
StartCount = C > 0 AND StartCountPlot1;
StartCount2 =C < 0 AND StartCountPlot1;
Shape1 = StartCount * shapeSmallCircle + StartCount2 * shapeSmallCircle;
PlotShapes(Shape1, IIf( StartCount, colorOrange, colorOrange),0, IIf(StartCount, Low, Low));

_SECTION_END();

``````
1 Like

@MCassICT Not to discourage you and unrelated to your code, there are a couple of old blog posts that researched IBD "distribution days" and found them to be useless. This is 10 year old research and it would be nice to see updated findings. Hope you can let us know how it goes.
First from a current AmiBroker user and member of this forum http://quantifiableedges.blogspot.com/2009/08/distribution-days-quantified.html

This from a very well known price pattern analyst,
http://thepatternsite.com/DistributionDay.html

5 Likes

Thanks for the information. I look forward to reading it!

1 Like

I can confirm that the IBD distribution days / follow through days as a trading system is terrible and should never be used. Countless hours wasted

Oâ€™Neil never meant to have this as it is being sold today by the site. It was meant to be a â€śtighten your stops, sell on strengthâ€ť kind of background indicator and not a strategy in and of itself. The primary indicator would always be the action of the leading stocks.

It is however worth noting that it might be used to create a good â€śhedgingâ€ť strategy for long term index investors but not any better than any other simple strategy.

2 Likes

I agree completely...my intent is NOT to use as an indicator for buying and selling. I haven't even tried testing it for that purpose. From my study, I agree that is not what it was ever meant for, only a "proceed with caution" sign basically. It doesn't necessarily mean that a car is coming the other way.

3 Likes