NexusFi: Find Your Edge


Home Menu

 





How to code Sierra Chart Study


Discussion in Trading Journals

Updated
      Top Posters
    1. looks_one tulanch with 6 posts (16 thanks)
    2. looks_two Grantx with 5 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 mkata with 1 posts (2 thanks)
    1. trending_up 4,178 views
    2. thumb_up 18 thanks given
    3. group 9 followers
    1. forum 12 posts
    2. attach_file 3 attachments




 
Search this Thread

How to code Sierra Chart Study

  #11 (permalink)
 mkata 
Columbus, OH
 
Experience: Intermediate
Platform: SierraChart
Trading: CL
Posts: 35 since May 2013
Thanks Given: 153
Thanks Received: 24


Grantx View Post
Can anyone help me out here? I am trying to set the starting point of a line to a specific date and time.
If I set my DateTime object to a date, how do I get Tool.BeginDateTime to accept it as a date?



SCDateTime GrantxDateTime;
GrantxDateTime.SetDateTime(2019, 06, 07, 10, 39, 0);

Tool.BeginDateTime = GrantxDateTime;
Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex];

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
32 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #12 (permalink)
 Grantx 
Reading UK
Legendary no drama Llama
 
Experience: None
Posts: 1,787 since Oct 2016
Thanks Given: 2,826
Thanks Received: 5,058


mkata View Post
SCDateTime GrantxDateTime;
GrantxDateTime.SetDateTime(2019, 06, 07, 10, 39, 0);

Tool.BeginDateTime = GrantxDateTime;
Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex];

Works

Had to use .SetDateTimeYMDHMS(2019, 06, 07, 14, 39, 0);

Thank you!

Visit my NexusFi Trade Journal Reply With Quote
  #13 (permalink)
 Grantx 
Reading UK
Legendary no drama Llama
 
Experience: None
Posts: 1,787 since Oct 2016
Thanks Given: 2,826
Thanks Received: 5,058


Hoping someone can help me out here. I am attempting to modify the 'High/Low for time period' study.
If I set the study to show the 1st hour of the US opening range, then it plots higher and lower lines on the chart. I would like the study to also reflect the difference between the high and low of that opening range.

You can see in the attached images what I mean. One image shows the standard study settings and the other one shows it with the text I am trying to add.

Here is the modified code. Everything I have added is commented with 'My stuff'.
You can see right at the bottom I calculate the high and low but then I dont know why the study does not add that data to the chart? I have added the drawstyle as text but why aint it showing?

 
Code
/*============================================================================
	Session high low
----------------------------------------------------------------------------*/
SCSFExport scsf_SessionHighLow(SCStudyInterfaceRef sc)
{
	SCSubgraphRef HighOfDay = sc.Subgraph[0];
	SCSubgraphRef LowOfDay = sc.Subgraph[1];
	//my stuff
	SCSubgraphRef HighLowRange = sc.Subgraph[2];;

	SCFloatArrayRef TimeRangeHigh = sc.Subgraph[0].Arrays[0];
	SCFloatArrayRef TimeRangeLow = sc.Subgraph[0].Arrays[1];
	SCFloatArrayRef DataRange = sc.Subgraph[0].Arrays[2];

	SCInputRef StartTime = sc.Input[0];
	SCInputRef EndTime = sc.Input[1];
	SCInputRef Version = sc.Input[2];
	SCInputRef InputDataHigh = sc.Input[3];
	SCInputRef InputDataLow = sc.Input[4];
	SCInputRef DisplayHighLowIncrementally = sc.Input[5];
	SCInputRef NumberDaysToCalculate = sc.Input[6];



	if (sc.SetDefaults)
	{
		sc.GraphName			= "High/Low for Time Period";
		sc.GraphRegion			= 0;
		sc.AutoLoop				= 0;
		
		HighOfDay.Name = "High";
		HighOfDay.DrawStyle = DRAWSTYLE_DASH;
		HighOfDay.PrimaryColor = RGB(0,255,0);
		HighOfDay.DrawZeros = false;
		
		LowOfDay.Name = "Low";
		LowOfDay.DrawStyle = DRAWSTYLE_DASH;
		LowOfDay.PrimaryColor = RGB(255,0,255);
		LowOfDay.DrawZeros = false;
		
		//My stuff:
		HighLowRange.Name = "Range";
		HighLowRange.DrawStyle = DRAWSTYLE_TEXT;
		HighLowRange.LineWidth = 8;
		HighLowRange.LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_RIGHT | LL_VALUE_ALIGN_CENTER;
		HighLowRange.PrimaryColor = RGB(0, 255, 0);

		StartTime.Name = "Start Time";
		//Set the start time to US session time 14:30
		StartTime.SetTime(52200);

		EndTime.Name = "End Time"; 
		//Set the start time to US session time 15:30
		EndTime.SetTime(55800); 

		InputDataHigh.Name = "Input Data High";
		InputDataHigh.SetInputDataIndex(SC_HIGH);

		InputDataLow.Name = "Input Data Low";
		InputDataLow.SetInputDataIndex(SC_LOW);

		DisplayHighLowIncrementally.Name = "Display High Low Incrementally";
		DisplayHighLowIncrementally.SetYesNo(false);

		NumberDaysToCalculate.Name= "Number Of Days To Calculate";
		NumberDaysToCalculate.SetInt(10000);

		Version.SetInt(2);

		return;
	}

	if(Version.GetInt() < 2 )
	{
		InputDataHigh.SetInputDataIndex(SC_HIGH);
		InputDataLow.SetInputDataIndex(SC_LOW);
		Version.SetInt(2);
	}

	if (NumberDaysToCalculate.GetInt() <= 0)
		NumberDaysToCalculate.SetInt(10000);

	int InputDataHighIndex = InputDataHigh.GetInputDataIndex();
	int InputDataLowIndex = InputDataLow.GetInputDataIndex();

	SCDateTime InStartTime = StartTime.GetDateTime();
	SCDateTime InEndTime = EndTime.GetDateTime();

	for(int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++)
	{
		SCDateTime DaysToCalculateStartDateTime = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.ArraySize-1]) - ( NumberDaysToCalculate.GetInt() - 1 );

		if (sc.BaseDateTimeIn[Index]  <  DaysToCalculateStartDateTime)
			continue;

		SCDateTime StartDateTime = 0;
		SCDateTime EndDateTime = 0;


		SCDateTime BarDate = sc.BaseDateTimeIn[Index].GetDate();
		if(InStartTime < InEndTime)
		{
			StartDateTime =  BarDate + InStartTime;
			EndDateTime = BarDate + InEndTime;
		}
		//Times are reversed and the current time is greater than or equal to the start time
		else if (sc.BaseDateTimeIn[Index].GetTimeInSeconds() >= InStartTime.GetTimeInSeconds() )
		{

			StartDateTime = BarDate + InStartTime;
			EndDateTime = BarDate + 1 + InEndTime;
		}
		//Times are reversed and the current time is less than or equal to the end time
		else if (sc.BaseDateTimeIn[Index].GetTimeInSeconds() <= InEndTime.GetTimeInSeconds() )
		{

			StartDateTime = BarDate + InStartTime - 1;
			EndDateTime = BarDate + InEndTime;
		}

		//Initial calculations or start of new time range
		if(Index == 0 || sc.BaseDateTimeIn[Index - 1] < StartDateTime)
		{
			TimeRangeHigh[Index] = -FLT_MAX;
			TimeRangeLow[Index] = FLT_MAX;
			//My stuff: This actually does fuckall
			DataRange[Index] = -FLT_MAX - FLT_MAX;
		}
		else
		{
			TimeRangeHigh[Index] = TimeRangeHigh[Index - 1];
			TimeRangeLow[Index] = TimeRangeLow[Index - 1];
		}

		//Outside of range
		if(sc.BaseDateTimeIn[Index] > EndDateTime || sc.BaseDateTimeIn[Index] < StartDateTime)
			continue;


		if(sc.BaseData[InputDataHighIndex].GetArraySize() > 0)
		{
			if(TimeRangeHigh[Index] < sc.BaseData[InputDataHighIndex][Index])
				TimeRangeHigh[Index] = sc.BaseData[InputDataHighIndex][Index];
		}
		else
		{

			if(TimeRangeHigh[Index] < sc.BaseData[0][Index])
				TimeRangeHigh[Index] = sc.BaseData[0][Index];
		}

		if(sc.BaseData[InputDataLowIndex].GetArraySize() > 0)
		{
			if(TimeRangeLow[Index] > sc.BaseData[InputDataLowIndex][Index])
				TimeRangeLow[Index] = sc.BaseData[InputDataLowIndex][Index];
		}
		else
		{
			if(TimeRangeLow[Index] < sc.BaseData[0][Index])
				TimeRangeLow[Index] = sc.BaseData[0][Index];
		}

		if (DisplayHighLowIncrementally.GetYesNo())
		{

			HighOfDay[Index] = TimeRangeHigh[Index];
			LowOfDay[Index] = TimeRangeLow[Index];
			My stuff: This also does fuckall
                        HighLowRange[Index] = DataRange[Index];
		}
		else
		{
			int	BackIndex = Index;

			while(true)
			{
				if(BackIndex < 0)
					break;

				SCDateTime IndexDateTime = sc.BaseDateTimeIn[BackIndex];

				if(IndexDateTime < StartDateTime)
					break;

				HighOfDay[BackIndex] = TimeRangeHigh[Index];
				LowOfDay[BackIndex] = TimeRangeLow[Index];
				
				//My stuff:
				float Openprice = sc.BaseDataIn[SC_OPEN][Index];
				float HighPrice = sc.BaseDataIn[SC_HIGH][Index];
				float LowPrice = sc.BaseDataIn[SC_LOW][Index];
				float ClosePrice = sc.BaseDataIn[SC_LAST][Index];
				DataRange[Index] = HighPrice - LowPrice;


				BackIndex--;

				if(sc.UpdateStartIndex != 0)
					sc.EarliestUpdateSubgraphDataArrayIndex = BackIndex;
			}
		}

	}
}

Attached Thumbnails
Click image for larger version

Name:	2019-06-14_16-55-232.png
Views:	217
Size:	24.3 KB
ID:	266840   Click image for larger version

Name:	2019-06-14_16-55-23.png
Views:	229
Size:	23.0 KB
ID:	266841  
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 14, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts