Join useThinkScript to post your question to a community of 21,000+ developers and traders.
#ErgodicOsc
#Modified by rad14733 for personal use
#Added moving average and no trade zone
declare lower;
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.Exponential;
plot ErgodicOsc = TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal;
plot ZeroLine = 0;
ErgodicOsc.SetPaintingStrategy(PaintingStrategy.Histogram);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.GREEN);
ErgodicOsc.DefineColor("Negative", Color.RED);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.color("Positive") else ErgodicOsc.color("Negative"));
ZeroLine.SetDefaultColor(GetColor(7));
plot avgErgodic = MovingAverage(AverageType.SIMPLE, ErgodicOsc, 8);
def noTradeValue = 2.5;
plot posNoTradeLine = noTradeValue;
plot negNoTradeLine = -noTradeValue;
plot longweak = if ErgodicOsc > 0 and ErgodicOsc < avgErgodic and ErgodicOsc < ErgodicOsc[1] and ErgodicOsc[1] > avgErgodic[1] then 0 else Double.NaN;
longweak.SetPaintingStrategy(PaintingStrategy.POINTS);
longweak.SetDefaultColor(Color.CYAN);
longweak.SetLineWeight(5);
longweak.HideTitle();
plot shortweak = if ErgodicOsc < 0 and ErgodicOsc > avgErgodic and ErgodicOsc > ErgodicOsc[1] and ErgodicOsc[1] < avgErgodic[1] then 0 else Double.NaN;
shortweak.SetPaintingStrategy(PaintingStrategy.POINTS);
shortweak.SetDefaultColor(Color.MAGENTA);
shortweak.SetLineWeight(5);
shortweak.HideTitle();
Thanks.@nrk786 The dots are my early indicators and for my use they fire a candle or two before my other indicators... You may need to tweak the indicator settings to what works best for your chart timeframe and security price range and volatility... They'll either work for you or they won't and they aren't 100% accurate, but they do help me... I use the same concept for almost every histogram indicator I use...
Rad14733 can you please explain how to use your version of this? As far as what entry and exit points you look for on this indicator? Thx@nrk786 I have added a moving average to my version and use that to help indicate early entry and exit signals... I have also added a no trade zone but can't say that I've paid much attention to it... It also paints dots when the histogram gaps below/above the average and that is my weakness/reversal indicator... Here it is... Let me know what you think...
Ruby:#ErgodicOsc #Modified by rad14733 for personal use #Added moving average and no trade zone declare lower; input longLength = 25; input shortLength = 13; input signalLength = 8; input averageType = AverageType.Exponential; plot ErgodicOsc = TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal; plot ZeroLine = 0; ErgodicOsc.SetPaintingStrategy(PaintingStrategy.Histogram); ErgodicOsc.SetLineWeight(3); ErgodicOsc.DefineColor("Positive", Color.GREEN); ErgodicOsc.DefineColor("Negative", Color.RED); ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.color("Positive") else ErgodicOsc.color("Negative")); ZeroLine.SetDefaultColor(GetColor(7)); plot avgErgodic = MovingAverage(AverageType.SIMPLE, ErgodicOsc, 8); def noTradeValue = 2.5; plot posNoTradeLine = noTradeValue; plot negNoTradeLine = -noTradeValue; plot longweak = if ErgodicOsc > 0 and ErgodicOsc < avgErgodic and ErgodicOsc < ErgodicOsc[1] and ErgodicOsc[1] > avgErgodic[1] then 0 else Double.NaN; longweak.SetPaintingStrategy(PaintingStrategy.POINTS); longweak.SetDefaultColor(Color.CYAN); longweak.SetLineWeight(5); longweak.HideTitle(); plot shortweak = if ErgodicOsc < 0 and ErgodicOsc > avgErgodic and ErgodicOsc > ErgodicOsc[1] and ErgodicOsc[1] < avgErgodic[1] then 0 else Double.NaN; shortweak.SetPaintingStrategy(PaintingStrategy.POINTS); shortweak.SetDefaultColor(Color.MAGENTA); shortweak.SetLineWeight(5); shortweak.HideTitle();
Rad14733 can you please explain how to use your version of this? As far as what entry and exit points you look for on this indicator? Thx
How did you decide on the value of your NoTradeLines or dead zones? I would like to apply a similar system to other indicators, but I don't know how to make a reliable determination of the minimum value for a trade.@nrk786 I have added a moving average to my version and use that to help indicate early entry and exit signals... I have also added a no trade zone but can't say that I've paid much attention to it... It also paints dots when the histogram gaps below/above the average and that is my weakness/reversal indicator... Here it is... Let me know what you think...
Ruby:#ErgodicOsc #Modified by rad14733 for personal use #Added moving average and no trade zone declare lower; input longLength = 25; input shortLength = 13; input signalLength = 8; input averageType = AverageType.Exponential; plot ErgodicOsc = TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal; plot ZeroLine = 0; ErgodicOsc.SetPaintingStrategy(PaintingStrategy.Histogram); ErgodicOsc.SetLineWeight(3); ErgodicOsc.DefineColor("Positive", Color.GREEN); ErgodicOsc.DefineColor("Negative", Color.RED); ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.color("Positive") else ErgodicOsc.color("Negative")); ZeroLine.SetDefaultColor(GetColor(7)); plot avgErgodic = MovingAverage(AverageType.SIMPLE, ErgodicOsc, 8); def noTradeValue = 2.5; plot posNoTradeLine = noTradeValue; plot negNoTradeLine = -noTradeValue; plot longweak = if ErgodicOsc > 0 and ErgodicOsc < avgErgodic and ErgodicOsc < ErgodicOsc[1] and ErgodicOsc[1] > avgErgodic[1] then 0 else Double.NaN; longweak.SetPaintingStrategy(PaintingStrategy.POINTS); longweak.SetDefaultColor(Color.CYAN); longweak.SetLineWeight(5); longweak.HideTitle(); plot shortweak = if ErgodicOsc < 0 and ErgodicOsc > avgErgodic and ErgodicOsc > ErgodicOsc[1] and ErgodicOsc[1] < avgErgodic[1] then 0 else Double.NaN; shortweak.SetPaintingStrategy(PaintingStrategy.POINTS); shortweak.SetDefaultColor(Color.MAGENTA); shortweak.SetLineWeight(5); shortweak.HideTitle();
The NoTradeLines need to be adjusted for every instrument charted so I rarely pay attention to them and, in fact, tend to turn off those plots most of the time... They might come in handy if the indicator was to be incorporated into a more broad trading strategy...How did you decide on the value of your NoTradeLines or dead zones? I would like to apply a similar system to other indicators, but I don't know how to make a reliable determination of the minimum value for a trade.
plot avgErgodic = MovingAverage(AverageType.SIMPLE, ErgodicOsc, 8);
ErgodicOsc.SetPaintingStrategy(PaintingStrategy.Histogram);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.GREEN);
ErgodicOsc.DefineColor("Negative", Color.RED);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.color("Positive") else ErgodicOsc.color("Negative"));
ZeroLine.SetDefaultColor(GetColor(7));
The ToS platform does not provide for the successful application of custom studies in the Option HackerLooking for coding help for scanning options using ErgodicOsc. I need the scan to read the histo closing above "zeroline" or changing colors to green for confirmation. Current scan is not accurate and looks for crosses only. I cant seem to figure out how to code for closed histo bars. Thanks
I I have a question. I have 2 indicators layered on top of each other, but every time I zoom in or move my chart the indicators separate. Is there a code that you can add so they both are aligned at the 0 line?
declare lower;
script normalizer {
input data = close;
input Min = -1;
input Max = 1;
input length = 50;
def hhData = Highest(data, length);
def llData = Lowest(data, length);
plot resized = (((Max - Min) * (data - llData)) /
(hhData - llData)) + Min;
}
### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;
plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);
ErgodicOsc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));
### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);
plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(3);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);
#--------------- [ Metrics From Mobius ] ---------------
def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));
plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;
#------------------------------------------------------------------------------------------
# David M.(Some Random Alien) 10-6-2021
# Don't blame Mobius... I made this mess :)
# Code displays Squeeze Watch Prediction Index.
# Depending on volume, a score of less then 25 could signal an impeding Squeeze.
def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;
rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];
#---------------------------- [ Plots Some Dots ] -----------------------------
Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);
#------------------------------------------------------------------------------
# Make the SI bar look pretty :)
#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);
def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0 else Double.NaN;
#--------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------
#AddLabel(!IsNaN(Squeeze), " >>> Squeeze <<< ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));
def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;
plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);
declare lower;
script normalizer {
input data = close;
input Min = -1;
input Max = 1;
input length = 50;
def hhData = Highest(data, length);
def llData = Lowest(data, length);
plot resized = (((Max - Min) * (data - llData)) /
(hhData - llData)) + Min;
}
### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;
plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);
ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));
### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);
plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(5);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);
#--------------- [ Metrics From Mobius ] ---------------
def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));
plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;
#------------------------------------------------------------------------------------------
# David M.(Some Random Alien) 10-6-2021
# Don't blame Mobius... I made this mess :)
# Code displays Squeeze Watch Prediction Index.
# Depending on volume, a score of less then 25 could signal an impeding Squeeze.
def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;
rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];
#---------------------------- [ Plots Some Dots ] -----------------------------
Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);
#------------------------------------------------------------------------------
# Make the SI bar look pretty :)
#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);
def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0 else Double.NaN;
#--------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------
#AddLabel(!IsNaN(Squeeze), " >>> Squeeze <<< ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));
def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;
plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);
declare lower;
script normalizer {
input data = close;
input Min = -1;
input Max = 1;
input length = 50;
def hhData = Highest(data, length);
def llData = Lowest(data, length);
plot resized = (((Max - Min) * (data - llData)) /
(hhData - llData)) + Min;
}
### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;
plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);
ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.WHITE); #Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.WHITE); #Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));
### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);
plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(5);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);
#--------------- [ Metrics From Mobius ] ---------------
def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));
plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;
#------------------------------------------------------------------------------------------
# David M.(Some Random Alien) 10-6-2021
# Don't blame Mobius... I made this mess :)
# Code displays Squeeze Watch Prediction Index.
# Depending on volume, a score of less then 25 could signal an impeding Squeeze.
def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;
rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];
#---------------------------- [ Plots Some Dots ] -----------------------------
Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);
#------------------------------------------------------------------------------
# Make the SI bar look pretty :)
#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);
def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0 else Double.NaN;
#--------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------
#AddLabel(!IsNaN(Squeeze), " >>> Squeeze <<< ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));
def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;
plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);
Thank you so much. I understand what you are pointing out. Thank you@candlestix : Area 1 highlights the overlaying of the Squeeze indicator by the ErgodicOsc indicator. As a result of using the two default indicators without changing the code you get the scaling issue I mentioned previously. The Scale is in percentages instead of numbers. Also, the Zero Lines are off.
Area 2 shows the proper overlaying of the two indicators where the Scale should and does have values revolving around a common Zero Line. In my opinion, the merging of these two indicators makes the newly combined indicator difficult to read, due to using two histograms for display of the data...
Below are three options to choose from:
Option 1: The original merging of the two indicators complete with two histograms and the aforementioned readability issue...
Option 2 : Changes the ErgodicOsc from a histogram to a line with the original coloring intact. Once again, this can be difficult to read in spots...
Option 3: Keeps the ErgodicOsc as a line and changes the coloring to white for contrast, clarity and easy readability...
Below is the respective code for each of the options:
Option 1
Code:declare lower; script normalizer { input data = close; input Min = -1; input Max = 1; input length = 50; def hhData = Highest(data, length); def llData = Lowest(data, length); plot resized = (((Max - Min) * (data - llData)) / (hhData - llData)) + Min; } ### ERGODIC OSCILLATOR ### input longLength = 25; input shortLength = 13; input signalLength = 8; input averageType = AverageType.EXPONENTIAL; plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal); ErgodicOsc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); ErgodicOsc.SetLineWeight(3); ErgodicOsc.DefineColor("Positive", Color.UPTICK); ErgodicOsc.DefineColor("Negative", Color.DOWNTICK); ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative")); ### SQUEEZE ### input length = 21; #hint length: Length for average calculation. input price = close; input SDmult = 2.0; input ATRmult = 1.5; def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length); plot Momo = normalizer(Inertia(price - K / 2, length)); Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Momo.SetLineWeight(3); Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN else if Momo > 0 and Momo < Momo[1] then Color.BLUE else if Momo < 0 and Momo < Momo[1] then Color.RED else Color.YELLOW); #--------------- [ Metrics From Mobius ] --------------- def SD = StDev(close, length); def Avg = Average(close, length); def ATR = Average(TrueRange(high, close, low), length); def SDup = normalizer(Avg + (SDmult * SD)); def ATRup = normalizer(Avg + (ATRmult * ATR)); plot Squeeze = if SDup < ATRUp then 0 else Double.NaN; #------------------------------------------------------------------------------------------ # David M.(Some Random Alien) 10-6-2021 # Don't blame Mobius... I made this mess :) # Code displays Squeeze Watch Prediction Index. # Depending on volume, a score of less then 25 could signal an impeding Squeeze. def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100; def squeezeIndex = Round(squeezePrediction * 10000, 0); def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100; def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2); def squeezeIndexOn = squeezeIndex <= 0; rec counter = if squeezeIndexOn then counter[1] + 1 else 0; def deepSqueeze = squeezeIndex <= -20; rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0; rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1]; #---------------------------- [ Plots Some Dots ] ----------------------------- Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS); Squeeze.SetLineWeight(5); Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED); Squeeze.SetDefaultColor(Color.RED); #------------------------------------------------------------------------------ # Make the SI bar look pretty :) #AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE); def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0 else Double.NaN; #-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------- # # I changed this Mobius code to show orange during initial squeeze # and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better # than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more # than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5. # Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride # at all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect # my ignorance of the craft :) # #---------------------------------------------------------------------------------------------------- #AddLabel(!IsNaN(Squeeze), " >>> Squeeze <<< ", if IsAscending(Momo) #then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226)); def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0; plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0; zero.SetPaintingStrategy(PaintingStrategy.POINTS); zero.SetLineWeight(5); zero.SetDefaultColor(Color.GREEN);
Option 2
Code:declare lower; script normalizer { input data = close; input Min = -1; input Max = 1; input length = 50; def hhData = Highest(data, length); def llData = Lowest(data, length); plot resized = (((Max - Min) * (data - llData)) / (hhData - llData)) + Min; } ### ERGODIC OSCILLATOR ### input longLength = 25; input shortLength = 13; input signalLength = 8; input averageType = AverageType.EXPONENTIAL; plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal); ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE); ErgodicOsc.SetLineWeight(3); ErgodicOsc.DefineColor("Positive", Color.UPTICK); ErgodicOsc.DefineColor("Negative", Color.DOWNTICK); ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative")); ### SQUEEZE ### input length = 21; #hint length: Length for average calculation. input price = close; input SDmult = 2.0; input ATRmult = 1.5; def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length); plot Momo = normalizer(Inertia(price - K / 2, length)); Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Momo.SetLineWeight(5); Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN else if Momo > 0 and Momo < Momo[1] then Color.BLUE else if Momo < 0 and Momo < Momo[1] then Color.RED else Color.YELLOW); #--------------- [ Metrics From Mobius ] --------------- def SD = StDev(close, length); def Avg = Average(close, length); def ATR = Average(TrueRange(high, close, low), length); def SDup = normalizer(Avg + (SDmult * SD)); def ATRup = normalizer(Avg + (ATRmult * ATR)); plot Squeeze = if SDup < ATRUp then 0 else Double.NaN; #------------------------------------------------------------------------------------------ # David M.(Some Random Alien) 10-6-2021 # Don't blame Mobius... I made this mess :) # Code displays Squeeze Watch Prediction Index. # Depending on volume, a score of less then 25 could signal an impeding Squeeze. def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100; def squeezeIndex = Round(squeezePrediction * 10000, 0); def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100; def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2); def squeezeIndexOn = squeezeIndex <= 0; rec counter = if squeezeIndexOn then counter[1] + 1 else 0; def deepSqueeze = squeezeIndex <= -20; rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0; rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1]; #---------------------------- [ Plots Some Dots ] ----------------------------- Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS); Squeeze.SetLineWeight(5); Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED); Squeeze.SetDefaultColor(Color.RED); #------------------------------------------------------------------------------ # Make the SI bar look pretty :) #AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE); def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0 else Double.NaN; #-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------- # # I changed this Mobius code to show orange during initial squeeze # and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better # than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more # than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5. # Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride # at all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect # my ignorance of the craft :) # #---------------------------------------------------------------------------------------------------- #AddLabel(!IsNaN(Squeeze), " >>> Squeeze <<< ", if IsAscending(Momo) #then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226)); def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0; plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0; zero.SetPaintingStrategy(PaintingStrategy.POINTS); zero.SetLineWeight(5); zero.SetDefaultColor(Color.GREEN);
Option 3
Code:# filename: MR__EZ_Squeeze_ErgodicOsc_Combo_ declare lower; script normalizer { input data = close; input Min = -1; input Max = 1; input length = 50; def hhData = Highest(data, length); def llData = Lowest(data, length); plot resized = (((Max - Min) * (data - llData)) / (hhData - llData)) + Min; } ### ERGODIC OSCILLATOR ### input longLength = 25; input shortLength = 13; input signalLength = 8; input averageType = AverageType.EXPONENTIAL; plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal); ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE); ErgodicOsc.SetLineWeight(3); ErgodicOsc.DefineColor("Positive", Color.WHITE); #Color.UPTICK); ErgodicOsc.DefineColor("Negative", Color.WHITE); #Color.DOWNTICK); ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative")); ### SQUEEZE ### input length = 21; #hint length: Length for average calculation. input price = close; input SDmult = 2.0; input ATRmult = 1.5; def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length); plot Momo = normalizer(Inertia(price - K / 2, length)); Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Momo.SetLineWeight(5); Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN else if Momo > 0 and Momo < Momo[1] then Color.BLUE else if Momo < 0 and Momo < Momo[1] then Color.RED else Color.YELLOW); #--------------- [ Metrics From Mobius ] --------------- def SD = StDev(close, length); def Avg = Average(close, length); def ATR = Average(TrueRange(high, close, low), length); def SDup = normalizer(Avg + (SDmult * SD)); def ATRup = normalizer(Avg + (ATRmult * ATR)); plot Squeeze = if SDup < ATRUp then 0 else Double.NaN; #------------------------------------------------------------------------------------------ # David M.(Some Random Alien) 10-6-2021 # Don't blame Mobius... I made this mess :) # Code displays Squeeze Watch Prediction Index. # Depending on volume, a score of less then 25 could signal an impeding Squeeze. def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100; def squeezeIndex = Round(squeezePrediction * 10000, 0); def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100; def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2); def squeezeIndexOn = squeezeIndex <= 0; rec counter = if squeezeIndexOn then counter[1] + 1 else 0; def deepSqueeze = squeezeIndex <= -20; rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0; rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1]; #---------------------------- [ Plots Some Dots ] ----------------------------- Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS); Squeeze.SetLineWeight(5); Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED); Squeeze.SetDefaultColor(Color.RED); #------------------------------------------------------------------------------ # Make the SI bar look pretty :) #AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE); def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0 else Double.NaN; #-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------- # # I changed this Mobius code to show orange during initial squeeze # and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better # than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more # than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5. # Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride # at all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect # my ignorance of the craft :) # #---------------------------------------------------------------------------------------------------- #AddLabel(!IsNaN(Squeeze), " >>> Squeeze <<< ", if IsAscending(Momo) #then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226)); def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0; plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0; zero.SetPaintingStrategy(PaintingStrategy.POINTS); zero.SetLineWeight(5); zero.SetDefaultColor(Color.GREEN);
Hope this helps...
Good Luck and Good Trading
Credits: Thanks to Mobius and Some Random Alien for the Squeeze portion of the code...
Start a new thread and receive assistance from our community.
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.
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.