The Stiffness Indicator For ThinkOrSwim

Code:
input MALength = 100;
input StiffnessLength = 60;
input Threshold = 90;

def MAValue = MovingAverage(AverageType.SIMPLE, close, MALength);
def MACorValue = MAValue - 0.2 * StDev(close, MALength);
def NumAboveMA = if close > MAValue then NumAboveMA[1] + 1 else 0;

def Stiffness_1 = 100 * (NumAboveMA / StiffnessLength);
def StiffnessEMA_1 = ExpAverage(Stiffness_1, StiffnessLength);

plot MA_COR = MACorValue;
plot MA = MAValue;

MA_COR.SetDefaultColor(GetColor(8));
MA.SetDefaultColor(GetColor(5));

plot Stiffness = Stiffness_1;
plot StiffnessEMA = StiffnessEMA_1;

Stiffness.SetDefaultColor(GetColor(3));
StiffnessEMA.SetDefaultColor(GetColor(4));
 
Made the stiffness MA a cloud and added Ehlers (stiffness) cloud as well that can be turned on or off in settings: http://tos.mx/4RGaLhE (Replaced link (again) to fix the gap in the clouds - added arrows

Ehlers Stiffness Cloud
pGl66Pg.png


MA Stiffness Cloud
5vJZhGx.png



Code:
#Stiffness MA/Ehlers Clouds



input MALength = 100;
input StiffnessLength = 60;
input Threshold = 90;
input ELlength = 23;
input coloredCandlesOn = no;
input show_ema_cloud_Ehlers = yes;
input show_ema_cloud_MA = no;
input show_Ehlers_arrows = yes;
input show_MA_arrows = no;

def price = (high + low) / 2;

def coeff = ELlength * price * price - 2 * price * sum(price, ELlength)[1] + sum(price * price, ELlength)[1];

plot Ehlers = sum(coeff * price, ELlength) / sum(coeff, ELlength);
Ehlers.SetDefaultColor(Color.light_gray);

def c = close;
def o = open;

def MAValue = MovingAverage(AverageType.SIMPLE, close, MALength);
def MACorValue = MAValue - 0.2 * StDev(close, MALength);
def NumAboveMA = if close > MAValue then NumAboveMA[1] + 1 else 0;

def MAValue2 = sum(coeff * price, ELlength) / sum(coeff, ELlength);
def MACorValue2 = MAValue2 - 0.2 * StDev(close, ELLength);
def NumAboveMA2 = if close > MAValue2 then NumAboveMA2[1] + 1 else 0;

def Stiffness_Ehlers = 100 * (NumAboveMA2 / StiffnessLength);
def Stiffness_Ehlers_2 = ExpAverage(Stiffness_Ehlers, StiffnessLength);

plot MA_COR = MACorValue;
plot MA = MAValue;

plot MA_COR2 = MACorValue2;
plot MA2 = MAValue2;

#def compressed = MAValue2 - MACorValue2;

#def compression = if (compressed <= 1) then 1 else 0;

#plot Squeeze_Alert = if compression then 1 else 0;
#Squeeze_Alert.SetPaintingStrategy(PaintingStrategy.POINTS);
#Squeeze_Alert.SetLineWeight(5);
#Squeeze_Alert.SetDefaultColor(Color.white);                                                                                        

def MA_Cor2_UP = if ((MA_cor2 > MA_cor2[1])) then 1 else 0;
def MA_Cor2_dn = if ((MA_cor2 < MA_cor2[1])) then 1 else 0;

def MA_Cor_UP = if ((MA_cor > MA_cor[1])) then 1 else 0;
def MA_Cor_dn = if ((MA_cor < MA_cor[1])) then 1 else 0;

plot MA_Cor2_UP_1 = if show_MA_arrows and MA_Cor2_UP and !MA_Cor2_UP[1] then low else Double.NaN;
MA_Cor2_UP_1.SetPaintingStrategy(PaintingSTrategy.ARROW_up);
MA_Cor2_UP_1.SetDefaultColor(Color.white);     

plot MA_Cor2_DN_1 = if  show_MA_arrows and MA_Cor2_DN and !MA_Cor2_DN[1] then high  else Double.NaN;
MA_Cor2_DN_1.SetPaintingSTrategy(paintingSTrategy.Arrow_DOWN);
MA_Cor2_DN_1.SetDefaultColor(Color.white);     

plot MA_Cor_UP_2 = if  show_Ehlers_arrows and MA_Cor2_UP and !MA_Cor2_UP[1] then low else Double.NaN;
MA_Cor_UP_2.SetPaintingStrategy(PaintingSTrategy.ARROW_up);
MA_Cor_UP_2.SetDefaultColor(Color.white);     

plot MA_Cor_DN_2 = if  show_Ehlers_arrows and MA_Cor2_DN and !MA_Cor2_DN[1] then high  else Double.NaN;
MA_Cor_DN_2.SetPaintingSTrategy(paintingSTrategy.Arrow_DOWN);
MA_Cor_DN_2.SetDefaultColor(Color.white);  

AddCloud(if show_ema_cloud_Ehlers and MA_Cor2 < close then MA_cor2 else MA2, MA_cor2,  Color.LIGHT_red, Color.green);
AddCloud(if show_ema_cloud_Ehlers and MA_Cor2 > close then MA2 else MA_COR2, MA2,  Color.LIGHT_red, Color.green);

AddCloud(if show_ema_cloud_MA and ((MA_cor > MA_cor[1])and(MA > MA[1])) then MA_cor else MA, MA,  Color.LIGHT_red, Color.green);
AddCloud(if show_ema_cloud_MA and ((MA_cor < MA_cor[1])and(MA < MA[1])) then MA else MA_COR, MA_COR,  Color.LIGHT_red, Color.green);


#plot Crossup3 = Crossup2;
#Crossup3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Up);
#Crossup3.SetDefaultColor(Color.Orange);
#Crossup3.SetLineWeight(arrow_size2);

#plot Crossdown3 = Crossdown2;
#Crossdown3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
#Crossdown3.SetDefaultColor(Color.orange);
#Crossdown3.SetLineWeight(arrow_size2);
#plot Stiffness = Stiffness_1;
#plot StiffnessEMA = StiffnessEMA_1;

#Stiffness.SetDefaultColor(GetColor(3));
#StiffnessEMA.SetDefaultColor(GetColor(4));
 
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
343 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