Login Page - Create Account

Support Board


Date/Time: Mon, 01 Jul 2024 21:10:45 +0000



Post From: Time Zone and Evening Trading Session

[2023-03-16 09:41:48]
User431178 - Posts: 439
Variation on above with selectable time zones.


// The top of every source code file must include this line
#include "sierrachart.h"


// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("Display New York and Local Times")

//This is the basic framework of a study function. Change the name 'DisplayTimes' to what you require.
SCSFExport scsf_DisplayTimes(SCStudyInterfaceRef sc)
{
auto& DisplayDate = sc.Input[0];
auto& DisplayWeekday = sc.Input[1];
auto& Horizontal = sc.Input[2];
auto& Vertical = sc.Input[3];

auto& TimeZone1 = sc.Input[4];
auto& TimeZone2 = sc.Input[5];

auto& TextSizeColor = sc.Subgraph[0];

if (sc.SetDefaults)
{
sc.GraphName = "Display Times";
sc.AutoLoop = 0;
sc.GraphRegion = 0;

TextSizeColor.Name = "Adjust Text Size and Color";
TextSizeColor.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
TextSizeColor.PrimaryColor = RGB(225, 215, 185);
TextSizeColor.LineWidth = 10;

DisplayDate.Name = "Display Date";
DisplayDate.SetYesNo(0);

DisplayWeekday.Name = "Display Weekday";
DisplayWeekday.SetYesNo(0);

Horizontal.Name = "Horizontal Position (0-150)";
Horizontal.SetInt(5);
Horizontal.SetIntLimits(0, 150);

Vertical.Name = "Vertical Position (0-100)";
Vertical.SetInt(80);
Vertical.SetIntLimits(0, 100);

TimeZone1.Name = "Time Zone 1";
TimeZone1.SetTimeZone(TIMEZONE_NEW_YORK);

TimeZone2.Name = "Time Zone 2";
TimeZone2.SetTimeZone(TIMEZONE_LONDON);

return;
}

const auto dT1 = sc.IsReplayRunning()
? sc.ConvertDateTimeFromChartTimeZone(sc.LatestDateTimeForLastBar, TimeZone1.GetTimeZone())
: sc.ConvertDateTimeFromChartTimeZone(sc.CurrentSystemDateTime, TimeZone1.GetTimeZone());

const auto dT2 = sc.IsReplayRunning()
? sc.ConvertDateTimeFromChartTimeZone(sc.LatestDateTimeForLastBar, TimeZone2.GetTimeZone())
: sc.ConvertDateTimeFromChartTimeZone(sc.CurrentSystemDateTime, TimeZone2.GetTimeZone());

auto displayText = SCString{};

if (sc.IsReplayRunning())
displayText.AppendFormat("Chart Is Replaying ... \n\n");

if (DisplayDate.GetYesNo())
displayText.AppendFormat("%s %d ", SHORT_NAME_FOR_MONTH[dT1.GetMonth()], dT1.GetDay());

if (DisplayWeekday.GetYesNo())
displayText.AppendFormat("%s ", SHORT_NAME_FOR_DAY_OF_WEEK[dT1.GetDayOfWeek()]);

displayText.Append(sc.DateTimeToString(dT1, FLAG_DT_COMPLETE_TIME));
displayText.AppendFormat(" [%s]\n\n", TIME_ZONE_NAME_STRINGS[TimeZone1.GetTimeZone()]);

if (DisplayDate.GetYesNo())
displayText.AppendFormat("%s %d ", SHORT_NAME_FOR_MONTH[dT2.GetMonth()], dT2.GetDay());

if (DisplayWeekday.GetYesNo())
displayText.AppendFormat("%s ", SHORT_NAME_FOR_DAY_OF_WEEK[dT2.GetDayOfWeek()]);

displayText.Append(sc.DateTimeToString(dT2, FLAG_DT_COMPLETE_TIME));
displayText.AppendFormat(" [%s]\n\n", TIME_ZONE_NAME_STRINGS[TimeZone2.GetTimeZone()]);

sc.AddAndManageSingleTextUserDrawnDrawingForStudy(sc, 0, Horizontal.GetInt(), Vertical.GetInt(), TextSizeColor, 1, displayText, 1, 0, 0);
}

imagedisplaytimes.png / V - Attached On 2023-03-16 09:40:30 UTC - Size: 54.06 KB - 154 views