Is it possible to align two studies against 0 (sea line)?

alelkid

New member
I'm trying to figure out in my custom study how to align two studies, MACD and Ergodisc on the same chart (plot) so that sea line for MACD and Ergodisc are the same. Tried to normalize but it didn't work. Would appreciate any help.
 
Solution
I'm trying to figure out in my custom study how to align two studies, MACD and Ergodisc on the same chart (plot) so that sea line for MACD and Ergodisc are the same. Tried to normalize but it didn't work. Would appreciate any help.

See if this helps

Screenshot-2023-01-04-135025.png
Ruby:
#MACD_ErgodicOsc Normalized
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};

plot Value;
plot Avg;
switch (AverageType) {
case SMA:
    Value = Average(close, fastLength) - Average(close, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
    Avg = ExpAverage(Value, MACDLength);
}

plot Diff = Value - Avg...
I'm trying to figure out in my custom study how to align two studies, MACD and Ergodisc on the same chart (plot) so that sea line for MACD and Ergodisc are the same. Tried to normalize but it didn't work. Would appreciate any help.

See if this helps

Screenshot-2023-01-04-135025.png
Ruby:
#MACD_ErgodicOsc Normalized
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};

plot Value;
plot Avg;
switch (AverageType) {
case SMA:
    Value = Average(close, fastLength) - Average(close, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
    Avg = ExpAverage(Value, MACDLength);
}

plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

script normalizePlot {
    input data = close;
    input newRngMin = -.2;
    input newRngMax = .2;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData -
llData )) + newRngMin;
}

input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageTypeE = AverageType.Exponential;

#plot ErgodicOsc = TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal;
plot ErgodicOsc = normalizePlot(reference ErgodicOsc());

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"));
ZeroLine.SetDefaultColor(GetColor(7));;
 
Solution
Hey, I've checked the script a bit, it's nice but shows it's a complex so may not run quickly. Here's my version which uses StDev to adjust one to another (slightly modified version of the script from Eric)

# https://usethinkscript.com/threads/macd-with-bollinger-bands-indicator-for-thinkorswim.287/

# TS_MACD_BB
# By Eric Purdy, ThinkScripter LLC
# http://www.thinkscripter.com
# [email protected]
# Last Update 07 Feb 2011

declare lower;
input price = close;
input BBlength = 10;
input BBNum_Dev = 1.0;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;
input ERGODICLongLength = 2;
input ERGODICShortLength = 10;
input ERGODICSignalLength = 36;
input ERGODICAverageType = {"SIMPLE", default "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};
input ShowMACDDots = No;

def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);

# plot MACD_Dots = MACD_Data;


# Ergodic
def Ergodic_Data = ErgodicOsc("long length" = ERGODICLongLength, "short length" = ERGODICShortLength, "signal length" = ERGODICSignalLength, "average type" = ERGODICAverageType).ErgodicOsc;
# def Ergodic_Max = Max(Ergodic_Data);

def Ergodic_Data_Max = Max(Ergodic_Data, TickSize());
def MACD_Data_Max = Max(MACD_Data, TickSize());

#Normalize MAC and Ergodic scales
def ERGO_Scale = StDev(MACD_Data) / StDev(Ergodic_Data);

plot eo = Ergodic_Data * ERGO_Scale;
eo.AssignValueColor(if Ergodic_Data < 0 then Color.RED else Color.GREEN);
eo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot MACD_Line = MACD_Data;


plot BB_Upper = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).UpperBand;
plot BB_Lower = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).Lowerband;
plot BB_Midline = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).MidLine;

BB_Upper.SetDefaultColor(Color.GRAY);
BB_Lower.SetDefaultColor(Color.GRAY);
BB_Midline.SetDefaultColor(Color.GRAY);
BB_Midline.SetStyle(Curve.SHORT_DASH);

MACD_Line.SetDefaultColor(Color.WHITE);
MACD_Line.AssignValueColor(
if MACD_Line > 0 then if MACD_Line > MACD_Line[1] then Color.GREEN else Color.DARK_GREEN
else if MACD_Line < 0 and MACD_Line > MACD_Line[1] then Color.DARK_RED else Color.RED);



#MACD_Dots.SetStyle(Curve.POINTS);
#MACD_Dots.SetLineWeight(2);
#MACD_Dots.AssignValueColor(if MACD_Line > MACD_Line[1] then Color.White
#else Color.DARK_RED);

plot eoDots = eo;
eoDots.SetStyle(Curve.POINTS);
eoDots.SetLineWeight(2);
eoDots.AssignValueColor(if eo > eo[1] then Color.White else Color.DARK_RED);

plot zero = 0;
zero.AssignValueColor(if MACD_Line < 0 then Color.RED else Color.GREEN);
zero.SetLineWeight(2);
 
Last edited:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
249 Online
Create Post

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