• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

How to rename TOS aggregation period for labeling, e.g. "5 min" to "5m"


New member

I have the following which allows the user to select different aggregation period:

input timeframe = {"1 min", "2 min", "3 min", "4 min", "5 min", "10 min", "15 min", "20 min", "30 min", "1 hour", "2 hours", "4 hours", default "Day", "2 Days", "3 Days", "4 Days", "Week", "Month"};

I want to add a label on the chart that reflects the aggregation period selected, like below:

AddLabel(yes, timeframe, Color.GREEN);

What I really want is a short-hand writing of the aggregation period. For example, I want to show "2H" instead of "2 hours".

I tried to do that by creating another variable using a swtich statement, but the switch statement doesn't seem to work with strings.

def timeshort;
switch (timeframe) {
case "1 min":
timeshort = "1m";
case "2 min":
timeshort = "2m";

Does anyone know of a way to get around?

Thank-you very much!


Edit: Solve. Thank-you!
Last edited by a moderator:

Similar threads