Creating script for candle height body height

chackiejan

New member
Hello, I'd like to use a script that marks all candles with body height greater than 50% of the candle height (wick to wick) with a star on top. And mark all the candles with less than 50% of body height candle height with the high price on top of that candle. I'd like to use this on any chart on TOS.
 
Solution
Hello, I'd like to use a script that marks all candles with body height greater than 50% of the candle height (wick to wick) with a star on top. And mark all the candles with less than 50% of body height candle height with the high price on top of that candle. I'd like to use this on any chart on TOS.

See if this helps

Capture.jpg
Ruby:
def bodyheight = if BodyHeight() > (high - low) * .5 then 1 else 0;

AddChartBubble(bodyheight, high, "*", Color.YELLOW);
AddChartBubble(!bodyheight, high*1.001, AsText(high), Color.WHITE);
Hello, I'd like to use a script that marks all candles with body height greater than 50% of the candle height (wick to wick) with a star on top. And mark all the candles with less than 50% of body height candle height with the high price on top of that candle. I'd like to use this on any chart on TOS.

See if this helps

Capture.jpg
Ruby:
def bodyheight = if BodyHeight() > (high - low) * .5 then 1 else 0;

AddChartBubble(bodyheight, high, "*", Color.YELLOW);
AddChartBubble(!bodyheight, high*1.001, AsText(high), Color.WHITE);
 
Solution

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

See if this helps
That works perfectly. Should have mentioned Low of that non star candle as well for puts. If you look at when the * candle closes above the high of the non star candle, it is considered as a break out, and the price often tests the high of the previous non star candle. Can I have the breakout star candle turn the color of the star box from yellow to green when its bullish and red when its bearish? The condition is that the * candle closes above the high of the preceeding non star candles when its bullish - and candle closes below the low the preceeding non star candle when its bearish.
 
Last edited:
Take this options chart for example, 380C $SPY after the dump. The * candle I have written breakout on top - and the previous non start candle high we put up an order that the next candle low picked up and went ahead.
usetos.png
 
Take this options chart for example, 380C $SPY after the dump. The * candle I have written breakout on top - and the previous non start candle high we put up an order that the next candle low picked up and went ahead.
usetos.png

Since the *bubble is yellow, I changed the bubble color to green/red from yellow as the candles are already green/red.

Capture.jpg
Ruby:
def bodyheight = if BodyHeight() > (high - low) * .5 then 1 else 0;

def breakup = if bodyheight and !bodyheight[1] and
                 close[1] > open[1] and close > open and
                 low > low[1] and high > high[1]
              then 1 else 0;
def breakdn = if bodyheight and !bodyheight[1] and
              close[1] < open[1] and close < open and
              low < low[1] and high < high[1]
              then 1 else 0;
AddChartBubble(bodyheight, high,
               if breakup
               then "UP\n *"
               else if breakdn
               then "DN\n *"
               else "*",
               if breakup
               then Color.GREEN
               else if breakdn
               then Color.RED else Color.YELLOW);

AddChartBubble(!bodyheight, high * 1.001, AsText(high), Color.WHITE);
AddChartBubble(!bodyheight, low * .999, AsText(low), Color.WHITE, no);
 
item.png

Thank you! I do think some of the values arent quite right, for eg . the up at 10:50am should not come because the previous high wasnt broken by the close. Also the candle at 11:30 should have given an up. $AMZN chart from today
 
item.png

Thank you! I do think some of the values arent quite right, for eg . the up at 10:50am should not come because the previous high wasnt broken by the close. Also the candle at 11:30 should have given an up. $AMZN chart from today
Try changing the code yourself as I used high instead of close in comparison to high[1] and low instead of close in comparison to low[1] and see if that fixes your issue. If not, then let me know if you run into problems. If you can fix it, then please post it for others to view.
 
Thank you, I was able to change to "close", however it is still not correct. Also it doesn't come in 14:40 candle in the chart when the BO was above the high.



Code:
def bodyheight = if BodyHeight() > (high - low) * .5 then 1 else 0;


def breakup = if bodyheight and !bodyheight[1] and

                 close[1] > open[1] and close > open and

                 low > low[1] and high > close[1]

              then 1 else 0;

def breakdn = if bodyheight and !bodyheight[1] and

              close[1] < open[1] and close < open and

              low < low[1] and high < close[1]

              then 1 else 0;

AddChartBubble(bodyheight, high,

               if breakup

               then "UP\n *"

               else if breakdn

               then "DN\n *"

               else "*",

               if breakup

               then Color.GREEN

               else if breakdn

               then Color.RED else Color.YELLOW);


AddChartBubble(!bodyheight, high * 1.001, AsText(high), Color.WHITE);

AddChartBubble(!bodyheight, low * .999, AsText(low), Color.WHITE, no);
item2.png
 
, it doesn't come in 14:40 candle in the chart when the BO was above the high.

if you look at the chart, then look at each part of the formula for breakup, and work out which parts are true and which are false, you will see that,

breakup wasn't triggered at 14:40 because you have a condition that tests if the previous bar was up,
. close[1] > open[1]
and it was wasn't , it was a red bar.

if the direction of the previous bar doesn't matter, then remove that part of the formula.

----------------------------------

to fix the study as you desire, an offset of 1 will need to be added to all variables.
if you want to check when close is greater than some number, but ignore the high of that bar, you will have to wait until that bar is closed, then look back and compare it to the bar before it.
but then the triggers will be 1 bar later, not on the triggered bar.

Code:
def bodyheight = if BodyHeight() > (high[0] - low[0]) * .5 then 1 else 0;

def prev_breakup = if bodyheight[1] and !bodyheight[2] and
 close[2] > open[2] and close[1] > open[1] and
 low[1] > low[2] and high[1] > high[2]
 then 1 else 0;

def prev_breakdn = if bodyheight[1] and !bodyheight[2] and
 close[2] < open[2] and close[1] < open[1] and
 low[1] < low[2] and high[1] < high[2]
 then 1 else 0;

#def breakup = prev_breakup[-1];
#def breakdn = prev_breakdn[-1];

def breakup = prev_breakup[0];
def breakdn = prev_breakdn[0];

input test = yes;
AddChartBubble(test and bodyheight, high+0.5,
    if breakup then "UP\n *"
    else if breakdn then "DN\n *"
    else "*",
    if breakup then Color.GREEN
    else if breakdn then Color.RED
    else Color.YELLOW);
#
 
I'm not sure thats a good idea - I'll skip the breakout, however it would be great to have the * be green if its a bull candle and red if it's a bear candle - and the high and low of the strong 50% candles as well for a more visual understanding.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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