Help with VolAvg code

J

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));
 
BenTen

BenTen

Administrative
Staff
VIP
Can you clarify? I don't get the problem here.

Why do you have multiple of the AssignBackgroundColor?
 
J

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

joshua74133

Member
VIP
Ok I solved the code to change the screen. Is there a way to code so when I get a red candle and green vol bar it will change the screen green?
 
J

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));
 
J

joshua74133

Member
VIP
Hey Ben is there no way to write a script for what I'm asking? Alert when I have a Red HA candle and green volume bar? The rest of it I think I can figure out
 
BenTen

BenTen

Administrative
Staff
VIP
@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
 
J

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

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:

Similar threads

Top