Combined Trend Indicators For ThinkOrSwim

HighBredCloud

Well-known member
Can you please take a look at the Schaff Wave below? There's a lot more indicators combined in the script below that are not needed...What needs to be kept and working is the actual Schaff Wave I believe its STC Wave in the script and the logic needs to be to color the candles based on the color change of the actual Wave...Everything else is not needed at all...

Code:
#STSW = Schaff Trend Line and Schaff Wave Line
#Schaff Trend Line = Used for quick up/down trend declaration
#Schaff Wave Line = Trade Wave in the direction of trend as
#declared by Trend Line.
#Schaff Wave Line can be used alone to enter trend
#declared by the MACD.
#Schaff Wave can be used with the EMA for signals

declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

plot Fifty_Line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));
STCWave.DefineColor("Up", GetColor(1));
STCWave.DefineColor("Down", GetColor(0));
STCWave.AssignValueColor(if STCWave > STCWave[1] then STCWave.Color("Up") else STCWave.Color("Down"));

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
#
# Polarity

# v0.01

# 6.2.19

# Nube

#hint: This study calculates a CCI from an average of high and low pivot prices then uses that CCI and a user defined number of deviations to determine polarity. A cross above +deviations or cross below -devations signals a polarity change

 

# subscript for calculating the mean of pivot prices

script pivotMean{

input pivotN = 4;

input stochasticN = 21;

def h = high;

def l = low;

def norm = (close - Lowest(l, pivotN)) /

(Highest(h, pivotN) - Lowest(l, pivotN));

 

## Pivot High

def hh = if norm crosses above .5

then h

else if h > hh[1]

then h

else hh[1];

def hpBar = if h == hh

then BarNumber()

else Double.NaN;

def hpPrice = if !IsNaN(hpBar)

then h

else hpPrice[1];

 

## Pivot Low

def ll = if norm crosses below .5

then l

else if l < ll[1]

then l

else ll[1];

def lpBar = if l == ll

then BarNumber()

else Double.NaN;

def lpPrice = if !IsNaN(lpBar)

then l

else lpPrice[1];

 

plot

pivotMean = Average((hpPrice + lpPrice) / 2, stochasticN);

}

 

# Inputs

input pivotLength = 4; #hint pivotLength: Number of bars for stochastic pivot calcuation

input meanLength = 21; #hint meanLength: Number of bars to calculate mean

input deviations = 1.0;#hint deviations: Number of deviations from mean to signal a polarity change

 

# Variables

def mean   = pivotMean(pivotLength, meanLength);

def linDev = lindev(close, meanLength);

def cci    = (close - mean) / linDev;

 

def polarity_;

if cci crosses above deviations{

polarity_ = 1;

}else

if cci crosses below -deviations{

polarity_ = -1;

}else{

polarity_ = polarity_[1];

}

 

# Plots

plot

Polarity = polarity_;

Polarity.AssignValueColor(if polarity_ > 0 then Color.Green else Color.Red);

 

#declare lower;

 

# f/ Polarity
 
Last edited by a moderator:
I modified it slightly by including the DSS line...
Code:
#STSW = Schaff Trend Line and Schaff Wave Line
#Schaff Trend Line = Used for quick up/down trend declaration
#Schaff Wave Line = Trade Wave in the direction of trend as
#declared by Trend Line.
#Schaff Wave Line can be used alone to enter trend
#declared by the MACD.
#Schaff Wave can be used with the EMA for signals

declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

#plot Fifty_Line = 50;
#fifty_line.SetDefaultColor(GetColor(8));
#fifty_line.HideTitle();
#fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));

STCWave.AssignValueColor(if STCWave > STCWave[1] then Color.MAGENTA else Color.CYAN);
STCWave.SetPaintingStrategy(PaintingStrategy.Line_VS_POINTS);

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
AvgExpWave.AssignValueColor(if AvgExpWave > AvgExpWave[1] then Color.YELLOW else Color.DARK_ORANGE);
AvgExpWave.SetPaintingStrategy(PaintingStrategy.Line);
#


# Slow Line
input N2_Period = 21;
input R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def X2 = ExpAverage(Y2, R2_period);


def Lxn = Lowest(x2, n2_period);
def Hxn = Highest(x2, n2_period);
def DSS = ((X2 - Lxn)/(Hxn - Lxn)) * 100;


def DSSb = ExpAverage(Dss, R2_period);
#DSSb.setdefaultColor(Color.GREEN);
#DSSb.AssignValueColor(Color.GREEN);

plot DSSsignal = DSSb[1];
DSSsignal.AssignValueColor(if DSSb>DSSsignal then Color.Green else Color.Red);
DSSsignal.SetLineWeight(1);
DSSsignal.SetPaintingStrategy(PaintingStrategy.LINE);
 
Last edited by a moderator:
This acts as a semi-directional guide for anticipating where the PPS is going, like the ship changes direction is slowly, so that is how this works. I would even try to code into a scanner, but I do not know coding very well.

Follow the STCTrend for color change, see when it changed
At bottom: STCTrend change to blue, (or whichever color you make it)
STCWave changes to green, and crosses 27 line.
AvgExpWave only shows the Relevant Volume, but does not indicate buy/sell volume separately.
The green/red line along the bottom is polarity, positive or negative, calculated CCI from an average of high and low pivot prices then uses that CCI and a user defined number of deviations to determine polarity

Code:
declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

plot Fifty_Line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));
STCWave.DefineColor("Up", GetColor(1));
STCWave.DefineColor("Down", GetColor(0));
STCWave.AssignValueColor(if STCWave > STCWave[1] then STCWave.Color("Up") else STCWave.Color("Down"));

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
#
# Polarity

# v0.01

# 6.2.19

# Nube

#hint: This study calculates a CCI from an average of high and low pivot prices then uses that CCI and a user defined number of deviations to determine polarity. A cross above +deviations or cross below -devations signals a polarity change

 

# subscript for calculating the mean of pivot prices

script pivotMean{

input pivotN = 4;

input stochasticN = 21;

def h = high;

def l = low;

def norm = (close - Lowest(l, pivotN)) /

(Highest(h, pivotN) - Lowest(l, pivotN));

 

## Pivot High

def hh = if norm crosses above .5

then h

else if h > hh[1]

then h

else hh[1];

def hpBar = if h == hh

then BarNumber()

else Double.NaN;

def hpPrice = if !IsNaN(hpBar)

then h

else hpPrice[1];

 

## Pivot Low

def ll = if norm crosses below .5

then l

else if l < ll[1]

then l

else ll[1];

def lpBar = if l == ll

then BarNumber()

else Double.NaN;

def lpPrice = if !IsNaN(lpBar)

then l

else lpPrice[1];

 

plot

pivotMean = Average((hpPrice + lpPrice) / 2, stochasticN);

}

 

# Inputs

input pivotLength = 4; #hint pivotLength: Number of bars for stochastic pivot calcuation

input meanLength = 21; #hint meanLength: Number of bars to calculate mean

input deviations = 1.0;#hint deviations: Number of deviations from mean to signal a polarity change

 

# Variables

def mean   = pivotMean(pivotLength, meanLength);

def linDev = lindev(close, meanLength);

def cci    = (close - mean) / linDev;

 

def polarity_;

if cci crosses above deviations{

polarity_ = 1;

}else

if cci crosses below -deviations{

polarity_ = -1;

}else{

polarity_ = polarity_[1];

}

 

# Plots

plot

Polarity = polarity_;

Polarity.AssignValueColor(if polarity_ > 0 then Color.Green else Color.Red);

 

#declare lower;

 

# f/ Polarity
 
Last edited by a moderator:

Some may work, but this will kill!

15 min $BCDA trade is developing on 6th, PPS under 200SMA. ~12 PM: Spike over 25 line STCWave (green)!
Volume follows: crossed Mid-range (50) and 2 Blue arrows ~ from STC Indicator (top chart).

& on 9th is your trade, see Svaboy_2 buy-in as PPS bumps 200SMA, crosses, then retraces.
& on 11th is second (Svanoy_2) supported buy-in with major volume in after hour trading, pivoy off 200SMA, & up to and through red lined major resistance.
 
Last edited:
I modified it slightly by including the DSS line...
Code:
#STSW = Schaff Trend Line and Schaff Wave Line
#Schaff Trend Line = Used for quick up/down trend declaration
#Schaff Wave Line = Trade Wave in the direction of trend as
#declared by Trend Line.
#Schaff Wave Line can be used alone to enter trend
#declared by the MACD.
#Schaff Wave can be used with the EMA for signals

declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

#plot Fifty_Line = 50;
#fifty_line.SetDefaultColor(GetColor(8));
#fifty_line.HideTitle();
#fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));

STCWave.AssignValueColor(if STCWave > STCWave[1] then Color.MAGENTA else Color.CYAN);
STCWave.SetPaintingStrategy(PaintingStrategy.Line_VS_POINTS);

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
AvgExpWave.AssignValueColor(if AvgExpWave > AvgExpWave[1] then Color.YELLOW else Color.DARK_ORANGE);
AvgExpWave.SetPaintingStrategy(PaintingStrategy.Line);
#


# Slow Line
input N2_Period = 21;
input R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def X2 = ExpAverage(Y2, R2_period);


def Lxn = Lowest(x2, n2_period);
def Hxn = Highest(x2, n2_period);
def DSS = ((X2 - Lxn)/(Hxn - Lxn)) * 100;


def DSSb = ExpAverage(Dss, R2_period);
#DSSb.setdefaultColor(Color.GREEN);
#DSSb.AssignValueColor(Color.GREEN);

plot DSSsignal = DSSb[1];
DSSsignal.AssignValueColor(if DSSb>DSSsignal then Color.Green else Color.Red);
DSSsignal.SetLineWeight(1);
DSSsignal.SetPaintingStrategy(PaintingStrategy.LINE);
I add clouds so that we can see trend changes easily.


Ruby:
#STSW = Schaff Trend Line and Schaff Wave Line
#Schaff Trend Line = Used for quick up/down trend declaration
#Schaff Wave Line = Trade Wave in the direction of trend as
#declared by Trend Line.
#Schaff Wave Line can be used alone to enter trend
#declared by the MACD.
#Schaff Wave can be used with the EMA for signals

declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

#plot Fifty_Line = 50;
#fifty_line.SetDefaultColor(GetColor(8));
#fifty_line.HideTitle();
#fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));

STCWave.AssignValueColor(if STCWave > STCWave[1] then Color.MAGENTA else Color.CYAN);
STCWave.SetPaintingStrategy(PaintingStrategy.Line_VS_POINTS);

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
AvgExpWave.AssignValueColor(if AvgExpWave > AvgExpWave[1] then Color.YELLOW else Color.DARK_ORANGE);
AvgExpWave.SetPaintingStrategy(PaintingStrategy.Line);
#


# Slow Line
input N2_Period = 21;
input R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def X2 = ExpAverage(Y2, R2_period);


def Lxn = Lowest(x2, n2_period);
def Hxn = Highest(x2, n2_period);
def DSS = ((X2 - Lxn)/(Hxn - Lxn)) * 100;


def DSSb = ExpAverage(Dss, R2_period);
#DSSb.setdefaultColor(Color.GREEN);
#DSSb.AssignValueColor(Color.GREEN);

plot DSSsignal = DSSb[1];
DSSsignal.AssignValueColor(if DSSb>DSSsignal then Color.Green else Color.Red);
DSSsignal.SetLineWeight(4);
DSSsignal.SetPaintingStrategy(PaintingStrategy.LINE);

Addcloud (DSSsignal, STCWave, color.light_red, color.green);
Addcloud (STCWave, AvgExpWave, color.light_green, color.light_red);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
349 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top