Support Board
Date/Time: Fri, 14 Mar 2025 04:22:50 +0000
Find time to certain Date
View Count: 670
[2022-06-17 04:33:10] |
Trader_Rob - Posts: 18 |
I need to find the time/days to a given date. Is there a function that takes the difference between two different dates?. I just need to get the time until expiration for an option (which I pull from the symbol), so that I can calculate IV and delta. This needs to be accurate, so I cant just approximate the months with say 30 days. Is there a function that could do this? |
[2022-06-17 14:36:21] |
John - SC Support - Posts: 38653 |
You can do this using the Spreadsheet Study. The only trick is that how you enter the formula will depend on how the underlying data exists. For instance, in the Spreadsheet Study, you can find the time between any two bars just by subtracting them and multiplying by an appropriate factor (depending on what you want to get). For example, if you want the difference in seconds, then the formula would be: =(A10 - A5) * 86400 Times within Sierra Chart are stored such that the integer portion is days and the fractional portion is the fraction of a day. Therefore, there are 86400 seconds in one day which is why the above gives the number of seconds. Refer to the following: Spreadsheet Functions: Serial DateTime Values The other, for instance, is when the data is not already in a stored date format. In which case, you will first need to convert the value to the stored format. There are different spreadsheet functions to convert the information depending on what you need, but refer to the information for the TIMEVALUE() function at the following link which converts a text date and time to the internal information: https://www.sierrachart.com/index.php?page=doc/SpreadsheetFunctions.html#TIMEVALUE_Function For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2022-06-17 22:08:54] |
Trader_Rob - Posts: 18 |
Thanks for the advice! I ended up tackling this a different way by using some functions included with the SDDateTime data structure: struct Date {
int d, m, y; }; // This function returns number of // days between two given dates int getDifference(Date dt1, Date dt2) { SCDateTime Date1; SCDateTime Date2; Date1.SetDateYMD(dt1.y, dt1.m, dt1.d); Date2.SetDateYMD(dt2.y, dt2.m, dt2.d); int iDifference = 0; for (iDifference; Date1 != Date2 && iDifference < 10000; iDifference++) Date1.AddDays(1); return(iDifference); } int GetWorkdayDifference(Date dt1, Date dt2) { SCDateTime Date1; SCDateTime Date2; Date1.SetDateYMD(dt1.y, dt1.m, dt1.d); Date2.SetDateYMD(dt2.y, dt2.m, dt2.d); int iWDDifference = 0; for (int i = 0; Date1 != Date2 && i < 10000; i++) { Date1.AddDays(1); if (!Date1.IsWeekend()) iWDDifference++; } return(iWDDifference); } I hope this helps someone else in the future! I recommend doing some testing to ensure it's working as intended. I also needed the time difference, so I simply subtracted the current time from the end time. Date Time Of Last Edit: 2022-06-17 22:11:39
|
To post a message in this thread, you need to log in with your Sierra Chart account: