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.
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: