Skip to content

Quick-tip 15 | How to format date and time using BarDateTime

This quick tip demonstrates how to format date and time in TradeStation. This quick tip is not relevant to MultiCharts.

Formatting date and time

This quick tip was created in TradeStation 9.5.

Using the EasyLanguage Date or D keyword in, for example, a print statement like:


Print( "Date ",D," Time ", T, " Close ", C:2:2 ); // e.g. Date 1171213.00 Time 1116.00 Close 2666.7500

Creates the date in the following format: YYMMDD or YYYMMDD. The potential problem is that year is represented  as the number of years since 1900, which can take a little bit of getting used to! TradeStation 9.5 does provide another way of calculating and displaying date and this is what I discuss in the following video. The program code from the video is included below.

Another potential problem is that using the Time or T keyword provides the time in an HHMM format. This can be problematic when using second or other charts with sub minute bar times. The video also included a discussion of this.

Quick-tips 15 indicator

{ THIS INDICATOR IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE,
RESULTING FROM THE USE OF THIS INFORMATION, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION IS AT YOUR OWN RISK.
THIS INDICATOR AND ASSOCIATED TECHNIQUES IS AN EXAMPLE ONLY, AND HAS BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION DOES NOT RECOMMEND
THAT YOU USE ANY SUCH TRADING STRATEGIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS
(OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF THIS INDICATOR DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.}

Once ClearPrintLog;

If LastBarOnChart then
Begin
Print( "Date ",D," Time ", T, " Close ", C:2:2 ); // e.g. Date 1171213.00 Time 1116.00 Close 2666.7500

Print( "Date ", BarDateTime.Format( "%Y%m%d.00" )," Time ", BarDateTime.Format( "%H%M.%S" ), " Close ", C:2:2 );

Print( BarDateTime.Format( "%a %b %d, %Y" ) ); // e.g. Wed Dec 13, 2017
Print( BarDateTime.Format( "%a %b %d, %Y" ) ); // e.g. Wed Dec 13, 2017
Print( BarDateTime.Format( "%H:%M:%S" ) ); // e.g. 11:15:02
Print( BarDateTime.Format( "%Hh%M:%S" ) ); // e.g. 11h39:25
Print( BarDateTime.Format( "%H:%M:%S %a %b %d, %Y" ) ); // e.g. 11:16:19 Wed Dec 13, 2017
Print( BarDateTime.Format( "%I:%M:%S %p" ) ); // 11:34:17 AM
Print( BarDateTime.Format( "%I:%M:%S " ), LowerStr( BarDateTime.Format( "%p" ) ) ); // 11:34:17 am
End;

{ ** Copyright (c) 2017 Markplex Corporation. All rights reserved. **
** Markplex Corporation reserves the right to modify or overwrite this analysis technique
on its https://markplex.com Web site. ** }