Well congratulations on getting the secondary aggregation period to work with those other indicators. The process is exactly the same for all indicators so I'm not sure why this one has tripped you up. The code you provided merely adds an input to contain the secondary aggregation period. The input is not applied anywhere in the code you provided. So that is the number one issue to address. If you add an input to a study, you need to wire that up so that it actually does something.
I see that you are trying to learn so I will go into a bit more detail to explain things rather simply provide a solution.
Properly Formatted Code Statements:
From your code we want to examine the following:
input period= Aggregationperiod.thirty_min;
First thing to mention. The word "period" is actually a keyword used to describe one of the input parameters of the price series data arrays. Which are: open, high, low, close, volume and a few others. Thinkorswim refers to these data arrays as "Fundamentals".
So we try to avoid using keywords as the names for inputs and variables. It's not required. But it makes the code easier to read, troubleshoot and maintain. So in place of the word "period" we'll use "timeFrame".
I will also clean up the code a bit. You did not properly apply the upper/lower case characters in your input statement. Again, this is not required as it would be an actual programming language. But it makes the code easier to read and maintain.
input timeFrame = AggregationPeriod.THIRTY_MIN;
The Solution:
Now that we have this patched up, we can get into the solution. Actually I don't need to explain things any further. I can simply provide you the link to the documentation in Thinkorswim and I'm done.
https://toslc.thinkorswim.com/center/reference/thinkScript/tutorials/Advanced/Chapter-11---Referencing-Secondary-Aggregation.html
Be sure to read through that documentation carefully. It will provide everything you need to know about referencing secondary aggregation periods. They employ a slightly different method than I prefer. However their technique provides the most flexibility. So we'll follow their lead in solving your particular request. (Hat Tip: I actually learned something new while writing this solution. Thanks for that. I LOVE to learn new things!)
Here are the two lines of code that require modifications to make use of the new "timeFrame" user input.
input price = close;
plot ROC = if price[length] != 0 then (price / price[length] – 1) * 100 else 0;
To those lines of code, we now apply the techniques taught in the documentation I linked above.
input price = FundamentalType.CLOSE;
plot ROC = if Fundamental(price, period = timeFrame)[length] != 0 then (Fundamental(price, period = timeFrame) / Fundamental(price, period = timeFrame)[length] – 1) * 100 else 0;
This solution allows the user input for "price" to be maintained. The solution I prefer requires that the "price" input be removed entirely. It makes the code easier to read and write. But it removes the ability to adjust the price from the user settings. (yes, I am very lazy and I cut corners wherever I find it appropriate)
I have attached a screenshot showing the results. The modified version is in the lower right subgraph. Compare that to the values in the lower subgraph to the left.