## ########################################################
#ToS OnBalanceVolumeModified
## ########################################################
input signalLength = 10;
input averageType = "exponential" ;
def obvm = OnBalanceVolumeModified().obVM;
def ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;
def crossUP = if obvm crosses above ema then ema else double.NaN ;
def crossDN = if obvm crosses below ema then obvm else double.NaN ;
## ########################################################
# Charting & Formatting
DefineGlobalColor("bull", Color.green) ;
DefineGlobalColor("bear", Color.red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;
AddLabel(yes,
if obvm crosses above ema then "obv cross up!" else
if obvm crosses below ema then "obv cross down!" else
if obvm > ema then "obv trending above" else " | obv trending below",
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
input paintCandles = yes ;
AssignPriceColor(
if !paintCandles then color.current else
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
## ########################################################
#ToS OnBalanceVolumeModified
## ########################################################
declare lower;
declare real_size;
DefineGlobalColor("bull", Color.green) ;
DefineGlobalColor("bear", Color.red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;
input signalLength = 10;
input averageType = "exponential" ;
plot obvm = OnBalanceVolumeModified().obVM;
plot ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;
addcloud(obvm, ema, GlobalColor("bull"), GlobalColor("bear"));
plot crossUP = if obvm crosses above ema then ema else double.NaN ;
crossUP.SetPaintingStrategy(PaintingStrategy.ARROW_up);
crossUP.SetDefaultColor(GlobalColor("crossup")) ;
crossUP.SetLineWeight(3);
plot crossDN = if obvm crosses below ema then obvm else double.NaN ;
crossDN.SetPaintingStrategy(PaintingStrategy.ARROW_down);
crossDN.SetDefaultColor(GlobalColor("crossdn")) ;
crossDN.SetLineWeight(3);
input showLabel = yes ;
AddLabel(showLabel,
if obvm crosses above ema then "obv cross up!" else
if obvm crosses below ema then "obv cross down!" else
if obvm > ema then "obv trending above" else " | obv trending below",
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
input paintCandles = yes ;
AssignPriceColor(
if !paintCandles then color.current else
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
I've reviewed the code (#3) above and have the following comments/questions:
1) I'd like to code an upper OBV chart label. How can I modify the code to identify the moving average type, the moving average length, and color the label dark_green if the OBV closes above the moving average else color the label dark_red if the OBV closes below the moving average. Thanks...
## ########################################################
# OnBalanceVolumeModified
# mike request
## ########################################################
input signalLength = 10;
input averageType = "exponential" ;
def obvm = OnBalanceVolumeModified().obVM;
def ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;
def crossUP = if obvm crosses above ema then ema else double.NaN ;
def crossDN = if obvm crosses below ema then obvm else double.NaN ;
## ########################################################
# Charting & Formatting
DefineGlobalColor("bull", Color.dark_green) ;
DefineGlobalColor("bear", Color.dark_red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;
AddLabel(yes,
"OBVm average used: " +averageType +" | average length: " +signalLength+
if obvm crosses above ema then " | obv cross up!" else
if obvm crosses below ema then " | obv cross down!" else
if obvm > ema then " | obv trending above" else " | obv trending below",
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
input paintCandles = no ;
AssignPriceColor(
if !paintCandles then color.current else
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
Hello All,
Would it be possible to add in a label to tell me how much of the numerical difference and percentage? Sometimes I like to see values changes to determine my exit.
obvm - ema = positive value or negative value
thanks,
jrj4774
def numerical Difference = put your definition here ;
def percentage = put your definition here ;
AddLabel(yes, "difference: " +numerical Difference +" | pct: " +percentage,
if percentage>0 then color.green else color.red);
You left off a semicolonI'm completely a newbie here, and I'm trying to find similar syntax in how the line/logic statement.
But I am getting an error message on the value differences. I tried both way I can think of.
and then the label, I'm completely lost.
Thanks,
jrj4774
todef numerical Difference = obvm - ema
Every thinkscript statement must end with a semicolon.def numerical Difference = obvm - ema ;
@merryDay Thank you for the insight...
I was able to successfully add in the script above and I tried to add another logic to the code -
I was trying to make the numericaldifference value turn a color just like the PCT%.
In line 47/48 it worked and tested.
View attachment 25994
I added the original label as you rewcommened. But then I wanted to add another logical with making the difference difference color when it's positive or negative.
AddLabel(yes, "Variance: " + numericalDifference + " | % PCT%: " + percentage,
if percentage > 0 then Color.GREEN else Color.RED,
if numericalDifference > 0 then Color.GREEN else Color.RED);
What am I missing?
View attachment 25995
Thank you for encouragement on coding... Your the MASTER!!!
Thanks,
jrj4774
Think about it: the percentage is always going to be greater or lesser than 0.if percentage > 0 then COLOR.GREEN else COLOR.RED ):
And eliminate the 2nd if statement.if percentage >= 0 then COLOR.GREEN else COLOR.RED ):
@merryDay
It make sense when you said about PCT%. I think I should of mention that I wanted the variance value to be a different color label.
I was able to add the script below -
def percentage = (obvm-ema)/ema;
def numericalDifference = obvm - ema;
AddLabel(yes,"PCT%: " + percentage,
if percentage >=0 then COLOR.GREEN else COLOR.RED);
AddLabel(yes, "Variance: " + numericalDifference ,
if numericalDifference> 0 then Color.GREEN else Color.RED);
But I am having trouble with the PCT% if it's less than 0, then it should be red. I tried adding the logical you suggested above, PCT should be negative right now because the variance is negative number. I don't see it changed. Is the logic "def percentage = (obvm-ema)/ema;" incorrect?
Thanks,
jrj4774
View attachment 25999
def percentage = (obvm - ema) / ema;
def numericalDifference = obvm - ema;
AddLabel(
yes,
"PCT%: " + AsText(Round(percentage * 100, 2)) + "%",
if percentage >= 0 then Color.GREEN else Color.RED
);
AddLabel(
yes,
"Variance: " + numericalDifference,
if numericalDifference >= 0 then Color.GREEN else Color.RED
);
Do you have the updated code and can you share it?@merryDay Thank you for the insight...
I was able to successfully add in the script above and I tried to add another logic to the code -
I was trying to make the numericaldifference value turn a color just like the PCT%.
In line 47/48 it worked and tested.
View attachment 25994
I added the original label as you rewcommened. But then I wanted to add another logical with making the difference difference color when it's positive or negative.
AddLabel(yes, "Variance: " + numericalDifference + " | % PCT%: " + percentage,
if percentage > 0 then Color.GREEN else Color.RED,
if numericalDifference > 0 then Color.GREEN else Color.RED);
What am I missing?
View attachment 25995
Thank you for encouragement on coding... Your the MASTER!!!
Thanks,
jrj4774
looks great!@merryDay
It make sense when you said about PCT%. I think I should of mention that I wanted the variance value to be a different color label.
I was able to add the script below -
def percentage = (obvm-ema)/ema;
def numericalDifference = obvm - ema;
AddLabel(yes,"PCT%: " + percentage,
if percentage >=0 then COLOR.GREEN else COLOR.RED);
AddLabel(yes, "Variance: " + numericalDifference ,
if numericalDifference> 0 then Color.GREEN else Color.RED);
But I am having trouble with the PCT% if it's less than 0, then it should be red. I tried adding the logical you suggested above, PCT should be negative right now because the variance is negative number. I don't see it changed. Is the logic "def percentage = (obvm-ema)/ema;" incorrect?
Thanks,
jrj4774
View attachment 25999
## ########################################################
#ToS OnBalanceVolumeModified
## ########################################################
declare lower;
declare real_size;
DefineGlobalColor("bull", Color.green) ;
DefineGlobalColor("bear", Color.red) ;
DefineGlobalColor("crossup", Color.cyan) ;
DefineGlobalColor("crossdn", Color.magenta) ;
input signalLength = 10;
input averageType = "exponential" ;
plot obvm = OnBalanceVolumeModified().obVM;
plot ema = OnBalanceVolumeModified("signal length" = signalLength, "average type" = averageType).Signal; ;
addcloud(obvm, ema, GlobalColor("bull"), GlobalColor("bear"));
plot crossUP = if obvm crosses above ema then ema else double.NaN ;
crossUP.SetPaintingStrategy(PaintingStrategy.ARROW_up);
crossUP.SetDefaultColor(GlobalColor("crossup")) ;
crossUP.SetLineWeight(3);
plot crossDN = if obvm crosses below ema then obvm else double.NaN ;
crossDN.SetPaintingStrategy(PaintingStrategy.ARROW_down);
crossDN.SetDefaultColor(GlobalColor("crossdn")) ;
crossDN.SetLineWeight(3);
input showLabel = yes ;
AddLabel(showLabel,
if obvm crosses above ema then "obv cross up!" else
if obvm crosses below ema then "obv cross down!" else
if obvm > ema then "obv trending above" else " | obv trending below",
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
input paintCandles = yes ;
AssignPriceColor(
if !paintCandles then color.current else
if obvm crosses above ema then GlobalColor("crossup") else
if obvm crosses below ema then GlobalColor("crossdn") else
if obvm > ema then GlobalColor("bull") else GlobalColor("bear"));
def percentage = (obvm-ema)/ema;
def numericalDifference = obvm - ema;
AddLabel(yes,"PCT%: " + percentage,
if percentage >=0 then COLOR.GREEN else COLOR.RED);
AddLabel(yes, "Variance: " + numericalDifference ,
if numericalDifference> 0 then Color.GREEN else Color.RED);
declare upper;
input signalLength = 10;
input showLabel = yes;
input paintCandles = yes;
input ChartBubblesOn = yes;
# OBV with safe initialization inside compoundValue
def obvVal = compoundValue(1, if IsNaN(CompoundValue(1, OBV(), 0)) then 0 else OBV(), 0);
# EMA of OBV
def emaVal = ExpAverage(obvVal, signalLength);
# Plots
plot obvPlot = obvVal;
plot emaPlot = emaVal;
obvPlot.AssignValueColor(if obvVal > emaVal then Color.GREEN else Color.RED);
emaPlot.AssignValueColor(if obvVal > emaVal then Color.GREEN else Color.RED);
AddCloud(obvPlot, emaPlot, Color.GREEN, Color.RED);
# Cross conditions
def crossUpCond = obvVal[1] <= emaVal[1] and obvVal > emaVal;
def crossDownCond = obvVal[1] >= emaVal[1] and obvVal < emaVal;
# Cross arrows
plot crossUpPlot = if crossUpCond then emaVal else Double.NaN;
crossUpPlot.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
crossUpPlot.SetDefaultColor(Color.CYAN);
crossUpPlot.SetLineWeight(3);
plot crossDownPlot = if crossDownCond then obvVal else Double.NaN;
crossDownPlot.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
crossDownPlot.SetDefaultColor(Color.MAGENTA);
crossDownPlot.SetLineWeight(3);
# Labels
AddLabel(showLabel,
if crossUpCond then "OBV Cross Up!" else
if crossDownCond then "OBV Cross Down!" else
if obvVal > emaVal then "OBV Trending Above" else "OBV Trending Below",
if crossUpCond then Color.CYAN else
if crossDownCond then Color.MAGENTA else
if obvVal > emaVal then Color.GREEN else Color.RED);
# Candle coloring
AssignPriceColor(
if !paintCandles then Color.CURRENT else
if crossUpCond then Color.CYAN else
if crossDownCond then Color.MAGENTA else
if obvVal > emaVal then Color.GREEN else Color.RED);
# Chart bubbles
AddChartBubble(ChartBubblesOn and crossUpCond and !crossUpCond[1], close, "Entering Acceleration", Color.GREEN);
AddChartBubble(ChartBubblesOn and crossDownCond and !crossDownCond[1], close, "Entering Deceleration", Color.RED);
OBV ema , can someone help?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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.