"CompoundValue"

JCN

New member
Hi think-Script community.

I found this code (see below) here https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/ and modified it to suit my purpose and it works really well as you can see in the photos below (the "def Condition" is only for demonstration purposes, this isn't my trade signal).

The first one gives me accumulated positive bars with a two-bar cushion (the within 2 bars added), once the cycle is broken it returns to zero.

The second chart with the modified 11th line ("else barUpCount[1]") you can see below it keeps accumulating and never returns to zero.

What I've been trying to do over the last few days unsuccessfully, is find whereby the total amount of signals in any given time spell, say one hour (see below 10-minute bars).

BAR 1 = 1 Result = 1
BAR 2 = 0 Result = 1
BAR 3 = 1 Result = 2
BAR 4 = 1 Result = 3
BAR 5 = 0 Result = 3
BAR 6 = 0 Result = 3
BAR 7 = 0 Result = 3
BAR 8 = 0 Result = 3
BAR 9 = 0 Result = 3
BAR 10 = 0 Result = 0

Then returning to zero and then restart the cycle, if no new signal occurs on the 6th bar after one hour having elapsed.

#1st CODE#

declare lower;
declare once_per_bar;
def zeroLine = 10;
plot pZeroLine = zeroLine;
pZeroLine.SetDefaultColor(Color.RED);
def upLine = 3;
plot pUpLine = upLine;
pUpLine.SetDefaultColor(Color.GREEN);
def Condition = (close is greater than reference VWAP()."VWAP" and high is not equal to low and close is greater than open and close is greater than close from 1 bars ago) within 2 bars;
def Conbar = Condition [0];
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else 0, 0);
plot pBarUpCount = if barUpCount > 0 then barUpCount else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.GREEN);

g3ru4cg.jpg




(#2nd CODE changed 11th line#)

def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else barUpCount[1], 0);

AGNP5IN.jpg


Anyone that can help? it would be much appreciated.

Thanking you in advance.

Jean-Claude
 
Last edited by a moderator:
Solution
Hi think-Script community.

I found this code (see below) here https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/ and modified it to suit my purpose and it works really well as you can see in the photos below (the "def Condition" is only for demonstration purposes, this isn't my trade signal).

The first one gives me accumulated positive bars with a two-bar cushion (the within 2 bars added), once the cycle is broken it returns to zero.

The second chart with the modified 11th line ("else barUpCount[1]") you can see below it keeps accumulating and never returns to zero.

What I've been trying to do over the last few days unsuccessfully, is find whereby the total amount of signals in any...
Hi think-Script community.

I found this code (see below) here https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/ and modified it to suit my purpose and it works really well as you can see in the photos below (the "def Condition" is only for demonstration purposes, this isn't my trade signal).

The first one gives me accumulated positive bars with a two-bar cushion (the within 2 bars added), once the cycle is broken it returns to zero.

The second chart with the modified 11th line ("else barUpCount[1]") you can see below it keeps accumulating and never returns to zero.

What I've been trying to do over the last few days unsuccessfully, is find whereby the total amount of signals in any given time spell, say one hour (see below 10-minute bars).

BAR 1 = 1 Result = 1
BAR 2 = 0 Result = 1
BAR 3 = 1 Result = 2
BAR 4 = 1 Result = 3
BAR 5 = 0 Result = 3
BAR 6 = 0 Result = 3
BAR 7 = 0 Result = 3
BAR 8 = 0 Result = 3
BAR 9 = 0 Result = 3
BAR 10 = 0 Result = 0

Then returning to zero and then restart the cycle, if no new signal occurs on the 6th bar after one hour having elapsed.

#1st CODE#

declare lower;
declare once_per_bar;
def zeroLine = 10;
plot pZeroLine = zeroLine;
pZeroLine.SetDefaultColor(Color.RED);
def upLine = 3;
plot pUpLine = upLine;
pUpLine.SetDefaultColor(Color.GREEN);
def Condition = (close is greater than reference VWAP()."VWAP" and high is not equal to low and close is greater than open and close is greater than close from 1 bars ago) within 2 bars;
def Conbar = Condition [0];
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else 0, 0);
plot pBarUpCount = if barUpCount > 0 then barUpCount else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.GREEN);

g3ru4cg.jpg




(#2nd CODE changed 11th line#)

def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else barUpCount[1], 0);

AGNP5IN.jpg


Anyone that can help? it would be much appreciated.

Thanking you in advance.

Jean-Claude

See if this helps.

It will count consecutive conbars as Histogram with count in a bubble above the Histogram bars.
A time interval is defined in minutes and the conbars within are counted and displayed in bubbles beneath the Histogram bars

The image shows a magenta VWAP line on the price graph

Screenshot-2022-10-28-131319.png
Ruby:
declare lower;
declare once_per_bar;

#Defines Interval in minutes to accumulate data
input minutes    = 60;
input multiplier = 1;
input showverticalline = yes;
input begin   = 0930;
input end     = 1600;
def bar       = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else bar[1] + 1;
def x         = bar % ((minutes * multiplier) / (GetAggregationPeriod() / 60000)) == 0;
AddVerticalLine(if showverticalline and SecondsFromTime(begin) >= 0
                then x
                else Double.NaN,
                color = Color.white, stroke = Curve.FIRM);
###################

def zeroLine = 10;
plot pZeroLine = zeroLine;
pZeroLine.SetDefaultColor(Color.RED);

#Conbar Defined
def upLine = 3;
plot pUpLine = upLine;
pUpLine.SetDefaultColor(Color.GREEN);
def Condition = (close is greater than reference VWAP()."VWAP" and high is not equal to low and close is greater than open and close is greater than close from 1 bars ago) within 2 bars;
def Conbar = Condition [0];

#Conbar when true displayed as Histogram and Consecutive Count in Bubble when true
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else if !conbar then 0 else barUpCount[1], 0);
plot pBarUpCount = if barUpCount > 0 then barUpCount else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.GREEN);
addchartBubble(pbarupcount, pbarupCount, pbarupcount);

#Conbar Cumulative Count in Bubble per Minutes Entered Above
def conbarsinterval = if x
                      then if conbar then 1 else 0
                      else if conbar
                      then conbarsinterval[1]+1
                      else conbarsinterval[1];

plot bottom = -5;#Bottom spacer to avoid hiding the Histogram
addchartBubble(conbarsinterval!=conbarsinterval[1], 0 , conbarsinterval, color.gray, no);
 
Solution
See if this helps.

It will count consecutive conbars as Histogram with count in a bubble above the Histogram bars.
A time interval is defined in minutes and the conbars within are counted and displayed in bubbles beneath the Histogram bars

The image shows a magenta VWAP line on the price graph
See if this helps.

It will count consecutive conbars as Histogram with count in a bubble above the Histogram bars.
A time interval is defined in minutes and the conbars within are counted and displayed in bubbles beneath the Histogram bars

The image shows a magenta VWAP line on the price graph
Thank you SleepyZ, I don't know how you did it and (so quickly) but that is exactly what I was looking for.
I will spend the next few days implementing it with my strategy on my TOS platform. I will keep you informed on my progressed.
If you are ever in this part of the world let me know and I will buy you a beer!

Jean-Claude
 

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

Thread starter Similar threads Forum Replies Date
pupu Coding Help: Fold vs CompoundValue Questions 1
D CompoundValue Function Questions 5

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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