indicator for microchannel

offshore

Member
Hey the forum has been great so far, a lot of cool indicators.... I was searching for an intraday 5 minute bar numbering indicator but couldnt seem to find one...does it exist?
 
Hey the forum has been great so far, a lot of cool indicators.... I was searching for an intraday 5 minute bar numbering indicator but couldnt seem to find one...does it exist?

something like this ?
Code:
# daily_count_bars_00

def diffday = if getday() != getday()[1] then 1 else 0;
def barcnt = if diffday then 1 else barcnt[1] + 1;

plot z = barcnt;
z.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
z.SetDefaultColor(Color.white);
#
 
Thats it.... Thanks. Is there any way I can adjust the code so only every 3rd bar is numbered? so 3,6,9,12 etc. I wanna do this on my 5 minute chart just so i know when a 15 minute bar will close as well. Thanks for the help
 
I tried changing the different values in the code but it probably requires more lines of code? I apologize I have no background in programming.

This numbers the bars during regular trading hours. There is an option to show every x (3) bar as you requested.

Screenshot-2022-10-16-200552.png
Ruby:
def bn    = barnumber();
def rth   = secondsfromTime(0930)>=0 and secondsfromTime(1600)<0;
def rthbn = if secondsfromTime(0930) == 0
            then 1
            else if rth
            then rthbn[1] + 1
            else double.nan;

input show_rth_barnumbers = no;
plot rthbarnumbers = rthbn;
rthbarnumbers.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
rthbarnumbers.sethiding(!show_rth_barnumbers);

input show_every_x_barnumber = yes;
input x_barnumber = 3;

plot xbars = if rthbn%x_barnumber == 0 then rthbn else double.nan;
xbars.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
xbars.sethiding(!show_every_x_barnumber);

#Example - Find the high of bn = 27
def hbar = if rthbn == 27 then high else 0;
addlabel(1, highestall(hbar) , color.gray);
 
Add def or plot as the first word and place a semicolon at the end... That's already compatible for the most part. The result is a Yes/No though. The real question is how do you want to display it, or what do you want to do with the answer?
 
Ok thanks...ya the code worked but cant get it to display on the chart. The code should paint bull bars with bigger tails on the downside than the size of the body and paint bear bars with bigger tails on the upside than the body of the bar. Not sure what i can add to the code to get this result
 
Try these, the top one follows what you said. If that's not what you actually meant, try the bottom one.

Ruby:
def Bull =
    Close > Open and
    Open - Low > Close - Open; 
def Bear =
    Close < Open and
    High - Open > Open - Close 
;
assignPriceColor(
    if Bull then Color.Dark_Green
    else if Bear then Color.Plum
    else Color.Current
);

Ruby:
def Bull =
    Close > Open and
    Open - Low > High - Open;
def Bear =
    Close < Open and
    High - Open > Open - Low
;
assignPriceColor(
    if Bull then Color.Dark_Green
    else if Bear then Color.Plum
    else Color.Current
);
 
Im a complete beginner at coding and Im looking for some really basic tutorial to start out. Im just trying to code for super basic bar characteristics like % close from high or low of bar, bars that are a % greater than atr on 5 minute time frame, consecutive bars that dont trade below prior bar etc. Been digging around for a little bit here but any help would be appreciated.

Thanks
 
Hey im trying to setup an indicator that alerts me after there has been a 5 consecutive bar channel where each bars low did not trade below the prior bars low and vice versa for a bear microchannel with 5 consecutive bars with highs that did not trade above the prior bars high. The bodies of the bars are irrelevant whether they are bull, bear or doji... any help would be much appreciated
 
Hey im trying to setup an indicator that alerts me after there has been a 5 consecutive bar channel where each bars low did not trade below the prior bars low and vice versa for a bear microchannel with 5 consecutive bars with highs that did not trade above the prior bars high. The bodies of the bars are irrelevant whether they are bull, bear or doji... any help would be much appreciated

Not sure how you want to be alerted otherwise, but you can create a scan that should find these.

Ruby:
def hilo = Sum(high < high[1], 5) == 5 or sum(low>low[1],5)==5;
plot xhilo=if hilo then 1 else 0;
 
Awesome @SleepyZ, this is perfect. thanks alot.... And i can just create a perpetual audio alert for it as well? I dont have to add an audio alert into the code?

If you are putting it in a study, then the following should give you an audio alert.

Code:
def hilo   = Sum(high < high[1], 5) == 5 or Sum(low > low[1], 5) == 5;
plot xhilo = if hilo >= 1 then 1 else 0;
xhilo.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Alert(xhilo, "5", Alert.BAR, Sound.Chimes);
 
Hey @SleepyZ sorry bug you again I forgot to mention for the indicator... if the high of a bar is equal to the high of the prior bar that is valid in the 5 bar bear channel count. same for the bull channel, if a bar has an identical low of the prior bar that is valid... how would i adjust the code for that?
 
Hey @SleepyZ sorry bug you again I forgot to mention for the indicator... if the high of a bar is equal to the high of the prior bar that is valid in the 5 bar bear channel count. same for the bull channel, if a bar has an identical low of the prior bar that is valid... how would i adjust the code for that?
I had that one made a couple months ago
https://usethinkscript.com/threads/consecutive.12146/#post-104528
Code:
input Number_Of_Consecutive_Lows = 5;
input Number_Of_Consecutive_Highs = 5;
input Reset_Time = 0930;

def Start ;
if GetAggregationPeriod() < AggregationPeriod.DAY {
    Start = SecondsTillTime(Reset_Time) == 0;
} else {
    Start = Double.NaN;}

def Bar = if !IsNaN(close) and BarNumber()>0 then BarNumber() else Bar[1];
########################################################################
#Do Not Remove Line of Code in this box.                               #
def FinalBar = if IsNaN(close[-1000]) then Bar[-1000] else FinalBar[1];#
########################################################################

def HigherLows;
if !IsNaN(Start) {
HigherLows = if IsNaN(close) or SecondsTillTime(Reset_Time) == 0 then 0 else if low >= low[1] then HigherLows[1]+1 else 0;
}else {
HigherLows = if IsNaN(close) then 0 else if low >= low[1] then HigherLows[1]+1 else 0;}
def TargetHigherLows = if !IsNaN(Start) then if SecondsTillTime(Reset_Time)[-1] == 0 then 0 else fold z = 0 to Bar while GetValue(low,-(z+1)) >= GetValue(low,-z) do GetValue(HigherLows,-z-1)+1 else fold w = 0 to Bar while GetValue(low,-(w+1)) >= GetValue(low,-w) do GetValue(HigherLows,-w-1)+1;
def ConsecutiveHigherLowsEndBN = fold a = 0 to Bar while GetValue(low,-(a+1)) >= GetValue(low,-a) do GetValue(Bar,-a-1);
def ConsecutiveHigherLowsStartBN = if HigherLows == 0 then Bar else 0;
def ConsecutiveHigherLowsEndLow = fold c = 0 to Bar while GetValue(low,-(c+1)) >= GetValue(low,-c) do GetValue(low,-c-1);
def ConsecutiveHigherLowsStartLow = if HigherLows == 0 then low else 0;
def ConsecutiveHigherLowsSlope = if HigherLows == 0 then (ConsecutiveHigherLowsEndLow - ConsecutiveHigherLowsStartLow)/(ConsecutiveHigherLowsEndBN - ConsecutiveHigherLowsStartBN) else ConsecutiveHigherLowsSlope[1];
def ConsecutiveHigherLowsLine = if HigherLows == 0 then low else if low < low[1] then Double.NaN else ConsecutiveHigherLowsLine[1] + ConsecutiveHigherLowsSlope;

def LowerHighs;
if !IsNaN(Start) {
LowerHighs = if IsNaN(close) or SecondsTillTime(Reset_Time) == 0 then 0 else if high <= high[1] then LowerHighs[1]+1 else 0;
}else {
LowerHighs = if IsNaN(close) then 0 else if high <= high[1] then LowerHighs[1]+1 else 0;}

def TargetLowerHighs = if !IsNaN(Start) then if SecondsTillTime(Reset_Time)[-1] == 0 then 0 else fold y = 0 to Bar while GetValue(high,-(y+1)) <= GetValue(high,-y) do GetValue(LowerHighs,-y-1)+1 else fold x = 0 to Bar while GetValue(high,-(x+1)) <= GetValue(high,-x) do GetValue(LowerHighs,-x-1)+1;
def ConsecutiveLowerHighsEndBN = fold b = 0 to Bar while GetValue(high,-(b+1)) <= GetValue(high,-b) do GetValue(Bar,-b-1);
def ConsecutiveLowerHighsStartBN = if LowerHighs == 0 then Bar else 0;
def ConsecutiveLowerHighsEndHigh = fold d = 0 to Bar while GetValue(high,-(d+1)) <= GetValue(high,-d) do GetValue(high,-d-1);
def ConsecutiveLowerHighsStartHigh = if LowerHighs == 0 then high else 0;
def ConsecutiveLowerHighsSlope = if LowerHighs == 0 then (ConsecutiveLowerHighsEndHigh - ConsecutiveLowerHighsStartHigh)/(ConsecutiveLowerHighsEndBN - ConsecutiveLowerHighsStartBN) else ConsecutiveLowerHighsSlope[1];
def ConsecutiveLowerHighsLine = if LowerHighs == 0 then high else if high > high[1] then Double.NaN else ConsecutiveLowerHighsLine[1] + ConsecutiveLowerHighsSlope;

plot ConsecutiveHigherLowsPlot = if (TargetHigherLows >= Number_Of_Consecutive_Lows) or (HigherLows >= Number_Of_Consecutive_Lows) or (TargetHigherLows[1] >= Number_Of_Consecutive_Lows and low >= low[1]) then ConsecutiveHigherLowsLine else Double.NaN;
ConsecutiveHigherLowsPlot.SetStyle(Curve.MEDIUM_DASH);

plot ConsecutiveLowerHighsPlot = if (TargetLowerHighs >= Number_Of_Consecutive_Highs) or (LowerHighs >= Number_Of_Consecutive_Highs) or (TargetLowerHighs[1] >= Number_Of_Consecutive_Highs and high <= high[1]) then ConsecutiveLowerHighsLine else Double.NaN;
ConsecutiveLowerHighsPlot.SetStyle(Curve.MEDIUM_DASH);
 
Last edited:
If you are putting it in a study, then the following should give you an audio alert.
Hey @SleepyZ sorry bug you again I forgot to mention for the indicator... if the high of a bar is equal to the high of the prior bar that is valid in the 5 bar bear channel count. same for the bull channel, if a bar has an identical low of the prior bar that is valid... how would i adjust the code for that?
Just put an equal sign after the < or > signs in the code
 

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