When using a daily time frame for a scans you can only look back 2 years. You will have to move to the Monthly time frame to go back further. But even the monthly time frame is limited to only 20 years. And using the daily time frame makes this code much easier to write.
If you are looking for details about these data limitations for scans you can find them here, at the bottom of the following wegpage:
I updated the title of your question to help it show up in the search results for any viewers that just might be looking for this. It certainly is well off the path most traders are thinking.
The following code will only work as you requested if the scan is set to Monthly time frame:
input threshold = 75.0;
input monthNumber = 1;
def targetMonth = GetMonth() == monthNumber;
def upBar = close > open;
def markUpMonths = if targetMonth then upBar else 0;
rec countTargetMonths = if targetMonth then countTargetMonths + 1 else countTargetMonths;
rec countUpMonths = if markUpMonths then countUpMonths + 1 else countUpMonths;
def keyMetric = 100 * (countUpMonths / countTargetMonths);
plot scan = keyMetric > threshold;
I have included user inputs to allow viewers to adjust the percent threshold and the month number without modifying the code.