1st bar to through whole number on a 1 minute chart

jtbiz

New member
Plus
Hello everyone! I am looking for thinkscript code to identify the 1st barnumber that went through a whole number on a 1 minute chart today.

def target = whole number; #need help here
def thru = high>target and low<target;
plot arrow = thru; #need way to plot arrow on 1st bar that crosses not everytime a bar goes through a whole number
arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrow.AssignValueColor(Color.cyan);
arrow.SetLineWeight(1);

see example in pic attached
 

Attachments

  • BarThruWholeNumber.JPG
    BarThruWholeNumber.JPG
    42.1 KB · Views: 117
@jtbiz
As far as defining the target bar:
Ruby:
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);
def thrutarget = High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow;

plot arrow = thrutarget;
arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrow.AssignValueColor(Color.cyan);
arrow.SetLineWeight(1);

plot arrow = thru; #need way to plot arrow on 1st bar that crosses not everytime a bar goes through a whole number

I'll assume you mean not every bar through same whole number as previous arrow.
Took the liberty of differentiating between crossing above or below.
LFqjUaQ.png

Ruby:
input Day_Start = 0930;

def GreenBar = close > open;
def RedBar = close < open;
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);

def thrutarget;
def BlackWhole;
if SecondstillTime(Day_Start)[-1] == 0 {
thrutarget = 0;
BlackWhole = 0;
}else if High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow 
            and (RoundedHigh + RoundedLow)/2 <> BlackWhole[1] {
thrutarget = 1;
BlackWhole = (RoundedHigh + RoundedLow)/2;
}else {
thrutarget = 0;
BlackWhole = BlackWhole[1];} 

plot uparrow = if Greenbar then thrutarget else double.nan;
uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uparrow.AssignValueColor(Color.cyan);
uparrow.SetLineWeight(1);

plot dnarrow = if Redbar then thrutarget else double.nan;
dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnarrow.AssignValueColor(Color.cyan);
dnarrow.SetLineWeight(1);
 
Last edited:

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

@jtbiz
As far as defining the target bar:
Ruby:
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);
def thrutarget = High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow;

plot arrow = thrutarget;
arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrow.AssignValueColor(Color.cyan);
arrow.SetLineWeight(1);



I'll assume you mean not every bar through same whole number as previous arrow.
Took the liberty of differentiating between crossing above or below.
LFqjUaQ.png

Ruby:
input Day_Start = 0930;

def GreenBar = close > open;
def RedBar = close < open;
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);

def thrutarget;
def BlackWhole;
if SecondstillTime(Day_Start)[-1] == 0 {
thrutarget = 0;
BlackWhole = 0;
}else if High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow
            and (RoundedHigh + RoundedLow)/2 <> BlackWhole[1] {
thrutarget = 1;
BlackWhole = (RoundedHigh + RoundedLow)/2;
}else {
thrutarget = 0;
BlackWhole = BlackWhole[1];}

plot uparrow = if Greenbar then thrutarget else double.nan;
uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uparrow.AssignValueColor(Color.cyan);
uparrow.SetLineWeight(1);

plot dnarrow = if Redbar then thrutarget else double.nan;
dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnarrow.AssignValueColor(Color.cyan);
dnarrow.SetLineWeight(1);
Beautiful! Thank you :) possible to change to 1st bar only irrespective of crossing above/below. so in that case only the 1st bar going thru' a whole number will have an arrow.
 
Beautiful! Thank you :) possible to change to 1st bar only irrespective of crossing above/below. so in that case only the 1st bar going thru' a whole number will have an arrow.
That is how it is currently written.
The only issue I foresee as of now is if a bar passes through 2 whole numbers. A subsequent bar passing through only 1 of the 2 whole numbers would still signal.
 
Last edited:
@jtbiz
As far as defining the target bar:
Ruby:
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);
def thrutarget = High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow;

plot arrow = thrutarget;
arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrow.AssignValueColor(Color.cyan);
arrow.SetLineWeight(1);



I'll assume you mean not every bar through same whole number as previous arrow.
Took the liberty of differentiating between crossing above or below.
LFqjUaQ.png

Ruby:
input Day_Start = 0930;

def GreenBar = close > open;
def RedBar = close < open;
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);

def thrutarget;
def BlackWhole;
if SecondstillTime(Day_Start)[-1] == 0 {
thrutarget = 0;
BlackWhole = 0;
}else if High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow
            and (RoundedHigh + RoundedLow)/2 <> BlackWhole[1] {
thrutarget = 1;
BlackWhole = (RoundedHigh + RoundedLow)/2;
}else {
thrutarget = 0;
BlackWhole = BlackWhole[1];}

plot uparrow = if Greenbar then thrutarget else double.nan;
uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uparrow.AssignValueColor(Color.cyan);
uparrow.SetLineWeight(1);

plot dnarrow = if Redbar then thrutarget else double.nan;
dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnarrow.AssignValueColor(Color.cyan);
dnarrow.SetLineWeight(1);
applied code to attached example. It appears that it would trigger alert 3 times when price crosses 54. I'm wanting to generate an alert just the 1st time it crosses a whole number. So in the example, once each the 1st time stock touches the whole numbers 57, 56,55,54,53
 

Attachments

  • BarThruWholeNumber2.JPG
    BarThruWholeNumber2.JPG
    50.5 KB · Views: 110
So in the example, once each the 1st time stock touches the whole numbers 57, 56,55,54,53
Not sure if possible since we cant use arrays, but this might work:
Ruby:
input Day_Start = 0930;
input Day_End = 1630;

def Active = SecondsFromTime(Day_Start) >= 0 and SecondsTillTime(Day_End) >= 0;
def GreenBar = close > open;
def RedBar = close < open;
def RoundedHigh = RoundDown(High,0);
def RoundedLow = RoundUp(Low,0);

def thrutarget;
def BlackWholeH;
def BlackWholeL;
if SecondstillTime(Day_Start)[-1] == 0 {
thrutarget = 0;
BlackWholeH = hl2[-1];
BlackWholeL = hl2[-1];
}else if Active and High > RoundedHigh and Low < RoundedLow and RoundedHigh >= RoundedLow 
        and (RoundedHigh > BlackWholeH[1] or RoundedLow < BlackWholeL[1]) {
thrutarget = 1;
BlackWholeH = if RoundedHigh > BlackWholeH[1] then RoundedHigh else BlackWholeH[1];
BlackWholeL = if RoundedLow < BlackWholeL[1] then RoundedLow else BlackWholeL[1];
}else {
thrutarget = 0;
BlackWholeH = BlackWholeH[1];
BlackWholeL = BlackWholeL[1];}

plot uparrow = if Greenbar then thrutarget else double.nan;
uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uparrow.AssignValueColor(Color.cyan);
uparrow.SetLineWeight(1);

plot dnarrow = if Redbar then thrutarget else double.nan;
dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnarrow.AssignValueColor(Color.cyan);
dnarrow.SetLineWeight(1);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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