Subgraphs - Sierra Chart Programming | futures io social day trading
futures io futures trading


Subgraphs
Updated: Views / Replies:985 / 9
Created: by tomlryde Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Subgraphs

  #1 (permalink)
Trading Apprentice
south bend, indiana
 
Futures Experience: Intermediate
Platform: sierra charts
Favorite Futures: futures
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

Subgraphs

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
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 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:
 
  #4 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

Hi,

Since PriorDifference is not plotted, I would personally use a http://www.sierrachart.com/index.php?l=doc/doc_ACS_ArraysAndLooping.html#ArraysOverviewsc.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

Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #5 (permalink)
Trading Apprentice
south bend, indiana
 
Futures Experience: Intermediate
Platform: sierra charts
Favorite Futures: futures
 
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
 
  #6 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 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

Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #7 (permalink)
Trading Apprentice
south bend, indiana
 
Futures Experience: Intermediate
Platform: sierra charts
Favorite Futures: futures
 
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
 
  #8 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 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

Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #9 (permalink)
Trading Apprentice
south bend, indiana
 
Futures Experience: Intermediate
Platform: sierra charts
Favorite Futures: futures
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

Need help some help with short study.

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
 
  #10 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,218 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.

https://futures.io/sierra-chart-programming/28646-i-am-my-witts-end-simple-macd-cross-over-strategy.html

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote

Reply



futures io > > > > > Subgraphs

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Study Subgraphs Difference instead of MACD Reggy Sierra Chart 3 July 21st, 2011 09:25 PM


All times are GMT -4. The time now is 12:31 AM.

Copyright © 2017 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
Page generated 2017-12-11 in 0.18 seconds with 19 queries on phoenix via your IP 107.20.115.174