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?
# 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);
#
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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.
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);
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
);
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
);
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
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?
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);
I had that one made a couple months agoHey @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?
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);
If you are putting it in a study, then the following should give you an audio alert.
Just put an equal sign after the < or > signs in the codeHey @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?
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Fractal Pivots Indicator - Need help adding signal | Questions | 1 | ||
C | Simple MACD + RSI Indicator | Questions | 1 | |
Adding a moving average to the ADX indicator | Questions | 1 | ||
S | Close Above High / Low Indicator | Questions | 1 | |
A | Accumulation/Distribution increasing indicator | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.