Hi folks, I'm new to the forum and relatively new to thinkscript. I saw this awesome library here and decide to try out a few ideas.

My idea was to keep a running total of the accumulation and distribution volume based on the arbitrary measure that a green day volume is accumulation and red day volume is distribution. But I only want to add the % volume that is above/below the average. So for example if today is a green day, and volume is 50% of average, I only want to add 50% of the volume to the counter.

The logic I am trying to code is the following:

I think my definition of UpVol and DnVol is messed up. Or logic is messed up. Thanks for any help!

Code:

```
#Counter
declare lower;
Def event = close >= close[1];
Def count = if event then count[1] + 1 else count[1];
Plot total = count;
```

My idea was to keep a running total of the accumulation and distribution volume based on the arbitrary measure that a green day volume is accumulation and red day volume is distribution. But I only want to add the % volume that is above/below the average. So for example if today is a green day, and volume is 50% of average, I only want to add 50% of the volume to the counter.

The logic I am trying to code is the following:

- Accumulation volume = if close > open, then add today's volume * (today's volume / average volume) to UpVolume counter
- Distribution volume = if close < open, then add today's volume * (today's volume / average volume) to DnVolume counter

Code:

```
declare lower;
def AvgVolume = average (volume, 10); #average volume
def RelVolume = volume / AvgVolume; #today's relative volume to average
def NewVolume = volume * RelVolume; #today's volume * Relative volume ratio
def UpVol = 0 #up volume counter initiated at 0
def DnVol = 0; #down volume counter initiated at 0
plot AccumVol = if close > open
then NewVolume+ UpVol[1] else UpVol[1] + 0; #if today is green, add today's Upvolume to yesterday's UpVol ounter, else add 0
plot DistVol = if Close < open
then DnVol + DnVol[1] else DnVol[1] +0; #if today is red, add today's Downvolume to yesterday's DnVol counter
```

I think my definition of UpVol and DnVol is messed up. Or logic is messed up. Thanks for any help!

Last edited: