How do I graph an Exploration

I'm working on an Exploration for groups of stocks and ETF's of their Closing prices above 10 day MA, 21 day MA, 50 day MA and 200 Day MA. and I would like to graph the results over a long period of time, to look for Trends.

Is there a way to graph/plot the AddSummaryRows ? Thank you for your time in advance.

All the best, Bonz

/////////////////MA TrendScore ////////////////////

//Moving Averages of the Close
MA10  = MA(Close, 10);
MA21  = MA(Close, 21);
MA50  = MA(Close, 50);
MA130 = MA(Close, 130);
MA200 = MA(Close, 200);

//Close verses the Moving Averages
Trend10 = IIf(Close>=(MA10),1,0);
Trend21 = IIf(Close>=(MA21),1,0);
Trend50 = IIf(Close>=(MA50),1,0);
Trend130 = IIf(Close>=(MA130),1,0);
Trend200 = IIf(Close>=(MA200),1,0);



//AddColumn(TrendScore, "Trend Score", 1.2);
AddColumn(Trend10, "Trend10", 1);
AddColumn(Trend21, "Trend21", 1);
AddColumn(Trend50, "Trend50", 1);
AddColumn(Trend130, "Trend130", 1);
AddColumn(Trend200, "Trend200", 1);

AddSummaryRows(3);



Filter=1;

SetSortColumns(0);
AddRankColumn();

Moderator comment: added required code tags

First of all please read "How to use this site" to get to know how to use code tags. They are mandatory features if adding code.

Secondly as for your question.

AddSummaryRows does not return values. It just outputs to exploration.
So you have to replicate its results via AFL.
As for plotting one can use XYChart* functions.

/// @link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490
////////////////MA TrendScore ////////////////////

//Moving Averages of the Close
MA10 = MA(Close, 10);
MA21 = MA(Close, 21);
MA50 = MA(Close, 50);
MA130 = MA(Close, 130);
MA200 = MA(Close, 200);

//Close verses the Moving Averages
Trend1 = Close>=(MA10);
Trend2 = Close>=(MA21);
Trend3 = Close>=(MA50);
Trend4 = Close>=(MA130);
Trend5 = Close>=(MA200);

AddSummaryRows(3);

Filter=1;

SetSortColumns(0);
AddRankColumn();

//AddColumn(TrendScore, "Trend Score", 1.2);
AddColumn(Trend1, "Trend10", 1);
AddColumn(Trend2, "Trend21", 1);
AddColumn(Trend3, "Trend50", 1);
AddColumn(Trend4, "Trend130", 1);
AddColumn(Trend5, "Trend200", 1);


/// @link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490/2
/// code to replicate & plot AddsummaryRows function's "Total" and "Average"
/// by fxshrat@gmail.com
lbr = Status("lastbarinrange");
lbi = LastValue(ValueWhen(lbr, BarIndex()));
bir = Status( "barinrange" );
cs_bir = Cum(bir);

mat = Matrix( 2, 5 );
for ( j = 0; j < 5; j++ ) {
	trend = VarGet("Trend"+(j+1));	
	total = Cum(IIf( bir, Nz(trend), 0));
	mat[0][j] = total[lbi]; 
	mat[1][j] = mat[0][j]/cs_bir[lbi]; 
}

colnum = MxGetSize(mat,1);

XYChartSetAxis( chartname ="Total", "[Columns]", "[Total]", chartStyle = styleHistogram );
for ( j = 0; j < colnum; j++ ) 		
	XYChartAddPoint( chartname, "", j+1, mat[0][j], colorGreen );	

XYChartSetAxis( chartname = "Average", "[Columns]", "[Average]", chartStyle = styleLine | styleDots );
for ( j = 0; j < colnum; j++ ) 		
	XYChartAddPoint( chartname, "", j+1, mat[1][j], colorGreen, colorGreen );		

1

2

5 Likes

Thanks fxshrat ,

I see the code button now! Sorry. Just a new guy self learning is a bit slow...

All the best, Bonz

1 Like

@bonz you have an excellent answer from @fxshrat but I interpreted your question somewhat differently. What information from the SummaryRows are you really interested in plotting?

So I tried a code which is similar to answers I've previously written on this forum, using StaticVarAdd, and at least it will give you something different to think about.

///@link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490

// Using StaticVarAdd and run EXPLORE
// pick watchlist in AA window

wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum );


if( Status( "stocknum" ) == 0 )
{
    // cleanup variables created in previous runs
    StaticVarRemove( "~Trend*" ); // should take care of all 5 "Trend" variables

    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {
        SetForeign( symbol );

        Trend1 = Close >= MA( Close, 10 );
        Trend2 = Close >= MA( Close, 21 );
        Trend3 = Close >= MA( Close, 50 );
        Trend4 = Close >= MA( Close, 130 );
        Trend5 = Close >= MA( Close, 200 );

        StaticVarAdd( "~Trend1", Trend1 );
        StaticVarAdd( "~Trend2", Trend2 );
        StaticVarAdd( "~Trend3", Trend3 );
        StaticVarAdd( "~Trend4", Trend4 );
        StaticVarAdd( "~Trend5", Trend5 );

        RestorePriceArrays();
    }
}

svTrend1 = StaticVarGet( "~Trend1" );
svTrend2 = StaticVarGet( "~Trend2" );
svTrend3 = StaticVarGet( "~Trend3" );
svTrend4 = StaticVarGet( "~Trend4" );
svTrend5 = StaticVarGet( "~Trend5" );


///////////////
// Explore
///////////////
Filter = Status( "stocknum" ) == 0 ;
SetOption( "NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn( svTrend1, "Number > ma(10)", 1.0 );
AddColumn( svTrend2, "Number > ma(21)", 1.0 );
AddColumn( svTrend3, "Number > ma(50)", 1.0 );
AddColumn( svTrend4, "Number > ma(130)", 1.0 );
AddColumn( svTrend5, "Number > ma(200)", 1.0 );


///////////////
// Chart
///////////////
Plot( svTrend1, "Number > ma(10)", colorRed, styleLine | styleThick );
Plot( svTrend2, "Number > ma(21)", colorRose, styleDashed );
Plot( svTrend3, "Number > ma(50)", colorlime, styledots );
Plot( svTrend4, "Number > ma(130)", colorOrange, styleLine );
Plot( svTrend5, "Number > ma(200)", colorlightBlue, styleLine );

And it produces a Plot like this (run on the Nasdaq 100 as an example)
image

Another possibility would be to calculate the percentage of your watch list that is above the various trend measures and plot those percentages.

4 Likes

The question is pretty clear... it asks for AddSummaryRows (function's output). Rows are not columns. Rows are horizontal.

1

The example of post #2 outputs per single symbol.

If he wants to run over multiple symbols to plot total and average per each symbol separately then all that is needed is adding Name() function to XYChart*.

/// @link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490
////////////////MA TrendScore ////////////////////

//Moving Averages of the Close
MA10 = MA(Close, 10);
MA21 = MA(Close, 21);
MA50 = MA(Close, 50);
MA130 = MA(Close, 130);
MA200 = MA(Close, 200);

//Close verses the Moving Averages
Trend1 = Close>=(MA10);
Trend2 = Close>=(MA21);
Trend3 = Close>=(MA50);
Trend4 = Close>=(MA130);
Trend5 = Close>=(MA200);

AddSummaryRows(3);

Filter=1;

SetSortColumns(0);
AddRankColumn();

//AddColumn(TrendScore, "Trend Score", 1.2);
AddColumn(Trend1, "Trend10", 1);
AddColumn(Trend2, "Trend21", 1);
AddColumn(Trend3, "Trend50", 1);
AddColumn(Trend4, "Trend130", 1);
AddColumn(Trend5, "Trend200", 1);


/// @link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490/5
/// code to replicate & plot AddsummaryRows function's "Total" and "Average"
/// by fxshrat@gmail.com
lbr = Status("lastbarinrange");
lbi = LastValue(ValueWhen(lbr, BarIndex()));
bir = Status( "barinrange" );
cs_bir = Cum(bir);
nm = Name();

mat = Matrix( 2, 5 );
for ( j = 0; j < 5; j++ ) {
	trend = VarGet("Trend"+(j+1));	
	total = Cum(IIf( bir, Nz(trend), 0));
	mat[0][j] = total[lbi]; 
	mat[1][j] = mat[0][j]/cs_bir[lbi]; 
}

colnum = MxGetSize(mat,1);

XYChartSetAxis( chartname ="Total_"+nm, "[Columns]", "[Total "+ nm +"]", chartStyle = styleHistogram );
for ( j = 0; j < colnum; j++ ) 		
	XYChartAddPoint( chartname, "", j+1, mat[0][j], colorGreen );	

XYChartSetAxis( chartname = "Average_"+nm, "[Columns]", "[Average "+ nm +"]", chartStyle = styleLine | styleDots );
for ( j = 0; j < colnum; j++ ) 		
	XYChartAddPoint( chartname, "", j+1, mat[1][j], colorGreen, colorGreen );	

2

1 Like

And of course (if it is not thousands of symbols) you could also plot all AddSummaryRows results of each symbol into single exploration chart.

/// @link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490
////////////////MA TrendScore ////////////////////

//Moving Averages of the Close
MA10 = MA(Close, 10);
MA21 = MA(Close, 21);
MA50 = MA(Close, 50);
MA130 = MA(Close, 130);
MA200 = MA(Close, 200);

//Close verses the Moving Averages
Trend1 = Close>=(MA10);
Trend2 = Close>=(MA21);
Trend3 = Close>=(MA50);
Trend4 = Close>=(MA130);
Trend5 = Close>=(MA200);

AddSummaryRows(3);

Filter=1;

SetSortColumns(0);
AddRankColumn();

//AddColumn(TrendScore, "Trend Score", 1.2);
AddColumn(Trend1, "Trend10", 1);
AddColumn(Trend2, "Trend21", 1);
AddColumn(Trend3, "Trend50", 1);
AddColumn(Trend4, "Trend130", 1);
AddColumn(Trend5, "Trend200", 1);


/// @link https://forum.amibroker.com/t/how-do-i-graph-an-exploration/13490/6
/// code to replicate & plot AddsummaryRows function's "Total" and "Average"
/// by fxshrat@gmail.com
lbr = Status("lastbarinrange");
lbi = LastValue(ValueWhen(lbr, BarIndex()));
bir = Status( "barinrange" );
cs_bir = Cum(bir);
nm = Name();
stocknum = Status("stocknum");

mat = Matrix( 2, 5 );
for ( j = 0; j < 5; j++ ) {
	trend = VarGet("Trend"+(j+1));	
	total = Cum(IIf( bir, Nz(trend), 0));
	mat[0][j] = total[lbi]; 
	mat[1][j] = mat[0][j]/cs_bir[lbi]; 
}

colnum = MxGetSize(mat,1);
color = colorGold + ((2*stocknum) % 15);

XYChartSetAxis( chartname ="Total", "[Columns]", "[Total]", chartStyle = styleLine | styleDots  );
for ( j = 0; j < colnum; j++ ) 		
	XYChartAddPoint( chartname, WriteIf(j == colnum-1, nm, ""), j+1, mat[0][j], color, color );	
XYChartAddPoint( chartname, "", Null, Null );	

XYChartSetAxis( chartname = "Average", "[Columns]", "[Average]", chartStyle );
for ( j = 0; j < colnum; j++ ) 		
	XYChartAddPoint( chartname, WriteIf(j == colnum-1, nm, ""), j+1, mat[1][j], color, color );	
XYChartAddPoint( chartname, "", Null, Null );	

1

7 Likes

Thanks all for you input. I need more time in my AFL studies

Best, Bonz