The direct answer to you question, how to reference the most recent value of a variable.
def lastValueOfN = n;
However since this is such an obvious answer and your code already contains this exact solution I perceive that you asking for something a bit different. What I perceive you are asking for, "not values from all its previous bars", is that you want to grab the value of "n" for the last bar on the chart. Then use that value for all the bars on the chart. If that is the case then this is how you do it:
def lastBar = IsNaN(close[-1]) and !IsNaN(close);
def closeOfLastBar = if lastBar then close else 0;
def fixedValueOfLastBar = HighestAll(closeOfLastBar);
The final line in that snippet will contain the close of the last bar on the chart and that variable will contain that same value for every bar on the chart. As you can see I am a fan of verbose variable names. I don't approve of variable names that are abbreviated more than required. Single character variable names make the code very difficult to read and maintain. I say this for the benefit of the rest of our viewers who are just learning how to write code. You do whatever you want for your own purposes.
Keep in mind that this solution is NOT: "reference a variable’s most recent bar value" as stated in the title of your question. So I really am taking a stab in the dark here. Please provide clarifications if this is not what you are requesting.
Note that this solution requires a variable that is never less than or equal to zero. If you have a variable that can vary above or below zero you will have to employ some additional methods to make this work.