3 Ways to Display Month Names in ThinkScript

ThinkScript, the powerful scripting language used in trading platforms like ThinkorSwim, offers a versatile toolkit for analyzing financial data and creating custom indicators. One intriguing aspect of ThinkScript is its ability to manipulate and display time-based information, including month names. In this article, we delve into three distinct methods for displaying month names in ThinkScript, exploring the syntax, practical examples, and the advantages each approach brings to the table.
Whether you're a seasoned trader or just starting out, understanding these techniques will empower you to create more informative and visually appealing charts, helping you make better-informed trading decisions. So, let's dive into the world of ThinkScript and discover how to harness the power of month names in your trading journey.
Method 1: Utilizing the DateToString Function

The DateToString function is a versatile tool in ThinkScript that allows you to convert date values into various string formats, including month names. This function provides a straightforward way to extract and display month names from your data. Here’s a breakdown of how to utilize this function effectively:
Syntax and Usage
The DateToString function follows a simple syntax:
DateToString(date, format)
Where:
- date is the input date value you want to convert.
- format is a string that specifies the desired output format. For month names, you'll typically use the "MMM" format specifier.
Example
Let's say you have a data set with a Date column containing date values, and you want to extract the month names from this column. Here's how you can achieve this using the DateToString function:
input Date = Date[0];
MonthName = DateToString(Date, "MMM");
In this example, Date[0] represents the current date or the date you're interested in. The DateToString function converts this date into a month name string, which is stored in the MonthName variable. You can then use this variable to display the month name in your indicator or study.
Advantages
Using the DateToString function offers several benefits:
- Flexibility: You can easily customize the output format by modifying the format parameter. This allows you to display month names in various styles, such as “MMM” for abbreviated names or “MMMM” for full month names.
- Simplicity: The function’s straightforward syntax makes it accessible to traders of all skill levels.
- Versatility: DateToString can be applied to various date-related tasks beyond month name extraction, making it a valuable tool in your ThinkScript toolkit.
Method 2: Custom Formatting with FormatDate

For traders seeking more advanced control over date formatting, the FormatDate function is an excellent choice. This function allows you to create custom date formats, including month names, using a flexible and expressive syntax. Let’s explore how to leverage the FormatDate function to display month names:
Syntax and Usage
The FormatDate function follows a syntax similar to that of the DateToString function:
FormatDate(date, format)
However, the format parameter in FormatDate is more flexible and allows for custom formatting. To display month names, you can use the "MMM" or "MMMM" format specifiers, just like in DateToString.
Example
To illustrate the use of FormatDate, consider the following example:
input Date = Date[0];
MonthName = FormatDate(Date, "MMM");
In this example, Date[0] represents the current date or the date you want to format. The FormatDate function takes this date and converts it into a month name string, using the "MMM" format specifier. The resulting month name is stored in the MonthName variable, which you can use in your indicator or study.
Advantages
The FormatDate function provides several advantages:
- Customizability: With FormatDate, you have fine-grained control over the date format. You can combine different format specifiers to create complex date strings, making it a powerful tool for traders who require precise date formatting.
- Flexibility: In addition to month names, FormatDate can be used to format other date components, such as days, years, or even custom date/time combinations.
- Expressiveness: The function’s syntax is intuitive and easy to understand, allowing traders to quickly create custom date formats without extensive coding knowledge.
Method 3: Extracting Month Names with MonthToString
ThinkScript offers yet another dedicated function for extracting month names: MonthToString. This function is specifically designed to convert month values into month name strings, providing a streamlined approach to displaying month names in your indicators.
Syntax and Usage
The MonthToString function follows a simple syntax:
MonthToString(month)
Where:
- month is the input month value you want to convert. It can be a numeric value (1-12) or a month name abbreviation (e.g., "Jan," "Feb," etc.).
Example
Suppose you have a data set with a Month column containing numeric month values, and you want to display the corresponding month names. Here's how you can use the MonthToString function:
input Month = Month[0];
MonthName = MonthToString(Month);
In this example, Month[0] represents the current month or the month value you're interested in. The MonthToString function converts this month value into a month name string, which is stored in the MonthName variable. You can then use this variable to display the month name in your indicator or study.
Advantages
Using the MonthToString function offers the following benefits:
- Simplicity: The function’s straightforward syntax makes it easy to integrate into your ThinkScript code.
- Dedicated Functionality: Being specifically designed for month name extraction, MonthToString provides a focused and efficient way to handle month-related tasks.
- Compatibility: This function is compatible with both numeric month values and month name abbreviations, offering flexibility in your data handling.
Conclusion: Choosing the Right Approach
Displaying month names in ThinkScript is a valuable skill for traders who want to enhance their chart analysis and indicator creation. Each of the three methods outlined in this article – DateToString, FormatDate, and MonthToString – offers unique advantages and caters to different trading needs. Whether you prefer a simple and straightforward approach or seek more advanced control over date formatting, ThinkScript provides the tools to achieve your goals.
By understanding and utilizing these methods, you can create visually appealing and informative charts, helping you make more confident trading decisions. Remember, the choice of method depends on your specific requirements and the nature of your data. So, choose wisely, and happy trading!
FAQ

Can I use these methods with custom date/time formats in ThinkScript?
+Absolutely! ThinkScript’s flexible date/time handling allows you to customize formats using the FormatDate function. You can combine different format specifiers to create custom date/time strings tailored to your needs.
Are there any limitations to the DateToString function when displaying month names?
+While DateToString is a powerful function, it may have limitations when dealing with non-standard date formats or custom date/time combinations. In such cases, the FormatDate function provides a more flexible solution.
Can I use the MonthToString function with month name abbreviations as input?
+Yes, the MonthToString function is designed to handle both numeric month values and month name abbreviations. This flexibility allows you to work with various types of month data.