Combine MACD and OBV together?

R

RegularRob

New member
VIP
Im having issues with plot upsignal and plot downsignal. This is a combination of OBV and MACD. I would like to get a signal only when OBV crosses abovesignal line and when MACD fast length crosses slow length. And a signal for the opposite direction as well. Can anyone help me out? thanks

Code:
declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = yes;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

def obv = reference OnBalanceVolume();

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);
plot UpSignal = if obvm crosses above signal and value is above avg then signal else Double.NaN;
plot DownSignal = if obvm crosses below signal and signal is below avg then signal else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Signal.SetDefaultColor(GetColor(2));

OBVM.SetDefaultColor(GetColor(5));
OBVM.SetPaintingStrategy(PaintingStrategy.line);
OBVM.SetLineWeight(3);
OBVM.DefineColor("Positive and Up", Color.GREEN);
OBVM.DefineColor("Positive and Down", Color.DARK_GREEN);
OBVM.DefineColor("Negative and Down", Color.RED);
OBVM.DefineColor("Negative and Up", Color.DARK_RED);
OBVM.AssignValueColor(if OBVM >= 0 then if OBVM > OBVM[1] then OBVM.Color("Positive and Up") else OBVM.Color("Positive and Down") else if OBVM < OBVM[1] then OBVM.Color("Negative and Down") else OBVM.Color("Negative and Up"));
 
R

RegularRob

New member
VIP
I also cant get the MACD to show up for some reason???
 
D

diazlaz

Well-known member
2019 Donor
VIP
try changes these two lines:

plot UpSignal = if obvm crosses above signal and value > avg then signal else Double.NaN;
plot DownSignal = if obvm crosses below signal and signal < avg then signal else Double.NaN;
 
R

RegularRob

New member
VIP
try changes these two lines:

plot UpSignal = if obvm crosses above signal and value > avg then signal else Double.NaN;
plot DownSignal = if obvm crosses below signal and signal < avg then signal else Double.NaN;
That fixed the error i was getting on the code, but for some reason the MACD isnt showing up so overall the script isnt working. any ideas?
 
horserider

horserider

Well-known member
VIP
Good luck with this one. Massive scaling differences is my guess.
 

Similar threads

Top