Candle Body Script help

VIP_TOS

Member
VIP
The code below shows a chart bubble for every candles body height. How can this be modified so a chart bubble ONLY appears if
body height is between 2 - 4 in height?


def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();

addchartbubble(1, candleBodyTop,BodyHeight() ,color.cyAN);
 
Solution
Hey @Svanoy thank you for following up with me & thank you @halcyonguy for chiming in to help out.
I am only a few weeks in on learning thinkscript so excuse me on the confusion I may have caused. I truly appreciate the help & guidance.
as for the script I believe i got it to work with fold. It now seems to sum the correct amount when I change the period input & time frame aggregation input. I attached what i have completed any input on if of if not correct would be appreciated.


Ruby:
#Short Term Candle Body Sentiment

input ShortTermSentiment = aggregationPeriod.fivE_MIN;
input ShortTermSumPeriods = 6;

def ST_O = open(period = ShortTermSentiment);
def ST_C = close(period = ShortTermSentiment);
def ST_bodyHeight =...

SleepyZ

Well-known member
VIP
Lifetime
The code below shows a chart bubble for every candles body height. How can this be modified so a chart bubble ONLY appears if
body height is between 2 - 4 in height?


def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();

addchartbubble(1, candleBodyTop,BodyHeight() ,color.cyAN);

Try this

capture.jpg
Ruby:
def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();

AddChartBubble( Between(BodyHeight(), 2, 4), CandleBodyTop, BodyHeight() , Color.CYAN);
 

SleepyZ

Well-known member
VIP
Lifetime
@SleepyZ Thank you very much. That worked! Now how do you add a custom text in the bubble instead of the number value ?

Here is example code adding text to the bubble. Use the \n to create additional stacked lines of text and/or values to the bubble.

Ruby:
def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();

AddChartBubble( Between(BodyHeight(), 2, 4), CandleBodyTop,
"Custom Text \n 2nd Line, if wanted  \n"
 + BodyHeight()
, Color.CYAN);
 

VIP_TOS

Member
VIP
Hello all, I am fairly new to thinkscript & appreciate all the knowledge & help I received on this forum. I just
signed up as a premium member to support. I cant find any help on the forum about this. I am looking for a script that will sum the previous 50 candle bodies by color. I have 6 candle colors 3 bullish colors & 3 bearish colors & would like the sum of each colors body & total.


An example below is the sum of 6 candles in total
3 bullish & 3 bearish


3 Bullish Color candles

1 Yellow candle = 4 BodyHeight()
1 Green candle = 8 BodyHeight()
1 Dark Green candle = 2 BodyHeight()

Sum of bullish candles = 14


3 Bearish color candles
1 Orange = 3 BodyHeight()
1 Red = 2 BodyHeight()
1 Dark Red = 6 BodyHeight()

Sum of bearish candles = 11
 

Svanoy

Active member
@VIP_TOS
With the information you have provided, it would be similar to this
Ruby:
def Bull = <YellowCandle> or <GreenCandle> or <DarkGreenCandle>;
def Bull_Candle_Count = fold i = 1 to 50 with Bull_Counter = 0 do if GetValue(Bull,i)==1 then Bull_Counter+GetValue(BodyHeight(),i) else Bull_Counter;
and repeat for Bear Candles.
Would need more information to go any further.
 

Svanoy

Active member
@VIP_TOS
The above code does not work on its own, it is only an example using the information provided in your post.

Without criteria for what is defining candle colors, I cannot produce a complete working script.
If you can provide the criteria, I will look at it tomorrow.
 

VIP_TOS

Member
VIP
I am using this script on a 5min chart. Is there a way to code it so I have the 5min chart open & it sums candles on a higher time frame like
15min, 1hr or daily ? I would add a chart label to display these values while watching the 5min chart
 

SleepyZ

Well-known member
VIP
Lifetime
What could you add to this script so that it only populates a chart bubble for the previous 10 candles?

Try this

Ruby:
input count = 10;
def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();
def cond    = Between(BodyHeight(), 2, 4);
def hcount  = CompoundValue(1, if !IsNaN(cond) then hcount[1] + 1 else hcount[1], 0);
AddChartBubble(HighestAll(hcount) - hcount <= count - 1 , CandleBodyTop,
"Custom Text \n 2nd Line, if wanted  \n"
 + BodyHeight()
, Color.CYAN);
 

VIP_TOS

Member
VIP
Thank you again SleepyZ. That worked to show the chart bubbles for only the previous 10 candles but it is showing all 10 chart bubbles regardless of the between number 2, 4 statement. Need it to show only if the last 10 candles are between 2 & 4 body height.
 

VIP_TOS

Member
VIP
@VIP_TOS
With the information you have provided, it would be similar to this
Ruby:
def Bull = <YellowCandle> or <GreenCandle> or <DarkGreenCandle>;
def Bull_Candle_Count = fold i = 1 to 50 with Bull_Counter = 0 do if GetValue(Bull,i)==1 then Bull_Counter+GetValue(BodyHeight(),i) else Bull_Counter;
and repeat for Bear Candles.
Would need more information to go any further.
I am using this script on a 5min chart. Is there a way to code it so I have the 5min chart open & it sums candles on a higher time frame like
15min, 1hr or daily ? I would add a chart label to display these values while watching the 5min chart
 

VIP_TOS

Member
VIP
Ruby:
def DAY_Chart_Candle_Count = aggregationPeriod.DAY;

#Candle Colors
input CandlesToSum = 10;
def Dark_Red_Candle_NAME = DarkRed;
def Red_Candle_NAME = Red;
def Yellow_Candle_NAME = Yellow;
def Orange_Candle_NAME = Orange;
def Green_Candle_NAME = Green;
def Dark_Green_Candle_NAME = DarkGreen;

#Bullish Candle BODY SUM

def Dark_green_Candle_BODY = fold i = 1 to candlesToSum with Dark_green_Candle_NAME_Counter = 0 do if GetValue(Dark_green_Candle_NAME,i)==1 then Dark_green_Candle_NAME_Counter+GetValue(BodyHeight(),i) else Dark_green_Candle_NAME_Counter ;


def green_Candle_BODY = fold h = 1 to candlesToSum with green_Candle_NAME_Counter = 0 do if GetValue(green_Candle_NAME,h)==1 then green_Candle_NAME_Counter+GetValue(BodyHeight(),h) else green_Candle_NAME_Counter;

def yellow_Candle_BODY = fold g = 1 to candlesToSum with yellow_Candle_NAME_Counter = 0 do if GetValue(yellow_Candle_NAME,g)==1 then yellow_Candle_NAME_Counter+GetValue(BodyHeight(),g) else yellow_Candle_NAME_Counter;



I put DAY_Chart_Candle_Count = aggregationPeriod.DAY; on top of code & got no change or sum for day aggregation. How would you define candles using higher timeframes in the code ?
 

SleepyZ

Well-known member
VIP
Lifetime

Oops, fixed below by modifing the cond within hcount as a 1/0, instead of !isnan/nan and included cond as part of the bubble criteria.

Rich (BB code):
input count = 10;
def CandleBodyTop = MidBodyVal() + 0.5 * BodyHeight();
def cond    = Between(BodyHeight(), 2, 4);
def hcount  = CompoundValue(1, if cond then hcount[1] + 1 else hcount[1], 0);
AddChartBubble(cond and HighestAll(hcount) - hcount <= count - 1 , CandleBodyTop,
"Custom Text \n 2nd Line, if wanted  \n"
 + BodyHeight()
, Color.CYAN);
 

Svanoy

Active member
@VIP_TOS

Code:
def DAY_Chart_Candle_Count = aggregationPeriod.DAY;

#Candle Colors
def Dark_Red_Candle_NAME = DarkRed;
def Red_Candle_NAME = Red;
def Yellow_Candle_NAME = Yellow;
def Orange_Candle_NAME = Orange;
def Green_Candle_NAME = Green;
def Dark_Green_Candle_NAME = DarkGreen;

That is not how to use a secondary aggregation period.
The rest, under #Candle Colors isn't even functioning code.
You haven't defined any criteria for determining what color a candle should be.
 

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