code help: range box

ulle73

New member
Hi

could someone help me code a similiar indicator to this:

rangebox.jpg


Picture is showing:
GREEN BOX -range from 00:01- 9:00 AM (london opening)
GRAY BOX - range from 00:01-15:30 (US market opening)

Would also love to have the ADR indicator at top, showing todays range, price moved 96% out of its average 5 day range

Im from sweden, thats why i want those time-intervals, MT4 is 1h behind, thats why picture is laging by 1h.

Using this to trade DJ with a 50p TP and 100p SL, when price breaks range box by 2p, go long above and short below, using fixed SL and TP, been trading it manually for quite some time, also im having an algo through PRT showing same results. But now moved to TOS
 
Solution
why does the indicator paint the rangebox all wrong? The green box should look like the red box i drawed.



range.jpg

See if this helps.

As I am unsure of what times you want based upon TOS using eastern timezone times vs those you posted above. I used a time setup that rolled over midnight to verify that the script works.

Also, since TOS does not have a function to plot the highs/lows, the volumeprofile study was modified to use its' profile highs/lows for them.

Screenshot-2022-11-02-193748.png
Ruby:
input afterbegin = 2300;
input afterend   = 0930;
def sec1    = SecondsFromTime(afterbegin);
def sec2    = SecondsFromTime(afterend);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 > 0 and...
Hi

could someone help me code a similiar indicator to this:


Picture is showing:
GREEN BOX -range from 00:01- 9:00 AM (london opening)
GRAY BOX - range from 00:01-15:30 (US market opening)

Would also love to have the ADR indicator at top, showing todays range, price moved 96% out of its average 5 day range

Im from sweden, thats why i want those time-intervals, MT4 is 1h behind, thats why picture is laging by 1h.

Using this to trade DJ with a 50p TP and 100p SL, when price breaks range box by 2p, go long above and short below, using fixed SL and TP, been trading it manually for quite some time, also im having an algo through PRT showing same results. But now moved to TOS

this allows the user to pick a time range and display the high and low.
https://usethinkscript.com/threads/average-daily-range-indicator-for-thinkorswim.244/#post-66296
 
Last edited:
why does the indicator paint the rangebox all wrong? The green box should look like the red box i drawed.



range.jpg

See if this helps.

As I am unsure of what times you want based upon TOS using eastern timezone times vs those you posted above. I used a time setup that rolled over midnight to verify that the script works.

Also, since TOS does not have a function to plot the highs/lows, the volumeprofile study was modified to use its' profile highs/lows for them.

Screenshot-2022-11-02-193748.png
Ruby:
input afterbegin = 2300;
input afterend   = 0930;
def sec1    = SecondsFromTime(afterbegin);
def sec2    = SecondsFromTime(afterend);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or (sec2 < sec2[1] and sec2 > 0);
def aftermarket = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else aftermarket[1], 0);

def bars   = 2000;

input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default BAR};
input onExpansion = no;
input profiles = 1000;

def period;

switch (timePerProfile) {
case BAR:
    period = BarNumber() - 1;
}


def count = CompoundValue(1, if aftermarket and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
def con = CompoundValue(1, onExpansion, no);

def hProfile = if aftermarket and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if aftermarket and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if aftermarket and plotsDomain then hProfile else Double.NaN;
def ProfileLow  = if aftermarket and plotsDomain then lProfile else Double.NaN;

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hrange.SetDefaultColor(Color.GREEN);
lrange.SetDefaultColor(Color.GREEN);
hrange.SetLineWeight(2);
lrange.SetLineWeight(2);


input bubblemover = 0;
def b  = bubblemover;
def b1 = b + 1;


input showbubbles = yes;
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b])  , hrange, AsText(hrange), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b]) , lrange, AsText(lrange), Color.LIGHT_green, up = no);

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);

input showclouds = yes;
AddCloud(if showclouds then hrange else Double.NaN, lrange, Color.GREEN, Color.GREEN);
 
Last edited:
Solution

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
462 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