NexusFi: Find Your Edge


Home Menu

 





Modify SuperTrend


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one crazybears with 5 posts (0 thanks)
    2. looks_two Renko123 with 5 posts (0 thanks)
    3. looks_3 cory with 2 posts (2 thanks)
    4. looks_4 kathy11 with 1 posts (0 thanks)
    1. trending_up 7,121 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 12 posts
    2. attach_file 4 attachments




 
Search this Thread
  #1 (permalink)
Renko123
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;

}


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
$12M Ceasefire Contract Goes Disputed as Bandar Abbas St …
Prediction Markets & Event Contracts
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
CME Raises Energy Futures Margins After Iran-War Volatil …
Commodities
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
NinjaTrader Parent Payward Acquires Bitnomial for $550M …
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
20 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
5 thanks
  #2 (permalink)
 
cory's Avatar
 cory 
virginia
the coin hunter
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,093


Renko123 View Post
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?


Reply With Quote
Thanked by:
  #3 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6



cory View Post
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.


Reply With Quote
  #4 (permalink)
 crazybears 
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;
	}


}


Reply With Quote
  #5 (permalink)
 crazybears 
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;


Reply With Quote
  #6 (permalink)
Renko123
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 View Post
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;
	}


}


Reply With Quote
  #7 (permalink)
 crazybears 
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 ?


Reply With Quote
  #8 (permalink)
Renko123
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 View Post
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 ?


Reply With Quote
  #9 (permalink)
 crazybears 
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
Reply With Quote
  #10 (permalink)
Renko123
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 View Post
Hi

try this


Reply With Quote




Last Updated on May 31, 2018


© 2026 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 - Downloads - Top
no new posts