
// 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("MyClockRealTime")

/*==========================================================================*/
//  changed name of study to MyClockRealTime
SCSFExport scsf_MyClockRealTime(SCStudyInterfaceRef sc)
{
	SCSubgraphRef Subgraph_Clock = sc.Subgraph[0];

	SCInputRef Input_HorizontalPosition = sc.Input[0];
	SCInputRef Input_VerticalPosition = sc.Input[1];
	SCInputRef Input_UseAMPM = sc.Input[3];
	SCInputRef Input_DrawAboveMainPriceGraph = sc.Input[4];
	SCInputRef Input_UseBoldFont = sc.Input[5];
	SCInputRef Input_TransparentLabelBackground = sc.Input[7];
	SCInputRef Input_HourOffset = sc.Input[8];
	// Line added below for MyTimeZone 		
	SCInputRef Input_MyTimeZone = sc.Input[9];

	if (sc.SetDefaults)
	{
		// Set the configuration and defaults
// Changed name of graph to My Clock - RealTime
		sc.GraphName = "MY Clock - RealTime";

		sc.AutoLoop = 0;//Manual looping
		sc.GraphRegion = 0;
		sc.ValueFormat = 0;
		sc.UpdateAlways = 1;
		// Changed name of graph to My Clock
		Subgraph_Clock.Name = "My Clock";
		Subgraph_Clock.LineWidth = 20;
		Subgraph_Clock.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
		Subgraph_Clock.PrimaryColor = RGB(0, 0, 0); //black
		Subgraph_Clock.SecondaryColor = RGB(255, 127, 0); //Orange
		Subgraph_Clock.SecondaryColorUsed = true;
		Subgraph_Clock.DisplayNameValueInWindowsFlags = 1;

		Input_HorizontalPosition.Name.Format("Initial Horizontal Position From Left (1-%d)", static_cast<int>(CHART_DRAWING_MAX_HORIZONTAL_AXIS_RELATIVE_POSITION));
		Input_HorizontalPosition.SetInt(20);
		Input_HorizontalPosition.SetIntLimits(1, static_cast<int>(CHART_DRAWING_MAX_HORIZONTAL_AXIS_RELATIVE_POSITION));

		Input_VerticalPosition.Name.Format("Initial Vertical Position From Bottom (1-%d)", static_cast<int>(CHART_DRAWING_MAX_VERTICAL_AXIS_RELATIVE_POSITION));
		Input_VerticalPosition.SetInt(90);
		Input_VerticalPosition.SetIntLimits(1, static_cast<int>(CHART_DRAWING_MAX_VERTICAL_AXIS_RELATIVE_POSITION));

		Input_UseAMPM.Name = "Use A.M. and P.M.";
		Input_UseAMPM.SetYesNo(false);

		Input_DrawAboveMainPriceGraph.Name = "Draw Above Main Price Graph";
		Input_DrawAboveMainPriceGraph.SetYesNo(false);

		Input_UseBoldFont.Name = "Use Bold Font";
		Input_UseBoldFont.SetYesNo(true);

		Input_TransparentLabelBackground.Name = "Transparent Label Background";
		Input_TransparentLabelBackground.SetYesNo(false);

		Input_HourOffset.Name = "Hour Offset";
		Input_HourOffset.SetInt(0);

		// 2 Lines added below for MyTimeZone 		
		Input_MyTimeZone.Name = "My Time Zone";
		Input_MyTimeZone.SetString("USA");

		return;
	}


	int Hour = 0, Minute = 0, Second = 0;
	if (sc.IsReplayRunning())
		SCDateTimeMS(sc.GetEndingDateTimeForBarIndex(sc.ArraySize - 1)).GetTimeHMS(Hour, Minute, Second);
	else
		sc.CurrentSystemDateTimeMS.GetTimeHMS(Hour, Minute, Second);

	if (Input_HourOffset.GetInt() != 0)
	{
		Hour += Input_HourOffset.GetInt();
		if (Hour > 24)
			Hour -= 24;
		else if (Hour < 0)
			Hour += 24;
	}

	SCString RemainingTimeString;
	if (Input_UseAMPM.GetYesNo())
	{
		int AdjustedHour = Hour;
		if (Hour >= 13)
			AdjustedHour -= 12;

		RemainingTimeString.Format("%d:%02d:%02d ", AdjustedHour, Minute, Second);
		if (Hour < 12)
			RemainingTimeString += "am";
		else
			RemainingTimeString += "pm";
	}
	else
		RemainingTimeString.Format("%d:%02d:%02d", Hour, Minute, Second);
	// Line added below for MyTimeZone 		
	RemainingTimeString += Input_MyTimeZone.GetString();

	int HorizontalPosition = Input_HorizontalPosition.GetInt();
	int VerticalPosition = Input_VerticalPosition.GetInt();

	int DrawAboveMainPriceGraph = Input_DrawAboveMainPriceGraph.GetYesNo();

	int TransparentLabelBackground = Input_TransparentLabelBackground.GetYesNo();
	int UseBoldFont = Input_UseBoldFont.GetYesNo();

	sc.AddAndManageSingleTextUserDrawnDrawingForStudy(sc, 0, HorizontalPosition, VerticalPosition, Subgraph_Clock, TransparentLabelBackground, RemainingTimeString, DrawAboveMainPriceGraph, 0, UseBoldFont);
}

/*==========================================================================*/
