OnBalanceVolume OBV OBVM Scan, Watchlist, Label For ThinkOrSwim

Awesome! Could also help me combine an additional indicator? It is the built in ROC indicator from TOS.
Basically I would like arrows to plot only if the OBV UpArrow is true and a confirmed ROC is greater than ZeroLine. And the opposite for the DnArrow so then plot the OBV DnArrow when combined with the ROC when its smaller than ZeroLine and confirmed.

input length = 14;
input signalLength = 26;
input averageType = AverageType.EXPONENTIAL;
input showarrows = yes;

def OBV = TotalSum(Sign(close - close[1]) * volume);
def OBVM = MovingAverage(averageType, OBV, length);
def Signal = MovingAverage(averageType, OBVM, signalLength);
def price = close ;
def up = OBVM > Signal and Signal < OBVM ;
def dn = OBVM < Signal and Signal > OBVM ;
def neutral = between(close,min(OBVM,SIGNAL),max(SIGNAL,OBVM));
def x = CompoundValue(1,
if x[1]>=0 and (dn[1] or up[1]==0) and up
then 1
else if x[1]>=1 and (up or !dn)
then x[1]+1
else 0, 1);
def y = CompoundValue(1,
if y[1]<=0 and (up[1] or dn[1]==0) and dn
then 1
else if y[1]>=1 and (dn or !up)
then y[1]+1
else 0, 1);
def uparrow = if showarrows and x == 1 and up then 1 else 0;
#uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#uparrow.SetLineWeight(1);
#uparrow.SetDefaultColor(Color.yellow);

def dnarrow = if showarrows and y == 1 and dn then 1 else 0;
#dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#dnarrow.SetLineWeight(1);
#dnarrow.SetDefaultColor(Color.white);

###

input length2 = 14;
input colorNormLength = 14;

assert(length2 > 0, "'length' must be positive: " + length2);

def ROC = if price[length2] != 0 then (price / price[length2] - 1) * 100 else 0;
def ZeroLine = 0;

#ROC.DefineColor("Highest", Color.YELLOW);
#ROC.DefineColor("Lowest", Color.LIGHT_RED);
#ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
#ZeroLine.SetDefaultColor(GetColor(5));

def highestROC = HighestAll(ROC);
def lowestROC = LowestAll(ROC);
def midPtHighestROC = highestROC/2;
def midPtLowestROC = lowestROC/2;

#highestROC.setLineWeight(3);
#lowestROC.setLineWeight(3);
#highestROC.setDefaultColor(Color.Red);
#lowestROC.setDefaultColor(Color.Green);

#midPtHighestROC.setLineWeight(1);
#midPtLowestROC.setLineWeight(1);
#midPtHighestROC.setStyle(Curve.Short_Dash);
#midPtLowestROC.setStyle(Curve.Short_Dash);
#midPtHighestROC.setDefaultColor(Color.light_red);
#midPtLowestROC.setDefaultColor(Color.light_green);


def extremeHigh = ROC < HighestROC and ROC >= midPtHighestROC;
def extremeLow = ROC > LowestROC and ROC <= midPtLowestROC;
def ROCUpSignal = extremeLow and (ROC > ROC[1]);
def ROCDownSignal = extremeHigh and (ROC < ROC[1]);

plot bullSignal = if UpArrow and ROC > ZeroLine and ZeroLine < ROC then UpArrow else double.nan;
plot bearSignal = if DnArrow and ROC < ZeroLine and ZeroLine > ROC then DnArrow else double.nan;

bullSignal.setPaintingStrategy(PaintingStrategy.Arrow_Up);
bullSignal.setDefaultColor(Color.Green);
bullSignal.setLineWeight(3);

bearSignal.setPaintingStrategy(PaintingStrategy.Arrow_Down);
bearSignal.setDefaultColor(Color.Red);
bearSignal.setLineWeight(3);

Thanks for providing your code. You were very close to what you requested! See if the following helps.

To have and confirmed ROC, I am assuming that you want the ROC on the bar before and during the arrow is the same, either above zero or below zero for bullsignal/bearsignal.

Code:
plot bullSignal = if UpArrow and ROC > ZeroLine and ROC[1] > ZeroLine[1] then UpArrow else double.nan;
plot bearSignal = if DnArrow and ROC < ZeroLine and ROC[1] < ZeroLine[1] then DnArrow else double.nan;

The [1] in the above is the ROC bar before the Uparrow/Downarrow.

Also your code needed the Arrows to be boolean as Uparrow/Downarrow are defined as 1/0 (true/false) rather than a price.

Here is the combined code with the above adjustments



Ruby:
input length = 14;
input signalLength = 26;
input averageType = AverageType.EXPONENTIAL;
input showarrows = yes;

def OBV = TotalSum(Sign(close - close[1]) * volume);
def OBVM = MovingAverage(averageType, OBV, length);
def Signal = MovingAverage(averageType, OBVM, signalLength);
def price = close ;
def up = OBVM > Signal and Signal < OBVM ;
def dn = OBVM < Signal and Signal > OBVM ;
def neutral = between(close,min(OBVM,SIGNAL),max(SIGNAL,OBVM));
def x = CompoundValue(1,
if x[1]>=0 and (dn[1] or up[1]==0) and up
then 1
else if x[1]>=1 and (up or !dn)
then x[1]+1
else 0, 1);
def y = CompoundValue(1,
if y[1]<=0 and (up[1] or dn[1]==0) and dn
then 1
else if y[1]>=1 and (dn or !up)
then y[1]+1
else 0, 1);
def uparrow = if showarrows and x == 1 and up then 1 else 0;
#uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#uparrow.SetLineWeight(1);
#uparrow.SetDefaultColor(Color.yellow);

def dnarrow = if showarrows and y == 1 and dn then 1 else 0;
#dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#dnarrow.SetLineWeight(1);
#dnarrow.SetDefaultColor(Color.white);

###

input length2 = 14;
input colorNormLength = 14;

assert(length2 > 0, "'length' must be positive: " + length2);

def ROC = if price[length2] != 0 then (price / price[length2] - 1) * 100 else 0;
def ZeroLine = 0;

#ROC.DefineColor("Highest", Color.YELLOW);
#ROC.DefineColor("Lowest", Color.LIGHT_RED);
#ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
#ZeroLine.SetDefaultColor(GetColor(5));

def highestROC = HighestAll(ROC);
def lowestROC = LowestAll(ROC);
def midPtHighestROC = highestROC/2;
def midPtLowestROC = lowestROC/2;

#highestROC.setLineWeight(3);
#lowestROC.setLineWeight(3);
#highestROC.setDefaultColor(Color.Red);
#lowestROC.setDefaultColor(Color.Green);

#midPtHighestROC.setLineWeight(1);
#midPtLowestROC.setLineWeight(1);
#midPtHighestROC.setStyle(Curve.Short_Dash);
#midPtLowestROC.setStyle(Curve.Short_Dash);
#midPtHighestROC.setDefaultColor(Color.light_red);
#midPtLowestROC.setDefaultColor(Color.light_green);


def extremeHigh = ROC < HighestROC and ROC >= midPtHighestROC;
def extremeLow = ROC > LowestROC and ROC <= midPtLowestROC;
def ROCUpSignal = extremeLow and (ROC > ROC[1]);
def ROCDownSignal = extremeHigh and (ROC < ROC[1]);

plot bullSignal = if UpArrow and ROC > ZeroLine and ROC[1] > ZeroLine[1] then UpArrow else double.nan;
plot bearSignal = if DnArrow and ROC < ZeroLine and ROC[1] < ZeroLine[1] then DnArrow else double.nan;

bullSignal.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullSignal.setDefaultColor(Color.Green);
bullSignal.setLineWeight(3);

bearSignal.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearSignal.setDefaultColor(Color.Red);
bearSignal.setLineWeight(3);
 
Thank SleepyZ! I'm not a programer but I get the idea based on your scripts and have learned lots.
I really appreciate the amazing support. You are brilliant! Cheers!
 
Hello, I'm trying to get a script that paints arrows when the moving average crosses the On Balance Volume (OBV) line. I've got it to the point where it's painting arrows, but they're painting on the lower part of the study and not where the crossover occurs. Here's the code I have so far. I am NOT a coder and have basically piecemealed this together so I'm sure it's something obvious to anyone with true experience. Any help getting these arrows to paint correctly would be greatly appreciated. Thanks!

declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;
input crossingType - {default Bullish, Bearish};

def obv = reference OnBalanceVolume();

plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));

plot signalUP = Crosses(OBVM, Signal, CrossingDirection.Above);

plot signalDN = Crosses(OBVM, Signal, CrossingDirection.Below);

signalUP.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_UP);

signalUP.DefineColor("Bullish", GetColor(1));

signalDN.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_DOWN);

signalDN.DefineColor("Bearish", GetColor(1));

#Trigger alerts

alert(signalUP, "Crossover", Alert.Bar, Sound.Ding);

alert(signalDN, "Crossover", Alert.Bar, Sound.Ding);
 
Hello, I'm trying to get a script that paints arrows when the moving average crosses the On Balance Volume (OBV) line. I've got it to the point where it's painting arrows, but they're painting on the lower part of the study and not where the crossover occurs. Here's the code I have so far. I am NOT a coder and have basically piecemealed this together so I'm sure it's something obvious to anyone with true experience. Any help getting these arrows to paint correctly would be greatly appreciated. Thanks!

declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;
input crossingType - {default Bullish, Bearish};

def obv = reference OnBalanceVolume();

plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));

plot signalUP = Crosses(OBVM, Signal, CrossingDirection.Above);

plot signalDN = Crosses(OBVM, Signal, CrossingDirection.Below);

signalUP.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_UP);

signalUP.DefineColor("Bullish", GetColor(1));

signalDN.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_DOWN);

signalDN.DefineColor("Bearish", GetColor(1));

#Trigger alerts

alert(signalUP, "Crossover", Alert.Bar, Sound.Ding);

alert(signalDN, "Crossover", Alert.Bar, Sound.Ding);

Let me know if this plots how you wanted -- the main issue as to why it was defaulting to plotting lower was the "declare lower" statement at the top of your code. Made very few other minor modifications:

Code:
input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;
input crossingType = {default Bullish, Bearish};

def obv = reference OnBalanceVolume();

def OBVM = MovingAverage(averageType, obv, length);
def Signal = MovingAverage(averageType, OBVM, signalLength);


plot signalUP = Crosses(OBVM, Signal, CrossingDirection.ABOVE);

plot signalDN = Crosses(OBVM, Signal, CrossingDirection.BELOW);

signalUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

signalUP.DefineColor("Bullish", GetColor(1));

signalDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

signalDN.DefineColor("Bearish", GetColor(1));

#Trigger alerts

Alert(signalUP, "Crossover", Alert.BAR, Sound.Ding);

Alert(signalDN, "Crossover", Alert.BAR, Sound.Ding);
 

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

Thread starter Similar threads Forum Replies Date
W BuySell Volume, PreMarket OBV & CumuVol For ThinkOrSwim Custom 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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