Announcement

Collapse
No announcement yet.

Outputting Dates in EasyLanguage

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Outputting Dates in EasyLanguage

    This article gives some tips and examples for outputting dates in EasyLanguage. Relevant EasyLanguage Date reserved words


    Just as a reminder, the following Date reserved words are often used in working with dates:
    • Date, which returns the Date of the current bar in YYYMMdd format. This date format is always the format with which a date calculation starts.
    • CurrentDate, returns the current computer date in YYYMMdd format.
    • ELDateToDateTime, converts a date in YYmmdd format to a date into DateTime format.

    See the Date & Time Routines for all EasyLanguage reserved words. Outputting the date


    The following example prints the current date to the PowerLanguage Editor log:
    Print("The current date is: ", CurrentDate);
    Which returns the following sentence: The current date is: 1120127.00.

    To output the date in a more readable format, the reserved word FormatDate is needed. However, FormatDate requires that the date is in DateTime format, while the default Date is in YYYMMdd format. So, a conversion to DateTime is needed first. This is done with the ELDateToDateTime reserved word.
    The code example below shows in detail which steps needs to be made.

    Variables:
    dateToday(0), dateInDateTimeFormat(0), dateReadable("");

    // 1. Assign the date of today to the variable 'dateToday'
    dateToday = CurrentDate;
    Print("The current date in YYYMMdd format is: ", dateToday, NewLine);

    // 2. Now, convert the date to DateTime format
    dateInDateTimeFormat = ELDateToDateTime(dateToday);
    Print("The current date in DateTime format is: ", NumToStr(dateInDateTimeFormat, 5), NewLine);

    // 3. Now we can print the current date in a more readable format
    dateReadable = FormatDate("dd-MM-yyyy", dateInDateTimeFormat);
    Print("The current date in a readable format is: ", dateReadable);
    This returns the following:

    The current date in YYYMMdd format is: 1120127.00

    The current date in DateTime format is: 40935.00000

    The current date in a readable format is: 27-01-2012
    Of course, not all these steps are needed. The extensive above example can be rewritten to simply:

    Print("The current date in a readable format is: ", FormatDate("dd-MM-yyyy", ELDateToDateTime(CurrentDate)));
    Which returns:

    The current date in a readable format is: 27-01-2012
    Outputting the date in different formats
    The FormatDate reserved word has a parameter string by which different date outputs can be generated. For example, in the code above we used "dd-MM-yyyy" to return "27-1-2012".

    The code example below shows some of these parameter options for FormatDate (see the FormatDate article for an extensive list of parameter options).

    Variables:
    dateInDateTime(0);

    dateInDateTime = ELDateToDateTime(CurrentDate);

    Print("Date in short version: ", FormatDate("d-M-y", dateInDateTime), NewLine);

    // Note: the output of the following statement depends on your regionale
    Print("Date in abbreviations: ", FormatDate("ddd-MMM-yy", dateInDateTime), NewLine);

    Print("Date fully written: ", FormatDate("dddd MMMM yyyy", dateInDateTime), NewLine);

    Print("Date in a sentence: ",
    FormatDate("The current Date is dddd anD the month is MMMM (which is month #MM). The Year is yyyy.", dateInDateTime));

    end;
    This gives the following output:

    Date in short version: 27-1-12

    Date in abbreviations: vr-jan-12

    Date fully written: vrijdag januari 2012

    Date in a sentence: The current Date is vrijdag anD the month is januari (which is month #01). The Year is 2012.

Disclaimer: There is a risk of loss in trading futures, forex and options. Futures, forex and options trading are not appropriate for all investors. Only risk capital should be used when trading futures. All information is for educational use only and is not investment advice. Past performance is not indicative of future results.

This website is hosted and operated by AMP Global Clearing, LLC ("AMP"), which provides brokerage services to traders of futures and foreign exchange products. This website is intended for customer support, educational and informational purposes only and should NOT be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by AMP and the information made available on this Web site is NOT an offer or solicitation of any kind. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of AMP.

All Users and Contributors along with their websites, products and services, are independent persons or companies that are in no manner affiliated with AMP. AMP is not responsible for, do not approve, recommend or endorse any User and/or Contributor Content referenced on this website and it’s your sole responsibility to evaluate All Content. Please be aware that any performance information provided by a user and/or contributor should be considered hypothetical.

HYPOTHETICAL PERFORMANCE RESULTS HAVE MANY INHERENT LIMITATIONS, SOME OF WHICH ARE DESCRIBED BELOW. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFITS OR LOSSES SIMILAR TO THOSE SHOWN. IN FACT, THERE ARE FREQUENTLY SHARP DIFFERENCES BETWEEN HYPOTHETICAL PERFORMANCE RESULTS AND THE ACTUAL RESULTS SUBSEQUENTLY ACHIEVED BY ANY PARTICULAR TRADING PROGRAM.

ONE OF THE LIMITATIONS OF HYPOTHETICAL PERFORMANCE RESULTS IS THAT THEY ARE GENERALLY PREPARED WITH THE BENEFIT OF HINDSIGHT. IN ADDITION, HYPOTHETICAL TRADING DOES NOT INVOLVE FINANCIAL RISK, AND NO HYPOTHETICAL TRADING RECORD CAN COMPLETELY ACCOUNT FOR THE IMPACT OF FINANCIAL RISK IN ACTUAL TRADING. FOR EXAMPLE, THE ABILITY TO WITHSTAND LOSSES OR TO ADHERE TO A PARTICULAR TRADING PROGRAM IN SPITE OF TRADING LOSSES ARE MATERIAL POINTS WHICH CAN ALSO ADVERSELY AFFECT ACTUAL TRADING RESULTS. THERE ARE NUMEROUS OTHER FACTORS RELATED TO THE MARKETS IN GENERAL OR TO THE IMPLEMENTATION OF ANY SPECIFIC TRADING PROGRAM WHICH CANNOT BE FULLY ACCOUNTED FOR IN THE PREPARATION OF HYPOTHETICAL PERFORMANCE RESULTS AND ALL OF WHICH CAN ADVERSELY AFFECT ACTUAL TRADING RESULTS.

AMP has NOT endorsed or recommended the use any product, services offered by any 3rd party User or Contributor on this forum. No person employed by, or associated with, AMP is authorized to provide any information about any 3rd party User or Contributor content. All specific brokerage related questions should be directed towards AMP.

Copyright © 2017. All rights reserved.

Working...
X