Dear Peter,
Thanks for your reply. While the excel output looks quiet interesting, for many price analysts (Those who look only at price & the patterns) the statistics might be difficult to fathom &/or reconstruct due to limited programming skills.
The idea is to construct an indicator, more or less on lines below (Am attaching the image as well as the code)
_SECTION_BEGIN("MA Tags");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
EMADiff = C-EMA(P,Periods);
EMADiffPer = EMADiff / C * 100;
Plot(EMADiffPer,_DEFAULT_NAME(),ParamColor( "Color", colorCycle ),styleLine);
Plot(10,"10 L",colorRed,styleLine | styleNoTitle);
Plot(5,"5 L",colorBlack,styleLine | styleNoTitle);
Plot(3,"3 L",colorBlue,styleLine | styleNoTitle | styleDashed);
Plot(0,"0 L",colorBlack,styleLine | styleNoTitle);
Plot(-3,"-3 L",colorBlue,styleLine | styleNoTitle | styleDashed);
Plot(-5,"-5 L",colorBlack,styleLine | styleNoTitle);
Plot(-10,"-10 L",colorRed,styleLine | styleNoTitle);
_SECTION_END();
What we want to now superimpose is the bell curve (Horizontally in this case) over the period visble in the chart.
Part 2 is constructing an exploration that gives the spread of number of stocks in a watchlist that are within a range of percentages from the 200 EMA.
For this I am reproducing the code that plots the number of stocks above the MAs 20-50-200
_SECTION_BEGIN("Moving Avergae 20-50-200");
/// Set symbol list in Analysis Filter - Include
/// And enable pad&align
/// Set Periodicity in analysis General settings
/// Create composite ARRAY via SCAN
/// @link https://forum.amibroker.com/t/percentage-stock-price-nyse-above-the-200-day-moving-average/19377/8
/// by AmiBroker.com and fxshrat@gmail.com
list_name = CategoryGetName(categoryGroup, 5);
symbol_name = "~AboveMA_"+list_name;
cnt = "~cnt_"+list_name;
periods = MxFromString("[20;50;200]");// MA periods
rows = MxGetSize(periods, 0);
persist = False;
if ( Status( "action" ) == actionScan )
{
/// derived from AB manual
/// @link https://www.amibroker.com/guide/afl/staticvaradd.html
if ( Status( "stocknum" ) == 0 )
{
// remove any earier composite values
StaticVarRemove(symbol_name+"*");
StaticVarRemove(cnt);
}
// Iterating periods
for ( i = 0; i < rows; i++ )
StaticVarAdd(symbol_name+"_"+ i, C >= MA(C, periods[i][0]), True, persist);
StaticVarAdd(cnt, 1, True, persist);
Buy = 0;
}
AddColumn(C,"Close",1.2);
colors = "colorGreen,colorBlue,colorRed";
// New code for display_name
currentWatchlistIndex = GetOption("FilterIncludeWatchlist");
if (currentWatchlistIndex >= 0) {
display_name = CategoryGetName(categoryWatchlist, currentWatchlistIndex);
} else {
display_name = "No Watchlist Selected"; // Default text when no watchlist is selected
}
// Iterating periods
for ( i = 0; i < rows; i++ )
{
Stocks_aboveMA = Nz(StaticVarGet(symbol_name+"_"+i));
WeekStocks=ValueWhen(DayOfWeek() > Ref( DayOfWeek(),1),Stocks_aboveMA);
pcnt_aboveMA = Nz(StaticVarGet(symbol_name+"_"+i) / StaticVarGet(cnt))*100;
titles = StrFormat("Percentage > %g-day MA", periods[i][0]);
Plot(pcnt_aboveMA, "Percentage > " + periods[i][0] + "-day MA (" + display_name + ")", VarGet(StrExtract(colors,i)), styleThick);
Filter = 1;
AddColumn(Stocks_aboveMA,"Count+"+periods[i][0],1.0);
AddColumn(pcnt_aboveMA,"Percent"+periods[i][0],1.2);
}
Plot(10,"10 L",colorBlack,styleLine | styleNoTitle);
Plot(30,"30 L",colorBlue,styleLine | styleNoTitle | styleDashed);
Plot(50,"50 L",colorBlack,styleLine | styleNoTitle);
Plot(70,"70 L",colorBlue,styleLine | styleNoTitle | styleDashed);
Plot(90,"90 L",colorBlack,styleLine | styleNoTitle);
SetSortColumns(-2);
_SECTION_END();
Courtesy @fxshrat