Help with VolAvg code

joshua74133

Member
VIP
It says VolAvg is whats wrong. im using this on a speed chart to change the background color to match the volume bars... i know this sounds crazy

Code:
input length = 50;

plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));

AssignBackgroundColor( if ("Up")
then Color. GREEN
else Color.CURRENT);

AssignBackgroundColor( if ("Down")
then Color. red
else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
 

joshua74133

Member
VIP
On mine VolAvg is red. I may have wrote it wrong (still learning) heres what I really want, I would love to figure out a way to have the screen turn green when theres a red heikin ashi candle and green volume avg bar.
 

joshua74133

Member
VIP
this is what im talking about ben. I got the volume script coded... now what i want is to figure out how to add a script that will assign background color if there is a red heikin ashi candle and green volume bar. i want the background color to change to green... this has proven to be a great way to find scalps or reversals.

input length = 50;

plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));

AssignBackgroundColor( if close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
@joshua74133 I think a good starting point would be the Heiken Ashi code below.

Code:
# Heiken Ashi Candle Colors_v4 _Mobius (JQ)

# Heiken Ashi Candle Colors
# Mobius
# V01.06.2011

def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
haclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen
                 then color.green
                 else color.red);
# End Code HA Candles
 

joshua74133

Member
VIP
ok i got it all done except the alert. why is IF in red?

here's the script, the alert is at the bottom. thanks for your help

Code:
input price = close;
input fastLength = 9;
input slowLength = 20;
input averageType = AverageType.EXPONENTIAL;

plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.AssignValueColor(if FastMA > SlowMA then color.green else color.red);
SlowMA.AssignValueColor(if FastMA > SlowMA then color.green else color.red);

plot ArrowUp = if FastMA crosses above SlowMA
               then low
               else double.nan;
     ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     ArrowUP.SetLineWeight(3);
     ArrowUP.SetDefaultColor(Color.Green);


AssignBackgroundColor( if Fastma > slowma
then Color.BLUE
else Color.red);

   plot ArrowDN = if FastMA crosses below SlowMA
               then high
               else double.nan;
     ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     ArrowDN.SetLineWeight(3);
     ArrowDN.SetDefaultColor(Color.Red);

def countUP = if !isNaN(ArrowUp)
              then 1
              else if FastMA > SlowMA
                   then countUP[1] + 1
              else if !isNaN(ArrowDN)
                   then 0
                   else countUP[1];
def countDN = if !isNaN(ArrowDN)
              then 1
              else if FastMA < SlowMA
                   then countDN[1] + 1
              else if !isNaN(ArrowUP)
                   then 0
                   else countDN[1];
AddLabel(1, "Count UP = " + countUP, color.white);
AddLabel(1, "Count DN = " + countDN, color.white);
def CrossBar = if FastMA crosses SlowMa
               then barNumber()
               else double.nan;


input length = 50;

plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));


def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
haclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen
                 then color.green
                 else color.red);

AssignBackgroundColor( if  Fastma > slowma and HAclose < HAopen and close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));

Alert(if Fastma > slowma and HAclose < HAopen and close > close[1] then Vol.Color("Up"), " ", Alert.Bar, Sound.Bell);
 

rad14733

Well-known member
VIP
At the bottom of your Thinkscript Editor you should have an error which states:

Syntax error: An 'else' block expected 81:7

As this implies, you are using an if . . . then . . . else clause without the else...

Your Alert() function parameters are in the wrong order as well... Try this for your last line...

Ruby:
Alert(if Fastma > slowma and HAclose < HAopen and close > close[1] then 1 else 0, " ", Alert.Bar, Sound.Bell);
 
Last edited:

cabe1332

Active member
is there anyway to add a stipulation to this? like only alerts red HA candle green volume on the 50 or any ema?
Hi @joshua74133, just want to share what has been working for me as far reversals and scalping midday or during power hour. The discussion link thread below provides you with the Trend Reversal code/study. I use the study to scan for reversal, very accurate, and $$$. As soon as the ticker shows up on my watchlist, and there will by multiples, I quickly check the chart hi/lo, parabolic, net change, volume, RV1 value, MA Uptrending, and most of all the price must be above VWAP. These rules have been successful trades ratios for me. You can ride it up $$$, but keep an eye on reversals. I "F" the FOMO and just sell on Resistance $$$.

https://usethinkscript.com/d/183-trend-reversal-indicator-with-signals-for-thinkorswim

Create a watchlist scanner with:
Stock: Last - min/max price you prefer
Stock: Volume - min/max you prefer, but I have 2Mil min for liquidity
Study: TrendReversalScanner()."upArrow" is true within 2 bars # I got my study set for 1 or 2 minutes EXT unchecked

Good luck!

cabe1332
 

cabe1332

Active member
ill give it a read. thanks
By the way, to make it easier for me I changed the "Reversal" to either "Buy" or "Sell" signal. You may need to play with the settings.

I have my inputs as:

Code:
method:  high_low
show supply demand:  none
usemanualfigskip:  no
fibskip:  0.5

AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Buy " + round(low,2) else "" , if Colorbars == 3 then Color.plum else Color.UPTICK, no);
AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Sell " + round(high,2) else "" , if Colorbars == 3 then Color.green else Color.DOWNTICK, yes);

Good luck!

cabe1332
 

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.
Top