How to Get the Range of the Tallest Red Candle of the Day So Far?

Trismagistus

New member
My purpose is simple: to find the range length of the tallest red candle to appear, so far, in today's trading.

I'm having a heckuva time finding how to get that, since most thinkscripts have more complex goals and concepts, and discussions tend to focus around averages or other calculations like ATR.

I don't need to plot the number, nor scan for it. I don't need the average over time. It might be most useful, however, if I can specify some number of 1m candles into the day as a starting point, since the first 10 minutes or so tend to have the largest volitility in range values.

Does anyone know how I might be able to get that number?

Many thanks in advance.

-- Tris
 
Ok, the code below is a complete mess. If only I could assign a global variable that I could change, it would be so simple. This code is the result of me banging my head on this problem for at least 8 hours. I don't have it to the point where I expect it to make sense. I'm just trying to get the values I want, add them together, and produce a number. Any help anyone can offer would be greatly appreciated.

I'm clearly missing some fundamental thinkscript concepts. I can put the following in the thinkscript editor and it allows it, but...

Code:
# DOESN'T WORK. DON'T TRY THIS AT HOME
#
def thisCandleRange = high - low;
def prevCandleRange = high[1] - low[1];
def nextCandleRange = high[-1] - low[-1];
def isRed = if open[1] > low[1] then yes else no;
def FormerBiggestRedRange =0;

AddLabel (yes, "isRed: " +  isRed + " ", Color.LIME );
AddLabel (yes, "thisCandleRange: " + thisCandleRange + " ", Color.LIME );
AddLabel (yes, "prevCandleRange: " + prevCandleRange + " ", Color.LIME );
AddLabel (yes, "nextCandleRange: " + nextCandleRange + " ", Color.LIME );
AddLabel (yes, "thisCandleRange[4]: " + thisCandleRange[4] + " ", Color.LIME );

# === Without the below, the above works, so far, just for producing some range
values. With the below, however, even the above AddLabels disappear.
# ==================================================
def TheBiggestRedRange;
if (isRed == yes && TheBiggestRedRange == double.nan ) {
    # This candle is the first red candle in our period, so grab its range.
    TheBiggestRedRange = thisCandleRange;
} else {
    if ( isRed == yes && (thisCandleRange > TheBiggestRedRange[1] ) ) {
        # This red candle's range is larger than the previous red's range
        # so save its range
         TheBiggestRedRange = thisCandleRange;
    } else {
        # Preserve the previous TheBiggestRedRange
        TheBiggestRedRange = TheBiggestRedRange[1];
    }
}

# if ( (thisCandleRange > FormerBiggestRedRange[1]) ) then FormerBiggestRedRange[1] = thisCandleRange;

AddLabel (yes, "TheBiggestRedRange: " + TheBiggestRedRange + " ", Color.YELLOW );

Perhaps pseudocode will explain what I'm trying to do better than my thinkscript attempts so far:

Context: 1m chart;
Period: Intraday since the opening bell;
Find the range of each red candle's high to low;
Compare it against the ranges of all the other red candles;
Return the range of the longest red candle;

That's it. I'll put the return value in a label.
 
Last edited by a moderator:
See if this is close to what you're after:

Code:
declare upper;

def istoday = if GetLastDay() == GetDay() then 1 else 0;

def redRange = if istoday == 1   
    and close < open
    and high - low > redRange[1]
    then high - low
    else redRange[1];

AddLabel(visible = Yes, text=Concat("Largest Red Candle Range: ", redRange));

-mashume
 
Mashume, THANK YOU!!! That's so elegant.

Before I saw your answer, I banged my head on finding a solution for another four hours. I never could get it right with explicit code like yours. So I started looking for functions to see if ThinkScript had something built in, and found this "HighestAll()" function which outputs the same answer:

def BiggestRed = HighestAll( if open > close then high - low else double.nan);
AddLabel (yes, "BiggestRed: " + BiggestRed + " ", Color.LIME );

Very handy, but I always prefer explicit code like yours in case I want to do something special. So THANK YOU again!

The one remaining challenge is that I want to exclude the first ten 1m bars after the open, since huge drops frequently happen there -- the scale of which often isn't repeated throughout the rest of the trading day.

I had hopes for using the "Highest(high[1], length)" with "BarNumber()-10" for the length parameter but the Highest() function throws an exception of "only constants expected here" for the length. Haven't found a way around that, yet.
 
Perhaps like this:
Code:
declare upper;

def istoday = if GetLastDay() == GetDay() then 1 else 0;
input ActivateTime  = 0940.0;

def Active = if  SecondsFromTime(ActivateTime) >= 0
                 then 1
                 else 0;

def redRange = if istoday == 1
    and Active == 1
    and close < open
    and high - low > redRange[1]
    then high - low
    else redRange[1];

AddLabel(visible = Yes, text=Concat("Largest Red Candle Range: ", redRange));

AddVerticalLine(Active[1] == 0 and Active == 1, "Start Measuring Candles");

-mashume
 
@Pensar I know how to do that under the appearance. What I am asking is there does anyone have a script to change the fill up or fill down for candles. I have a script looking for a specific candle. When this candle appears on my chart it automatically changes the border color and candle fill color. I am looking to keep the border color as it is (green or red) but I am looking for a script or command to add to the script I have that will leave the fill up or fill down color.white.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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