Hello,
It is possible to do a explore to calculate the HistVol without using SetForeign (symbol) like here @fxshrat
@link Percentage Stock price nyse above the 200 day moving average
Thank you,
Carlos
// @fxshrat
// @link https://forum.amibroker.com/t/percentage-stock-price-nyse-above-the-200-day-moving-average/19377/5
// watchlist should contain all symbols included in the test
wlnum = 297; // GetOption( "FilterIncludeWatchlist" ); --> WatchList StocksIV
ListComp = CategoryGetSymbols( categoryWatchlist, wlnum ) ;
if( Status( "stocknum" ) == 0 )
{
// cleanup variables created in previous runs (if any)
StaticVarRemove( "rankIV*" );
StaticVarRemove( "valuesIV*" );
for( n = 0; ( Symbol = StrExtract( ListComp, n ) ) != ""; n++ )
{
SetForeign( symbol );
//Indicador de Ratio de Volatilidad
HistVol = StDev(log(close/Ref(close,-1)),10)/(StDev(log(close/Ref(close,-1)),100) + 1e-9 );
values = HistVol;
RestorePriceArrays();
// write ranked values to a static variable
StaticVarSet( "valuesIV" + symbol, values );
}
}
// perform ranking
StaticVarGenerateRanks( "rankIV", "valuesIV", 0, 1224 ); // normal rank mode
symbol = Name();
values = StaticVarGet( "valuesIV" + symbol );
rank = StaticVarGet( "rankIV" + "valuesIV" + symbol );
Plot(values, "Ratio Volatilidad 10/100", colorBlueGrey, styleLine|styleThick);
// Controla el filtro de búsqueda
// Seleccionar en 'Apply to' --> *Filter
if ( GetOption("ApplyTo") == 2 ) {
ListarComp = Param("Nº Valores a Listar",10,1,StrCount(ListComp,",")+1,1);
Filter = rank <= ListarComp ;
SetOption("NoDefaultColumns", True );
// exploration code for verification
AddColumn(DateTime(),"Fecha", formatDateTime);
AddTextColumn(Name(),"Ticker",0,colorDefault,colorDefault);
AddTextColumn(FullName(),"Nombre",0,colorDefault,colorDefault);
AddColumn( Nz(values), "IV",1.2,colorBlack,IIf(values>=0,colorGreen,colorRed));
AddColumn( rank, "Rank IV",1.0,colorDefault,colorDefault);
AddColumn(StrCount(ListComp,",")+1,"Nº. Comp.",1.0);
if( Status( "Action" ) == actionExplore )
SetSortColumns( 5 );
} else
if ( Status( "action" ) == actionExplore )
Error("Seleccionar en 'Apply to' --> *Filter --> Stocks IV");