Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Modify SuperTrend
Updated May 31, 2018
Top Posters
looks_one
crazybears
with 5 posts (0 thanks)
looks_two
Renko123
with 5 posts (0 thanks)
looks_3
cory
with 2 posts (2 thanks)
looks_4
kathy11
with 1 posts (0 thanks)
trending_up
5,326 views
thumb_up
2 thanks given
group
4 followers
forum
12 posts
attach_file
4 attachments
Modify SuperTrend
August 7th, 2015, 01:35 AM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Could someone with more ability then me modify the supertrend indicator to plot only the uptrend?
I tried, had to accept that i couldn't get it working.
Thanks in advance.
Code
/*============================================================================
SuperTrend Stop study function.
----------------------------------------------------------------------------*/
SCSFExport scsf_SuperTrendStop(SCStudyInterfaceRef sc)
{
SCSubgraphRef Stop = sc.Subgraph[0];
SCSubgraphRef Median = sc.Subgraph[1];
SCFloatArrayRef TrueRange = Stop.Arrays[0];
SCFloatArrayRef AvgTrueRange = Stop.Arrays[1];
SCFloatArrayRef Trend = Stop.Arrays[2];
SCInputRef ATRMultiplier = sc.Input[0];
SCInputRef ATRPeriod = sc.Input[1];
SCInputRef MedianPeriod = sc.Input[2];
// Set configuration variables
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "SuperTrend Stop";
sc.StudyDescription = "";
sc.DrawZeros = false;
sc.GraphRegion = 0;
sc.ValueFormat = sc.BaseGraphValueFormat;
//During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
sc.FreeDLL = 0;
sc.AutoLoop = 1;
Stop.Name = "Stop";
Stop.DrawStyle = DRAWSTYLE_DASH;
Stop.LineWidth = 2;
Stop.PrimaryColor = COLOR_BLUE;
Stop.SecondaryColor = COLOR_RED;
Stop.SecondaryColorUsed = 1;
ATRMultiplier.Name = "ATR Multiplier";
ATRMultiplier.SetFloat(2);
ATRMultiplier.SetFloatLimits(0.000001f,(float)MAX_STUDY_LENGTH);
ATRPeriod.Name = "ATR Period";
ATRPeriod.SetInt(3);
ATRPeriod.SetIntLimits(1,MAX_STUDY_LENGTH);
MedianPeriod.Name = "Median Period";
MedianPeriod.SetInt(3);
MedianPeriod.SetIntLimits(1,MAX_STUDY_LENGTH);
return;
}
// Do data processing
sc.MovingMedian(sc.HLAvg, Median, sc.Index, MedianPeriod.GetInt());
sc.ATR(sc.BaseDataIn, TrueRange, AvgTrueRange, sc.Index, ATRPeriod.GetInt(), MOVAVGTYPE_SIMPLE);
if (sc.Index == 0)
{
sc.ValueFormat = sc.BaseGraphValueFormat;
Stop[sc.Index] = sc.Close[sc.Index];
Trend[sc.Index] = 1;
return;
}
if (sc.FormattedEvaluate(sc.Close[sc.Index], sc.ValueFormat, GREATER_OPERATOR, Stop[sc.Index-1], sc.ValueFormat))
{
Trend[sc.Index] = 1;
float NewStop = Median[sc.Index] - ATRMultiplier.GetFloat()*AvgTrueRange[sc.Index-1];
if (Trend[sc.Index-1] < 0)
{
Stop[sc.Index] = NewStop;
}
else
{
Stop[sc.Index] = max(NewStop, Stop[sc.Index-1]);
}
}
else if (sc.FormattedEvaluate(sc.Close[sc.Index], sc.ValueFormat, LESS_OPERATOR, Stop[sc.Index-1], sc.ValueFormat))
{
Trend[sc.Index] = -1;
float NewStop = Median[sc.Index] + ATRMultiplier.GetFloat()*AvgTrueRange[sc.Index-1];
if (Trend[sc.Index-1] > 0)
{
Stop[sc.Index] = NewStop;
}
else
{
Stop[sc.Index] = min(NewStop, Stop[sc.Index-1]);
}
}
else
{
Trend[sc.Index] = Trend[sc.Index-1];
Stop[sc.Index] = Stop[sc.Index-1];
}
Stop.DataColor[sc.Index] = Trend[sc.Index] > 0 ? Stop.PrimaryColor : Stop.SecondaryColor;
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
August 7th, 2015, 07:51 AM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
Renko123
Could someone with more ability then me modify the supertrend indicator to plot only the uptrend?
I tried, had to accept that i couldn't get it working.
Thanks in advance.
why not just set downtrend color to background color?
August 7th, 2015, 10:48 AM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
cory
why not just set downtrend color to background color?
Thanks for the reply cory.
Its good to see a fellow member from the DC metro area.
Setting the background color to chart color wont do what i need.
Because the stop value is still plotted on the chart and picked up by the spreadsheet.
If there was a separate StopLong and a StopShort instead of one "Stop" variable , I would be able to choose ignore to keep the StopLong or the StopShort value from showing up in the chart and being captured by the spreadsheet.
August 7th, 2015, 11:46 AM
Alesia E.U.
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115
Hi
try this , set scale Same as Region
Code
/*============================================================================
SuperTrend Stop study function.
----------------------------------------------------------------------------*/
SCSFExport scsf_SuperTrendStop(SCStudyInterfaceRef sc)
{
SCSubgraphRef Stop = sc.Subgraph[0];
SCSubgraphRef Median = sc.Subgraph[1];
SCSubgraphRef Stop1 = sc.Subgraph[2];
SCFloatArrayRef TrueRange = Stop.Arrays[0];
SCFloatArrayRef AvgTrueRange = Stop.Arrays[1];
SCFloatArrayRef Trend = Stop.Arrays[2];
SCInputRef ATRMultiplier = sc.Input[0];
SCInputRef ATRPeriod = sc.Input[1];
SCInputRef MedianPeriod = sc.Input[2];
// Set configuration variables
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "SuperTrend Stop";
sc.StudyDescription = "";
sc.DrawZeros = false;
sc.GraphRegion = 0;
sc.ValueFormat = sc.BaseGraphValueFormat;
//During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
sc.FreeDLL = 1;
sc.AutoLoop = 1;
Stop.Name = "Stop";
Stop.DrawStyle = DRAWSTYLE_DASH;
Stop.LineWidth = 2;
Stop.PrimaryColor = COLOR_BLUE;
Stop.SecondaryColor = COLOR_RED;
Stop.SecondaryColorUsed = 1;
ATRMultiplier.Name = "ATR Multiplier";
ATRMultiplier.SetFloat(2);
ATRMultiplier.SetFloatLimits(0.000001f,(float)MAX_STUDY_LENGTH);
ATRPeriod.Name = "ATR Period";
ATRPeriod.SetInt(3);
ATRPeriod.SetIntLimits(1,MAX_STUDY_LENGTH);
MedianPeriod.Name = "Median Period";
MedianPeriod.SetInt(3);
MedianPeriod.SetIntLimits(1,MAX_STUDY_LENGTH);
return;
}
// Do data processing
sc.MovingMedian(sc.HLAvg, Median, sc.Index, MedianPeriod.GetInt());
sc.ATR(sc.BaseDataIn, TrueRange, AvgTrueRange, sc.Index, ATRPeriod.GetInt(), MOVAVGTYPE_SIMPLE);
if (sc.Index == 0)
{
sc.ValueFormat = sc.BaseGraphValueFormat;
Stop[sc.Index] = sc.Close[sc.Index];
Stop1[sc.Index] = sc.Close[sc.Index];
Trend[sc.Index] = 1;
return;
}
if (sc.FormattedEvaluate(sc.Close[sc.Index], sc.ValueFormat, GREATER_OPERATOR, Stop1[sc.Index-1], sc.ValueFormat))
{
Trend[sc.Index] = 1;
float NewStop = Median[sc.Index] - ATRMultiplier.GetFloat()*AvgTrueRange[sc.Index-1];
if (Trend[sc.Index-1] < 0)
{
Stop[sc.Index] = NewStop;
Stop1[sc.Index] = NewStop;
}
else
{
Stop[sc.Index] = max(NewStop, Stop1[sc.Index-1]);
Stop1[sc.Index] = max(NewStop, Stop1[sc.Index-1]);
}
}
else if (sc.FormattedEvaluate(sc.Close[sc.Index], sc.ValueFormat, LESS_OPERATOR, Stop1[sc.Index-1], sc.ValueFormat))
{
Trend[sc.Index] = -1;
float NewStop = Median[sc.Index] + ATRMultiplier.GetFloat()*AvgTrueRange[sc.Index-1];
if (Trend[sc.Index-1] > 0)
{
Stop1[sc.Index] = NewStop;
Stop[sc.Index] = 0;
}
else
{
Stop1[sc.Index] = min(NewStop, Stop1[sc.Index-1]);
Stop[sc.Index] = 0;
}
}
else
{
Trend[sc.Index] = Trend[sc.Index-1];
Stop1[sc.Index] = Stop1[sc.Index-1];
Stop[sc.Index] = 0;
}
}
August 7th, 2015, 11:48 AM
Alesia E.U.
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115
if works remember to change sc.FreeDLL = 1; to sc.FreeDLL = 0;
August 7th, 2015, 05:02 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Thanks crazybears,
That worked for the long side , but it doesn't allow me to be able to select ignore for the short side or provide a separate named variable value plotted on the chart for the long and short side.
ie:
StopLong
StopShort
crazybears
Hi
try this , set
scale Same as Region
Code
/*============================================================================
SuperTrend Stop study function.
----------------------------------------------------------------------------*/
SCSFExport scsf_SuperTrendStop(SCStudyInterfaceRef sc)
{
SCSubgraphRef Stop = sc.Subgraph[0];
SCSubgraphRef Median = sc.Subgraph[1];
SCSubgraphRef Stop1 = sc.Subgraph[2];
SCFloatArrayRef TrueRange = Stop.Arrays[0];
SCFloatArrayRef AvgTrueRange = Stop.Arrays[1];
SCFloatArrayRef Trend = Stop.Arrays[2];
SCInputRef ATRMultiplier = sc.Input[0];
SCInputRef ATRPeriod = sc.Input[1];
SCInputRef MedianPeriod = sc.Input[2];
// Set configuration variables
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "SuperTrend Stop";
sc.StudyDescription = "";
sc.DrawZeros = false;
sc.GraphRegion = 0;
sc.ValueFormat = sc.BaseGraphValueFormat;
//During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
sc.FreeDLL = 1;
sc.AutoLoop = 1;
Stop.Name = "Stop";
Stop.DrawStyle = DRAWSTYLE_DASH;
Stop.LineWidth = 2;
Stop.PrimaryColor = COLOR_BLUE;
Stop.SecondaryColor = COLOR_RED;
Stop.SecondaryColorUsed = 1;
ATRMultiplier.Name = "ATR Multiplier";
ATRMultiplier.SetFloat(2);
ATRMultiplier.SetFloatLimits(0.000001f,(float)MAX_STUDY_LENGTH);
ATRPeriod.Name = "ATR Period";
ATRPeriod.SetInt(3);
ATRPeriod.SetIntLimits(1,MAX_STUDY_LENGTH);
MedianPeriod.Name = "Median Period";
MedianPeriod.SetInt(3);
MedianPeriod.SetIntLimits(1,MAX_STUDY_LENGTH);
return;
}
// Do data processing
sc.MovingMedian(sc.HLAvg, Median, sc.Index, MedianPeriod.GetInt());
sc.ATR(sc.BaseDataIn, TrueRange, AvgTrueRange, sc.Index, ATRPeriod.GetInt(), MOVAVGTYPE_SIMPLE);
if (sc.Index == 0)
{
sc.ValueFormat = sc.BaseGraphValueFormat;
Stop[sc.Index] = sc.Close[sc.Index];
Stop1[sc.Index] = sc.Close[sc.Index];
Trend[sc.Index] = 1;
return;
}
if (sc.FormattedEvaluate(sc.Close[sc.Index], sc.ValueFormat, GREATER_OPERATOR, Stop1[sc.Index-1], sc.ValueFormat))
{
Trend[sc.Index] = 1;
float NewStop = Median[sc.Index] - ATRMultiplier.GetFloat()*AvgTrueRange[sc.Index-1];
if (Trend[sc.Index-1] < 0)
{
Stop[sc.Index] = NewStop;
Stop1[sc.Index] = NewStop;
}
else
{
Stop[sc.Index] = max(NewStop, Stop1[sc.Index-1]);
Stop1[sc.Index] = max(NewStop, Stop1[sc.Index-1]);
}
}
else if (sc.FormattedEvaluate(sc.Close[sc.Index], sc.ValueFormat, LESS_OPERATOR, Stop1[sc.Index-1], sc.ValueFormat))
{
Trend[sc.Index] = -1;
float NewStop = Median[sc.Index] + ATRMultiplier.GetFloat()*AvgTrueRange[sc.Index-1];
if (Trend[sc.Index-1] > 0)
{
Stop1[sc.Index] = NewStop;
Stop[sc.Index] = 0;
}
else
{
Stop1[sc.Index] = min(NewStop, Stop1[sc.Index-1]);
Stop[sc.Index] = 0;
}
}
else
{
Trend[sc.Index] = Trend[sc.Index-1];
Stop1[sc.Index] = Stop1[sc.Index-1];
Stop[sc.Index] = 0;
}
}
August 8th, 2015, 07:57 AM
Alesia E.U.
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115
Hi Renko123
maybe i didn't understand but you didn't want to plot only the up trend of super trend ?
do you want the choice to plot only the up or the down trend ?
August 8th, 2015, 03:20 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Yes, crazybears.
If possible the ability to choose to plot either long, short or both on the chart.
something like choices in the input.
SCInputRef PlotLong = sc.Input[3];
SCInputRef PlotShort = sc.Input[4];
With the supertrend directional stops "Stop" or "Stop1" plotted on the chart depending on which input was chosen.
Thanks.
crazybears
Hi Renko123
maybe i didn't understand but you didn't want to plot only the up trend of super trend ?
do you want the choice to plot only the up or the down trend ?
August 12th, 2015, 05:28 PM
Alesia E.U.
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115
Hi
try this
Attached Files
Elite Membership required to download: Supertrend2.cpp
August 16th, 2015, 02:49 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Thanks crazybears for the coding changes,
However some problems still remains.
The subgraph SuperTrend(SG5) stop name for long or short is still the same.
There needs to be a separate subgraph stop name for each the long and the short trend.
ie:subgraph
StopLong(SG5)
StopShort(SG6)
Another issue is when the option to show only the short stop is selected.
The stop is all over the place.
The stop moves up and down the short side trend.
crazybears
Last Updated on May 31, 2018