Creating a dynamic EMA using the TTM Squeeze

OptionsTrader

New member
I was experimenting with different ways of looking at the oscillator and the line on the TTM squeeze (this is a modified version of it) The idea is that seeing where the oscillator moves doesn't matter because the color will change for us.

I was wondering if its possible to create a dynamic EMA out of it.

For example:
Use any EMA then change the color according to the oscillator.

Negative and down = Dark red
Negatvie and up = Red
Positive and down = Green
Positive and up = Dark Green

As for the squeeze itself, I was thinking when there is a squeeze then the ema will get a dot on it or a squeeze will be signaled in the form of a label.

Below is a picture of the oscillator with the line. So basically put that but on an EMA. Also below is the TTM Squeeze Pro code.

Code:
input enableAllAlerts = NO;

declare lower;

def nBB = 2.0;
def Length = 20.0;
def nK_High = 1.0;
def nK_Mid = 1.5;
def nK_Low = 2.0; 
def price = close;

def momentum = TTM_Squeeze(price = price, length = length, nk = nk_Mid, nbb = nbb)."Histogram";
plot oscillator = momentum;
def BolKelDelta_Mid = reference BollingerBands("num_dev_up" = nBB, "length" = Length )."upperband" - KeltnerChannels("factor" = nK_Mid, "length" = Length)."Upper_Band";
def BolKelDelta_Low = reference BollingerBands("num_dev_up" = nBB, "length" = Length )."upperband" - KeltnerChannels("factor" = nK_Low, "length" = Length)."Upper_Band";
def BolKelDelta_High = reference BollingerBands("num_dev_up" = nBB, "length" = Length )."upperband" - KeltnerChannels("factor" = nK_High, "length" = Length)."Upper_Band";
oscillator.DefineColor("Up", CreateColor(0, 255, 255));
oscillator.DefineColor("UpDecreasing", CreateColor(0, 0, 255));
oscillator.DefineColor("Down", CreateColor(255, 0, 0));
oscillator.DefineColor("DownDecreasing",  CreateColor(255, 255, 0));
oscillator.AssignValueColor(
if oscillator[1] < oscillator then if oscillator[0] >= 0
then oscillator.Color("Up")
else oscillator.Color("DownDecreasing") 
else if oscillator >= 0
then oscillator.Color("UpDecreasing") 
else oscillator.Color("Down") );
oscillator.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
oscillator.SetLineWeight(5);

plot squeeze = If(IsNaN(close), Double.NaN, 0);
squeeze.DefineColor("NoSqueeze", Color.GREEN);
squeeze.DefineColor("SqueezeLow", Color.black);
squeeze.DefineColor("SqueezeMid", Color.RED);
squeeze.DefineColor("SqueezeHigh", Color.orange);
squeeze.AssignValueColor(if BolKelDelta_High <= 0 then squeeze.Color("SqueezeHigh") else if BolKelDelta_Mid <= 0 then squeeze.Color("SqueezeMid") else if BolKelDelta_Low <= 0 then squeeze.Color("SqueezeLow") else squeeze.color("noSqueeze"));
squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
squeeze.SetLineWeight(3);

def enteredHighSqueeze = BolKelDelta_High <= 0 and BolKelDelta_High[1] > 0;
def enteredMidSqueeze = BolKelDelta_Mid <= 0 and BolKelDelta_Mid[1] > 0;
def enteredLowSqueeze = BolKelDelta_Low <= 0 and BolKelDelta_Low[1] > 0;

def exitedHighSqueeze = BolKelDelta_High > 0 and BolKelDelta_High[1] <= 0;
def exitedMidSqueeze = BolKelDelta_Mid > 0 and BolKelDelta_Mid[1] <= 0;
def exitedLowSqueeze = BolKelDelta_Low > 0 and BolKelDelta_Low[1] <= 0;

alert(enteredHighSqueeze and enableAllAlerts, "Entered High Squeeze", alert.bar, sound.NoSound);
alert(enteredMidSqueeze and enableAllAlerts, "Entered Mid Squeeze", alert.bar, sound.NoSound);
alert(enteredLowSqueeze and enableAllAlerts, "Entered Low Squeeze", alert.bar, sound.NoSound);

alert(exitedHighSqueeze and enableAllAlerts, "High Squeeze Fired", alert.bar, sound.NoSound);
alert(exitedMidSqueeze and enableAllAlerts, "Mid Squeeze Fired", alert.bar, sound.NoSound);
alert(exitedLowSqueeze and enableAllAlerts, "Low Squeeze Fired", alert.bar, sound.NoSound);

def conditionSqueeze = BolKelDelta_High <= 0 or BolKelDelta_Mid <= 0 or BolKelDelta_Low <= 0;

def sqz = conditionSqueeze;
def direction = oscillator > oscillator[1];
def count = if sqz and !sqz[1] then 1 else count[1]+1;
def fired = if !sqz and sqz[1] then 1 else 0;
def firedCount = if fired then 1 else firedCount[1]+1;
def firedDirection = if fired then direction else firedDirection[1];
addLabel(yes, if sqz then "Squeeze:" + count else if sum(fired,5) then "Fired:" + firedCOunt + if firedDirection then " Long" else " Short" else "-", if sqz then Color.RED else if fired then color.ORANGE else if sum(fired,5) and firedDirection then color.GREEN else color.black);
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
403 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