need signal appear between the 0 -5th minute of the hour

rvaidyamath

New member
How do we do place a signal for clock hours of 5th minute, 10th minute etc . .when the time frame is set for 5 minutes? ( we do need signal appear between the 0 -5th minute of the hour and same applies to other time of the hour)
 
Last edited by a moderator:
Solution
How do we do place a signal for clock hours of 5th minute, 10th minute etc . .when the time frame is set for 5 minutes? ( we do need signal appear between the 0 -5th minute of the hour and same applies to other time of the hour)

It appears that you are looking for a bar timer. TOS does not currently provide one.

A workaround is to use a 1minute chart and use the following code. It is based upon the 1minute bars that plot. If a bar does not plot for each minute, then the time will be off. It will only track the whole minutes, no seconds.

Place the code in a lower study in a separate chart set to 1m.

Uncheck in chart settings the show price in subgraph.

Display this chart below the main chart you are using.

At the input...
How do we do place a signal for clock hours of 5th minute, 10th minute etc . .when the time frame is set for 5 minutes? ( we do need signal appear between the 0 -5th minute of the hour and same applies to other time of the hour)

It appears that you are looking for a bar timer. TOS does not currently provide one.

A workaround is to use a 1minute chart and use the following code. It is based upon the 1minute bars that plot. If a bar does not plot for each minute, then the time will be off. It will only track the whole minutes, no seconds.

Place the code in a lower study in a separate chart set to 1m.

Uncheck in chart settings the show price in subgraph.

Display this chart below the main chart you are using.

At the input aggregation in the code, enter the number of minutes on the main chart.

Select at the input whether you want to display labels and/or bubble with the minutes remaining.

The code does not work first bar for aggregations = 4, 20 and 60

The first image below has the main chart set to 5m. The new chart below with the timer code is set below the main chart as discribed above and resized. It shows that 4m of the next 5m candle have expired and the red, last 1m is now occurring.
Screenshot 2023-10-27 114011.png
Screenshot 2023-10-27 121134.png
Code:
#Bar Minute Timer
#Set chart timeframe to 1 minute... input aggregation you want to time... time will countdown in whole minutes (sorry no seconds are possible at this time)... the final minute will appear in red
#hidePricePlot();
input aggregation = 5;#hint aggregation: Does not work first bar for aggregation = 4, 20 and 60
input showverticalline = no;
def begin     = if aggregation == 60 then 1000 else if aggregation == 4 then 0932 else if aggregation == 20 then 0940 else 0930;
input end     = 1600;
def bar       = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else bar[1] + 1;
AddVerticalLine(if showverticalline and GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0
                then bar % ((Ceil(aggregation)) / (GetAggregationPeriod() / 60000)) == 0
                else Double.NaN,
                color = Color.BLUE, stroke = Curve.FIRM);


def start = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0
            then aggregation - bar % ((Ceil(aggregation) / (GetAggregationPeriod() / 60000))) 
            else start[1];

input showlabel = yes;
AddLabel(showlabel, "Chart Aggregation : " + aggregation, Color.CYAN);
AddLabel(showlabel, "Current Minute: " +  (bar % ((Ceil(aggregation) / (GetAggregationPeriod() / 60000)))) + "  ", Color.WHITE);
AddLabel(showlabel, "  Minutes Remaining : " + start, if start > 1 then Color.YELLOW  else color.red);
input bubblemover = -1;
def x  = bubblemover;
def x1 = x + 1;
plot line0 = 0;
plot line1 = 1;
line1.SetDefaultColor(Color.BLACK);
line0.SetDefaultColor(Color.BLACK);
AddChartBubble(!IsNaN(close[x1]) and IsNaN(close[x]), line0,  start[x1] , if start[x1] > 1 then Color.yellow else Color.RED );
 
Solution
how do I get the current minute of the hour ; that could help as well. ; i tried with epoch time and so many code; somehow I am not getting the desired results.... appreciate the help - Raj

a while ago, i made a progress bar, with labels.
https://usethinkscript.com/threads/text-progress-bar-0-to-100-for-thinkorswim.10813/
i updated it to have 2 colors, and applied it to sleepyz code.


Code:
#bar_timer_labels2

# add progress bar

#https://usethinkscript.com/threads/need-signal-appear-between-the-0-5th-minute-of-the-hour.16906/#post-133370
#SleepyZ

declare lower;

input aggregation = 5;#hint aggregation: Does not work first bar for aggregation = 4, 20 and 60
input showverticalline = no;

def begin     = if aggregation == 60 then 1000 else if aggregation == 4 then 0932 else if aggregation == 20 then 0940 else 0930;
input end     = 1600;
def bar       = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else bar[1] + 1;
AddVerticalLine(if showverticalline and GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0
                then bar % ((Ceil(aggregation)) / (GetAggregationPeriod() / 60000)) == 0
                else Double.NaN,
                color = Color.BLUE, stroke = Curve.FIRM);


def start = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0
            then aggregation - bar % ((Ceil(aggregation) / (GetAggregationPeriod() / 60000)))
            else start[1];

def elapsed_min = (bar % ((Ceil(aggregation) / (GetAggregationPeriod() / 60000))));

input showlabel = yes;
AddLabel(showlabel, "Chart Aggregation : " + aggregation, Color.CYAN);
#AddLabel(showlabel, "Current Minute: " +  (bar % ((Ceil(aggregation) / (GetAggregationPeriod() / 60000)))) + "  ", Color.WHITE);
AddLabel(showlabel, "Current Minute: " + elapsed_min + "  ", Color.WHITE);

AddLabel(showlabel, "  Minutes Remaining : " + start, if start > 1 then Color.YELLOW  else color.red);
input bubblemover = -1;
def x  = bubblemover;
def x1 = x + 1;
plot line0 = 0;
plot line1 = 1;
line1.SetDefaultColor(Color.BLACK);
line0.SetDefaultColor(Color.BLACK);
AddChartBubble(!IsNaN(close[x1]) and IsNaN(close[x]), line0,  start[x1] , if start[x1] > 1 then Color.yellow else Color.RED );

#------------------------------

# horz_progress_bar_02

# progress bar (labels)
# place this code at the end of a study and calculate a percent number for the data to display

#------------------------
# 23-10  chg to- 2 colors
# halcyonguy
# 22-04-04
# build a horizontal progress bar, 1 to 100
#------------------------
# enter a % number to display in a progress bar
#input percent = 38;
def percent = round(100*(elapsed_min/aggregation),0);


#------------------------
def p = percent;
def q = 100 - p;

def div1 = 1;
def div5 = 5;
def div25 = 25;
#  ] is narrower than the vertical line
input c1 = "]";
input c5 = "]]]]]";
input c25 = "]]]]]]]]]]]]]]]]]]]]]]]]]";
#input c1 = " ";
#input c5 = "     ";
#input c25 = "                         ";
#input c1 = "|";
#input c5 = "|||||";
#input c25 = "|||||||||||||||||||||||||";

#----------------------------
# colors

DefineGlobalColor("elapsed_c", color.green);
DefineGlobalColor("remaining_c", color.magenta);
#GlobalColor("elapsed_c")
#GlobalColor("remaining_c")

#-----------------------
# elapsed data

# divide by biggest
def eq25 = floor(p/div25);
def er25 = p % div25;
# divide by smaller
def eq5 = floor(er25/div5);
def er5 = er25 % div5;
# divide by smallest
def eq1 = floor(er5/div1);
def er1 = er5 % div1;

addlabel(1, "  ", color.black);
addlabel(1, " ", color.cyan);

addlabel(1,
(if eq25 == 1 then c25 else if eq25 == 2 then c25 + c25 else if eq25 == 3 then c25 + c25 + c25 else if eq25 == 4  then c25 + c25 + c25 + c25 else "") +
(if eq5 == 1 then c5 else if eq5 == 2 then c5 + c5 else if eq5 == 3 then c5 + c5 + c5 else if eq5 == 4  then c5 + c5 + c5 + c5 else "") +
(if eq1 == 1 then c1 else if eq1 == 2 then c1 + c1 else if eq1 == 3 then c1 + c1 + c1 else if eq1 == 4  then c1 + c1 + c1 + c1 else "")
, GlobalColor("elapsed_c"));
#, color.yellow);

#-----------------------
# remaining data

# divide by biggest
def rq25 = floor(q/div25);
def rr25 = q % div25;
# divide by smaller
def rq5 = floor(rr25/div5);
def rr5 = rr25 % div5;
# divide by smallest
def rq1 = floor(rr5/div1);
def rr1 = rr5 % div1;

addlabel(1,
(if rq25 == 1 then c25 else if rq25 == 2 then c25 + c25 else if rq25 == 3 then c25 + c25 + c25 else if rq25 == 4  then c25 + c25 + c25 + c25 else "") +
(if rq5 == 1 then c5 else if rq5 == 2 then c5 + c5 else if rq5 == 3 then c5 + c5 + c5 else if rq5 == 4  then c5 + c5 + c5 + c5 else "") +
(if rq1 == 1 then c1 else if rq1 == 2 then c1 + c1 else if rq1 == 3 then c1 + c1 + c1 else if rq1 == 4  then c1 + c1 + c1 + c1 else "")
, GlobalColor("remaining_c"));
addlabel(1, " ", color.cyan);
addlabel(1, "  ", color.black);

#-----------------------
addlabel(1, floor(p) + "%", color.yellow);
addlabel(1, elapsed_min + "/" + aggregation, color.yellow);


#-----------------------
# test data

input test1_elapsed = no;
addlabel(test1_elapsed , "    " , color.black);
addlabel(test1_elapsed , p , color.yellow);
addlabel(test1_elapsed , "  " , color.black);
addlabel(test1_elapsed , eq25 + " * " + div25 + " = " + (eq25 * div25), color.yellow);
addlabel(test1_elapsed , eq5 + " * " + div5 + " = " + (eq5 * div5), color.yellow);
addlabel(test1_elapsed , eq1 + " * " + div1 + " = " + (eq1 * div1), color.yellow);
addlabel(test1_elapsed , "  " , color.black);

input test2_remaining = no;
addlabel(test2_remaining , "    " , color.black);
addlabel(test2_remaining , q , color.yellow);
addlabel(test2_remaining , "  " , color.black);
addlabel(test2_remaining , rq25 + " * " + div25 + " = " + (rq25 * div25), color.yellow);
addlabel(test2_remaining , rq5 + " * " + div5 + " = " + (rq5 * div5), color.yellow);
addlabel(test2_remaining , rq1 + " * " + div1 + " = " + (rq1 * div1), color.yellow);
addlabel(test2_remaining , "  " , color.black);

#

% number, progress bar , green/purple
zIcXpxJ.jpg
 
Last edited by a moderator:
how do I get the current minute of the hour ; that could help as well. ; i tried with epoch time and so many code; somehow I am not getting the desired results.... appreciate the help - Raj
 
how do I get the current minute of the hour and later we can divide the same ; by aggregation period? ; ex., if my order to kick in with a custom script is every 5 minutes, it will divide the current minute / aggregation period ; if the remainder = 0 ; it shows the complete minutes are done ; that an work with 3 minutes, 5 , 15 minute etc.
 
how do I get the current minute of the hour ; that could help as well. ; i tried with epoch time and so many code; somehow I am not getting the desired results.... appreciate the help - Raj

As stated in the link above, TOS does not have a bar timer. https://usethinkscript.com/threads/...he-0-5th-minute-of-the-hour.16906/post-133370

To get hours and minutes, we can only use the bars on the charts to assist. So if you are on a 1min chart, we can tell the current minute, if all of the bars for RThrs are plotted. However, if we are on a 5min chart, we are only able to describe minutes in 5min increments.

Here is some example code that puts bubbles on a chart when a condition is met. In the image below the upper chart is set to 5min and the bubbles display the time with 5min times. The same code is on a 1min chart in the lower panel and the bubble times are in 1min timeframes.

Screenshot 2023-11-09 081510.png
Code:
#Example Time_Gettime
#Sleepz 20210315
#Usethinkscript request

#Time Stamp based upon Gettime and RegularTradingStart. Choose timezone
input timezone = {default "ET", "CT", "MT", "PT"};

def starthour  = (if timezone == timezone."ET"
                        then 9
                        else if timezone == timezone."CT"
                        then 8
                        else if timezone == timezone."MT"
                        then 7
                        else 6) ;
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;

#Example : Bubble showing current time of last bar displayed

input showBubble_lastbar = yes;

AddChartBubble(showBubble_lastbar and IsNaN(close[-1]), low, hour + ":" + (if minutes < 10 then "0" else "") + minutes, Color.WHITE, no);


#Bubbles showing time stamp based upon a 'cond'

input showBubbles_Limited_by_Count = yes;
input updown_bubblemover   = 3; # number of ticks * ticksize()
input sideways_bubblemover = 3; # shifts bubble right (pos) / left (neg)
def b = -sideways_bubblemover;
def b1 = b + 1;

def cond = if ExpAverage(close, 3) crosses below ExpAverage(close, 13) then 1 else Double.NaN;

#Bubbles to be displayed are limited by the number input at 'bubble_limit', excluding the last bubble, which follows in code below. The last bubble was separated to show how to connect the offset bubble_limit to the bar it is referencing

input bubble_limit = 3;
def dataCount  = if !IsNaN(cond) == 1    then  dataCount[1] + 1  else dataCount[1];
def dataCountb = if !IsNaN(cond[b]) == 1 then  dataCountb[1] + 1 else dataCountb[1];

AddChartBubble(showBubbles_Limited_by_Count and HighestAll(dataCount) - dataCount != 0 and       HighestAll(dataCount) - dataCount - 1 <= bubble_limit - 2 and !IsNaN(hour) and !IsNaN(cond[1]) == 0 and !IsNaN(cond) == 1,
    high + TickSize() * updown_bubblemover,
    hour + ":" +
    if minutes < 10
    then "0" + minutes 
    else "" + minutes , Color.WHITE, yes);


#Example of Drawing a Line between the last offset bubble and the bar it is referencing

input show_Last_Bubble_Limited_by_Count = yes;

AddChartBubble(show_Last_Bubble_Limited_by_Count and HighestAll(dataCountb) - dataCountb <= 0 and !IsNaN(hour[b]) == 1 and  !IsNaN(cond[b1]) == 0 and !IsNaN(cond[b]) == 1,
    high[b1] + TickSize() * updown_bubblemover,
    hour[b]  + ":" +
    if minutes[b] < 10
    then "0" + minutes[b] 
    else "" + minutes[b] , Color.WHITE, yes);

plot hh  = if HighestAll(dataCount) - dataCount <= 1 - 1 and !IsNaN(cond) == 1
           then high
           else Double.NaN;
plot hh1 = if HighestAll(dataCountb) - dataCountb <= 1 - 1 and !IsNaN(cond[b]) == 1
           then high[b1] + TickSize() * updown_bubblemover
           else Double.NaN;
plot hhline = if !IsNaN(cond[b]) == 1 then hh1 else if !IsNaN(cond) == 1 then hh else Double.NaN;
hhline.SetDefaultColor( Color.WHITE);
hhline.EnableApproximation();
hhline.SetLineWeight(3);
 
ThanQ ; but I am surprised TOS does not give an option to get pure, date parameters as any other platform or coding language! -

ex. YYYY, MM. DD , HH , MM and SS ETC

Raj
 

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