@Nick Radge thank you for your interest in my "PercentageUp" timing filter. I try not to talk in technical terms as this is a beginner's thread but for you, I can expand the explanation & construction of this filter.
The "PercentageUp Filter" calculates the percentage of stocks in a watchlist that have closed higher than their open price averaged over a nPeriod removing the weighting from each position in the watchlist. The code first gets the watchlist symbols & then loops through each symbol in the watchlist. For each symbol, the code sets the foreign symbol & calculates the percentage of bars where the close price is higher than the open price. The code then saves the total number of bars & the number of bars where the close price is higher than the open price to static variables.
The percentage of bars where the close price is higher than the open price is then calculated by dividing the number of bars where the close price is higher than the open price by the total number of bars & multiplying by 100. The code then sets the PercentageBullish variable to "True" if the percentage of bars where the close price is higher than the open price is greater than 50%, & sets the PercentageBearish variable to "True" if the percentage of bars where the close price is higher than the open price is less than 25.
Finally, the "PercentageUp" variable is set to "True" if the PercentageBullish variable is True. Each variable "PercentageBullish variable" & the "PercentageBearish" variable performs completely different functions within the strategy.
Simply, the "PercentageUp Filter" is constantly calculating the percentage of stocks in a watchlist that have a bullish or bearish trend based on their closing & opening prices. The "PercentageUp" code retrieves the user-defined value for the watchlist filter using the GetOption() function & assigns it to the variable. Then, it uses CategoryGetSymbols() function to retrieve a list of symbols in the watchlist specified by the categoryWatchlist argument.
Next, the code initialises variables Up, Total, & period to zero. The If statement then checks whether the Status() function returns zero for the parameters, indicating that the code is being executed for the first time. If so, the code enters a loop that iterates through each symbol in the watchlist using a "for loop".
Within the loop, the code sets the current symbol as the foreign symbol using the SetForeign() function, which prepares the AFL for working with data from that symbol. It then calculates the percentage increase in price by dividing the Close price by the Open price, & increments the Up variable if the result is greater than 1 (indicating a bullish trend). It also increments the period variable if the Close price is not null. Finally, the code restores the price arrays to their initial state using RestorePriceArrays().
After the loop has been completed, the code saves the values of the Up & period variables to static variables using the StaticVarSet() function. Convert that to a ribbon & it's easy to understand the timing of this filter.
XAO time stamp (27/3/2023 @1pm)
At times a picture paints a thousand words.
View attachment 155006
View attachment 155007
Skate.
Thank you Skate for sharing in detail this very Interesting indicator, despite having spend weeks searching this forum and read your detailed reply above, there is still things that is left for interpretation.
Please correct me where I am wrong in interpreting your text..
"The "PercentageUp Filter" calculates the percentage of stocks in a watchlist that have closed higher than their open price averaged over a nPeriod removing the weighting from each position in the watchlist. The code first gets the watchlist symbols & then loops through each symbol in the watchlist. For each symbol, the code sets the foreign symbol & calculates the percentage of bars where the close price is higher than the open price. The code then saves the total number of bars & the number of bars where the close price is higher than the open price to static variables.
The percentage of bars where the close price is higher than the open price is then calculated by dividing the number of bars where the close price is higher than the open price by the total number of bars & multiplying by 100. The code then sets the PercentageBullish variable to "True" if the percentage of bars where the close price is higher than the open price is greater than 50%, & sets the PercentageBearish variable to "True" if the percentage of bars where the close price is higher than the open price is less than 25."
1: You first calculate the percentage of stocks, in a watchlist, that have closed higher then open, and then you write "averaged over a nPeriod", May i ask, what is your definition of averaged ? the close and open ? or somehow the percentage you get period 1, period 2 and 3, etc is then averaged to get a total %?
2: You then take all the bars from the symbols in the watchlist, that exist for the used nPeriod (So if 100 symbols, and nPeriod is 2 weeks, that would be 200 weekly bars), and to get the (% Bullish number ) you then "dividing the number of bars where the close price is higher than the open price by the total number of bars & multiplying by 100", Have I understood your correctly?
Somehow here you get two % values, one for point 1, and one for point 2? I am sure I am misunderstanding something here.
Grateful for a clarification,
Thank you for sharing your ideas