Subgraphs - futures io
futures io futures trading



Subgraphs


Discussion in Sierra Chart

Updated by Big Mike
      Top Posters
    1. looks_one tomlryde with 4 posts (0 thanks)
    2. looks_two Nicolas11 with 3 posts (3 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Big Mike with 1 posts (0 thanks)
    1. trending_up 1,479 views
    2. thumb_up 4 thanks given
    3. group 3 followers
    1. forum 9 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Subgraphs

(login for full post details)
  #1 (permalink)
south bend, indiana
 
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

I am struggling a little to understand how sub graphs are used and work. Can anyone point me to a link on the Sierra web site or give me a quick explanation that will help me program and better utilize the language
Thanks
Tomlryde

Reply With Quote

Can you help answer these questions
from other members on futures io?
Chart text fixed and move with time
NinjaTrader
Where can I trade BTC FUTURES, and what are margin amounts
Brokers
TOS script help - crossover with alerts - help please?
ThinkOrSwim
TOS script
ThinkOrSwim
FYI plot bug & workaround: changing color or width is delayed 1 bar
EasyLanguage Programming
 
 
(login for full post details)
  #3 (permalink)
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 837 received


You use a subgraph for any calculation you want to plot on the screen or any calculation where you want to be able to access prior bar(s) data. In the example below, for the high and low I didn't need to access prior bars calculations, so I simply defined them as floats. But for the Plot calculation, I wanted to be able to take the difference between the high and low for the current bar and high and low for the prior bar. To do that, I needed the PriorDifference calculation to be a subgraph so I could reference sc.Index-1.

 
Code
#include "sierrachart.h"

SCDLLName("Example") 
/*==========================================================================*/
SCSFExport scsf_Example(SCStudyInterfaceRef sc)
{
	SCSubgraphRef Plot	 	= sc.Subgraph[0];
	SCSubgraphRef PriorDifference    =  sc.Subgraph[1];

	// Set configuration variables
	if (sc.SetDefaults)
	{
		// Set the configuration and defaults
		sc.GraphName = "Example";
		sc.FreeDLL = 0;
		sc.AutoLoop = 1;
		
		Plot.Name = "Plot";
		Plot.DrawStyle = DRAWSTYLE_LINE;
		return;
	}
	
	// Do data processing
	
	float high = sc.High[sc.Index];
	float low = sc.Low[sc.Index];
	
	PriorDifference[sc.Index] = high-low;
	Plot[sc.Index] = PriorDifference[sc.Index] - PriorDiffference[sc.Index-1];

}

Reply With Quote
The following user says Thank You to vegasfoster for this post:
 
(login for full post details)
  #4 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,745 received

Hi,

Since PriorDifference is not plotted, I would personally use a https://www.sierrachart.com/index.php?l=doc/ACS_ArraysAndLooping.htmlsc.Subgraph[0].Arrays[], perhaps more suited to this kind of background calculation. But everybody has his/her own programming style!

Nicolas

Sent from my mobile phone with Tapatalk

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #5 (permalink)
south bend, indiana
 
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

Thank you very much, So a Subgraph is an array and every loop of the program puts the result in the subgraph relative the the Index value? I understand but do not quite understand how to best use them, or why some things need subraphs and some do not. Is there any sort of programmers manual available besides the Information on the Sierra web site? How many subgraphs does Sierra allow?

Thanks again

Tom

Reply With Quote
 
(login for full post details)
  #6 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,745 received

1. Yes, the Subgraph is an array. Its length is the same as the number of (price) bars on the screen.

The Subgraph basically corresponds to a one-line indicator. It stores the values of the said indicator, to be drawn on chart. For instance, if you want to display a stochastics, the subgraph will contain the value of the stochastics for each bar. If you need an average of the stochastics (to see stochastics crossover with signal line), you will use a second subgraph (in the same study) to store the value of this average.

Within the study, there are as many subgraphes as indicator "lines" to be displayed.

2. We could define as many as 60 subgraphes (documentation) within the same study. It means that a given study (indicator) can display as many as 60 lines (or other types of display). If, for any reason, it is not enough, we can always create a second study.

3. The procedure scsf_xxx of the studies is called once per bar for past bars, then at each update interval for real-time bars (documentation).

So, when scsf_xxx is called, it means that there is, either a new bar, or an update of the price of the current bar. So we have to modify the [sc.Index] value of the subgraph, since sc.Index is the index of the last bar.
We should not modify the values of the previous indexes of the subgraph (0, 1, ..., sc.Index-1), since they were calculated at previous calls of the function (except if we want an indicator which... repaints).

4. Have you looked at the "Step-By-Step Instructions to Create an Advanced Custom Study Function"? It contains a template of study.

You can also have a look within CustomStudies.cpp and Studies#.cpp which contains numerous examples of studies (more on that page).

5. I am not aware of the existence of a Sierra Chart "tutorial" or "manual" different from the on-line documentation.

6. If you are not very comfortable with programming, you can start with Sierra Chart's spreadsheets, which allow creating indicators on an Excel-like spreadsheets. Quite convenient!

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #7 (permalink)
south bend, indiana
 
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

Thank you very much Nicholas,

I am a fairly proficient C Programer but C++ is a bit different and some of the C++ syntax gives me a hard time but I seem to muddle through and get things done. Thank you for the subgraph explanation. I have combined all the examples in the Sierra Library into one file so I can easily search for examples. I am heading out of town for a week to visit my daughter in California. I will post a few examples of what I am trying to do. Well, I am trying to write a routine that compares previews bars MACD lines with current bars MACD. It is Different from corss over. Cross over is an event. Comparing MACD previos bar with current would be to examine if MACD lines crosses and then re-crossed on next bar giving you a false entry. I am struggling to understand the MACD arrays and why I can not access previews bars

if (MovingAverageType.GetMovAvgType()==MOVAVGTYPE_EXPONENTIAL)
sc.DataStartIndex = 2;
else
sc.DataStartIndex = MACDLength.GetInt() + max(FastLength.GetInt(), SlowLength.GetInt());

int i = sc.Index;
sc.MACD(sc.BaseDataIn[InputData.GetInputDataIndex()], MACD, i, FastLength.GetInt(), SlowLength.GetInt(), MACDLength.GetInt(), MovingAverageType.GetInt());

MovAvgOfMACD[i] = MACD.Arrays[2][i];
MACDDiff[i] = MACD.Arrays[3][i];
RefLine[i] = 0;
sc.Subgraph[7][i] = MACD.Arrays[2][i-1];
sc.Subgraph[8][i] = MACD.Arrays[3][i-1];


Thanks so much for your help. Hope your trades are profitable

Tom

Reply With Quote
 
(login for full post details)
  #8 (permalink)
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
 
Nicolas11's Avatar
 
Posts: 1,071 since Aug 2011
Thanks: 2,232 given, 1,745 received

I am not sure if there is a question in your last message.

If you need help on the code, it would be better than you post a fully compilable code, and explain more explicitly what "does not work" (expected result vs actual result).

Nicolas

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
(login for full post details)
  #9 (permalink)
south bend, indiana
 
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

I am at my wits end, simple MACD Cross over strategy
Below is the complete code I wrote for a simple MACD Cross over strategy (long) I then reversed the logic on the Buy sell entry trigger to have a short Strategy. It does not work and I am at my wits end ready to pull my hair our. I need your help to look it over and tell me where I went wrong on the short strategy. I hear how robust the Sierra Language is but it seems extremely temperamental. I have added one line of code to a strategy-- just on line and it completely changes the functionality of the code. It almost seems illogical. Someone please help me and clue me in.

Thanking you in advance

Tom

#include "sierrachart.h"



SCDLLName("9513help")

/********************************************************************
* *
* Tom MACD Long Combo *
* *
********************************************************************/

SCSFExport scsf_TomComboStrategyMACD(SCStudyInterfaceRef sc)
{
SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0];
SCSubgraphRef BuyExitSubgraph = sc.Subgraph[1];
SCSubgraphRef MACDData = sc.Subgraph[2];
SCSubgraphRef MovAvgOfMACD = sc.Subgraph[3];
SCSubgraphRef MACD = sc.Subgraph[4];
SCSubgraphRef MACDDiff = sc.Subgraph[5];




SCInputRef InputData = sc.Input[0];
SCInputRef FastLen = sc.Input[1];
SCInputRef SlowLen = sc.Input[2];
SCInputRef MACDLen = sc.Input[3];
SCInputRef MAType = sc.Input[4];
SCInputRef OffsetPercentInput = sc.Input[5];
SCInputRef Enabled = sc.Input[6];
SCInputRef TargetValue = sc.Input[9];
SCInputRef StopValue = sc.Input[10];
SCInputRef EntryLevelNum = sc.Input[11];




if (sc.SetDefaults)
{
// Set the configuration and defaults


sc.GraphName = "Tom MACD Strategy Long~";
sc.GraphRegion = 0; //Main chart region
sc.AutoLoop = 1;
sc.FreeDLL = 1;



BuyEntrySubgraph.Name = "Long Entry";
BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROWUP;
BuyEntrySubgraph.PrimaryColor = RGB(19, 101, 236);
BuyEntrySubgraph.LineWidth = 2;
BuyEntrySubgraph.DrawZeros = false;


BuyExitSubgraph.Name = "Long Exit";
BuyExitSubgraph.DrawStyle = DRAWSTYLE_ARROWDOWN;
BuyExitSubgraph.PrimaryColor = RGB(140, 209, 242);
BuyExitSubgraph.LineWidth = 2;
BuyExitSubgraph.DrawZeros = false;

Enabled.Name = "Enabled";
Enabled.SetYesNo(0);

TargetValue.Name = "Target Value - Points - 1/4 point incriments";
TargetValue.SetFloat(20.0f);

StopValue.Name = "Stop Value - Points - 1/4 point incriments";
StopValue.SetFloat(1.25f);

/************MACD*****************/

InputData.Name = "Input Data";
InputData.SetInputDataIndex(SC_LAST);

FastLen.Name ="Fast Moving Average Length";
FastLen.SetInt(5);
FastLen.SetIntLimits(1,MAX_STUDY_LENGTH);

SlowLen.Name = "Slow Moving Average Length";
SlowLen.SetInt(30);
SlowLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MACDLen.Name = "MACD Moving Average Length";
MACDLen.SetInt(9);
MACDLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MAType.Name = "Moving Average Type";
MAType.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL);

EntryLevelNum.Name = "Entry Level Below -0- Line"; //inactive in this code
EntryLevelNum.SetFloat(-1.0f);



sc.Input[15].Name = "Contracts to Buy";
sc.Input[15].SetInt(1);
sc.Input[15].SetIntLimits(1, 100);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// order stuff
sc.AllowMultipleEntriesInSameDirection = false;
sc.SupportReversals = false;
sc.SendOrdersToTradeService = false;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
sc.SupportAttachedOrdersForTrading = false;
sc.CancelAllOrdersOnEntriesAndReversals= false;
sc.AllowEntryWithWorkingOrders = false;
sc.CancelAllWorkingOrdersOnExit = false;
sc.AllowOnlyOneTradePerBar = true;
sc.MaintainTradeStatisticsAndTradesData = true;

return;
}

int Order_qty = sc.Input[15].GetInt();
sc.MaximumPositionAllowed = Order_qty;

//Do Study calculations ~~~~~~~~~~~~~~~

// MACD

sc.MACD(sc.BaseDataIn[InputData.GetInputDataIndex()], MACDData, sc.Index, FastLen.GetInt(), SlowLen.GetInt(), MACDLen.GetInt(), MAType.GetInt());
MovAvgOfMACD[sc.Index] = MACD.Arrays[2][sc.Index];
MACDDiff[sc.Index] = MACD.Arrays[3][sc.Index];
float LowerLine = sc.Input[11].GetFloat();




if (!Enabled.GetYesNo())
return;

SCFloatArrayRef Last = sc.Close;

// Get the Internal Position data to be used for position exit processing.
s_SCPositionData InternalPositionData;
sc.GetInternalPosition(InternalPositionData) ;
float LastTradePrice = sc.Close[sc.Index];
// Create an s_SCNewOrder object.
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = Order_qty; //Total contracts
NewOrder.OrderType = SCT_MARKET;



int cnt=0;
int i = sc.Index;
int Result;
int status = sc.GetBarHasClosedStatus(sc.UpdateStartIndex);



if ((sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_BOTTOM) && (status == BHCS_BAR_HAS_CLOSED))
{Result = sc.BuyEntry(NewOrder); // Buy Long
if (Result > 0)
BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index];
}
else { // exit routine
if (InternalPositionData.PositionQuantity > 0 &&
((LastTradePrice <= InternalPositionData.AveragePrice - StopValue.GetFloat()) ||
(sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_TOP)
))

{Result = sc.BuyExit(NewOrder); //Sell Long
if(Result>0)
BuyExitSubgraph[sc.Index] = sc.High[sc.Index];

}
}

/*********************************** End Long Order Entry/Exit ****************/

}



/********************************************************************
* *
* Tom MACD short Combo *
* *
********************************************************************/

SCSFExport scsf_TomComboShortStrategyMACD(SCStudyInterfaceRef sc)
{
SCSubgraphRef SellEntrySubgraph = sc.Subgraph[0];
SCSubgraphRef SellExitSubgraph = sc.Subgraph[1];
SCSubgraphRef MACDData = sc.Subgraph[2];
SCSubgraphRef MovAvgOfMACD = sc.Subgraph[3];
SCSubgraphRef MACD = sc.Subgraph[4];
SCSubgraphRef MACDDiff = sc.Subgraph[5];




SCInputRef InputData = sc.Input[0];
SCInputRef FastLen = sc.Input[1];
SCInputRef SlowLen = sc.Input[2];
SCInputRef MACDLen = sc.Input[3];
SCInputRef MAType = sc.Input[4];
SCInputRef OffsetPercentInput = sc.Input[5];
SCInputRef Enabled = sc.Input[6];
SCInputRef TargetValue = sc.Input[9];
SCInputRef StopValue = sc.Input[10];
SCInputRef EntryLevelNum = sc.Input[11];




if (sc.SetDefaults)
{
// Set the configuration and defaults


sc.GraphName = "Tom MACD Short Strategy ";
sc.GraphRegion = 0; //Main chart region
sc.AutoLoop = 1;
sc.FreeDLL = 1;



SellEntrySubgraph.Name = "Long Entry";
SellEntrySubgraph.DrawStyle = DRAWSTYLE_ARROWUP;
SellEntrySubgraph.PrimaryColor = RGB(19, 101, 236);
SellEntrySubgraph.LineWidth = 2;
SellEntrySubgraph.DrawZeros = false;


SellExitSubgraph.Name = "Long Exit";
SellExitSubgraph.DrawStyle = DRAWSTYLE_ARROWDOWN;
SellExitSubgraph.PrimaryColor = RGB(140, 209, 242);
SellExitSubgraph.LineWidth = 2;
SellExitSubgraph.DrawZeros = false;

Enabled.Name = "Enabled";
Enabled.SetYesNo(0);

TargetValue.Name = "Target Value - Points - 1/4 point incriments";
TargetValue.SetFloat(20.0f);

StopValue.Name = "Stop Value - Points - 1/4 point incriments";
StopValue.SetFloat(1.25f);

/************MACD*****************/

InputData.Name = "Input Data";
InputData.SetInputDataIndex(SC_LAST);

FastLen.Name ="Fast Moving Average Length";
FastLen.SetInt(5);
FastLen.SetIntLimits(1,MAX_STUDY_LENGTH);

SlowLen.Name = "Slow Moving Average Length";
SlowLen.SetInt(30);
SlowLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MACDLen.Name = "MACD Moving Average Length";
MACDLen.SetInt(9);
MACDLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MAType.Name = "Moving Average Type";
MAType.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL);

EntryLevelNum.Name = "Entry Level Below -0- Line"; //inactive in this code
EntryLevelNum.SetFloat(-1.0f);



sc.Input[15].Name = "Contracts to Sell";
sc.Input[15].SetInt(1);
sc.Input[15].SetIntLimits(1, 100);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// order stuff
sc.AllowMultipleEntriesInSameDirection = false;
sc.SupportReversals = false;
sc.SendOrdersToTradeService = false;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
sc.SupportAttachedOrdersForTrading = false;
sc.CancelAllOrdersOnEntriesAndReversals= false;
sc.AllowEntryWithWorkingOrders = false;
sc.CancelAllWorkingOrdersOnExit = false;
sc.AllowOnlyOneTradePerBar = true;
sc.MaintainTradeStatisticsAndTradesData = true;

return;
}

int Order_qty = sc.Input[15].GetInt();
sc.MaximumPositionAllowed = Order_qty;

//Do Study calculations ~~~~~~~~~~~~~~~

// MACD

sc.MACD(sc.BaseDataIn[InputData.GetInputDataIndex()], MACDData, sc.Index, FastLen.GetInt(), SlowLen.GetInt(), MACDLen.GetInt(), MAType.GetInt());
MovAvgOfMACD[sc.Index] = MACD.Arrays[2][sc.Index];
MACDDiff[sc.Index] = MACD.Arrays[3][sc.Index];
float LowerLine = sc.Input[11].GetFloat();




if (!Enabled.GetYesNo())
return;

SCFloatArrayRef Last = sc.Close;

// Get the Internal Position data to be used for position exit processing.
s_SCPositionData InternalPositionData;
sc.GetInternalPosition(InternalPositionData) ;
float LastTradePrice = sc.Close[sc.Index];
// Create an s_SCNewOrder object.
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = Order_qty; //Total contracts
NewOrder.OrderType = SCT_MARKET;



int cnt=0;
int i = sc.Index;
int Result;
int status = sc.GetBarHasClosedStatus(sc.UpdateStartIndex);



if ((sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_TOP) && (status == BHCS_BAR_HAS_CLOSED))
{Result = sc.SellEntry(NewOrder); // Sell Long
if (Result > 0)
SellEntrySubgraph[sc.Index] = sc.High[sc.Index];
}
else { // exit routine
if (InternalPositionData.PositionQuantity > 0 &&
((LastTradePrice <= InternalPositionData.AveragePrice + StopValue.GetFloat()) ||
(sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_BOTTOM)
))

{Result = sc.SellExit(NewOrder); //Sell Long
if(Result>0)
SellExitSubgraph[sc.Index] = sc.Low[sc.Index];

}
}

/*********************************** End Short Order Entry/Exit ****************/

}

Reply With Quote
 
(login for full post details)
  #10 (permalink)
Site Administrator
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 48,902 since Jun 2009
Thanks: 31,586 given, 94,527 received


@tomlryde,

1) Wrap long blocks of code in the [code] bbcode so someone doesn't have to scroll forever in your post.
2) You already have an existing thread on this, please do not cross-post/duplicate.



Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my Facebook Visit my futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators Sierra Chart > Subgraphs


September 5, 2013


Upcoming Webinars and Events
 

Every journal equals ten meals for the hungry

Now
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts