Hi, I try to make the indicator show me the percentage of shares above the average of 200. This code makes me go through the list and I see the tape go down continuously, even, half slows down Ami. Sure there is a way to do it but I don't give. I download a list daily on my google drive and wish I could take it to my amibroker.
// Using StaticVarAdd and run EXPLORE
// pick watchlist in AA window
//wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryGroup, 5);
if( Status( "stocknum" ) == 0 )
// cleanup variables created in previous runs (if any)
StaticVarRemove( "~SymbolCount*" );
StaticVarRemove( "~above*" );
for( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
SetForeign( symbol );
above = C >= MA( C, 200 );
StaticVarAdd( "~SymbolCount", 1 );
StaticVarAdd( "~above", above );
ABOVEcomp = StaticVarGet( "~above" );
svSymbolCount = StaticVarGet( "~SymbolCount" );
PercentAbove = ( ABOVEcomp / svSymbolCount ) * 100;
// various Filter settings are possible depending on what you want your
// Exploration output to look like
Filter = Status( "stocknum" ) == 0 ;
SetOption( "NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn( svSymbolCount, "Total Number of Stocks", 1.0 );
AddColumn( ABOVEcomp, "Number>200 day ma", 1.0 );
AddColumn( PercentAbove, "Percentage > 200 day ma", 1.2 );
Plot( PercentAbove, "Percentage > 200 day ma", colorBlueGrey, styleThick );
There is a growing number of codes that abuse SetForeign in a loop. This is all wrong. Composites should NOT be re-calculated over and over again. They should be calculated JUST ONCE using process described in the manual: http://www.amibroker.com/guide/a_addtocomposite.html
StaticVarAdd may be added instead of AddToComposite BUT the procedure should stay the same, i.e. run scan ONCE to create static variable and don't use SetForeign AT ALL.
First of all, sorry if I haven't added the code and photo correctly but I think so.
The second, for simplicity, I just want an indicator that shows me, on the NYSE, the percentage of shares that are above the sma 200 . I have retouched the code avoiding the explorer's errors and changing what was proposed, but I didn't do it well.
Thanks for the help. I'm going to change the data necessary for it to work. I really have read the manual. I'm going to read again. But there are many things that you need to explain with examples and to be able to ask questions. For those who do not understand programming it is very difficult.
I was very interested to see the application of StaticVar in this afl as opposed to creating a composite symbol. In this afl, how would one have more than one instance of the afl on a particular chart as Technical Analysts like to look at the % stocks above 200, 50 and 10 day moving averages in one glance because the shape and position of each plot adds to the story? Creating more than one instance of this afl as it stands returns the latest used moving average scan in all the instances of the plots of this afl.
This code is very instructive in demonstrating the capabilities of StaticVarAdd and how to count the number of symbols in a watchlist. It has proven to be quite useful to me (thanks fxshrat) but I would also like it to produce an actual symbol that can be placed in a watchlist in addition to being plotted on a chart. I have tried to accomplish this by adding an AddToComposite line such as:
Running a Scan with this addition does produce a matching indicator that could be placed in a watchlist, however, when this symbol is displayed in a Price chart the scaling information on the right side is not scaled from 0% to 100% as I would like it to be. See below:
The top pane charts the indicator generated from AddToComposite and the lower one from the AFL Plot statement.
I have made multiple attempts to change the scaling for the upper pane using Remap and also with manual control through SetChartOptions, StyleOwnScale, etc., but none gave the desired result.
Any help on the best way to create a symbol that can be put in a watchlist and have its chart pane reflect the correct 0% to 100% scaling would be much appreciated.