Consecutive Bar Count Indicator for ThinkorSwim

M

mudvnine

New member
Hi all,

First post, but before I get to that, just wanted to shout out a big "Thank you!" to all of you for all of the great information and knowledge that is freely shared here. I inadvertently stumbled onto the place a couple weeks ago in a Google search (for what I don't remember now), and so glad that I did. Have learned so much, and "borrowed" a number of indicators that seem fascinating...even if I don't understand their usage 100% yet. I'm just amazed at the thought processes behind them, and the ability to script them in the manner in which they are. So "Thank you" once again.

My question/request is wrt creating an alert that would notify me when there are "X" amount of red or green candles in a row on a given timeframe, that would set off an audible tone notifying me of the event. For instance - six green candles in a row - "DING!".....and/or - two red candles in a row - "DING!" (or "BING!" if it's possible to have a different tone for each color event).

Thanks in advance.

EDIT: Oops, my bad....forgot to think about searching for a bar count indicator that was already done. I'll read through the posts here (or search other threads) to learn about attaching an audible alert to the indicator. (y)
 
Last edited:
wtf_dude

wtf_dude

Active member
Gil Morales (one of the O'neil traders) had mentioned one of his indicator/scans was finding stocks that were up 12 out of 15 days or 11 out of 13. Scans for the stocks and watches the consolidation, waiting to buy into to the inevitable next break. I even put the quote into the scan code so you won't forget what its for. Seems like a good idea for spec plays.

Morales Interview


Code:
#Q: I have heard of a buy signal being given if a stock is up in 12 of the past 15 days. Where would the actual entry point be?

#G: I look for 11 out of 13 or 12 out of 15 days up in a row after a breakout. Once the stock does this, I’ll wait #for it to move sideways or perhaps pull back for anywhere from 3-10 days, and once it moves back out through the #top of this little formation I will come into the stock heavily as I add to my original position, or even sometimes #just enter the stock for the first time.



def price= close;

def a = if close > close[1] then 1 else double.nan;
def b = if close[1] > close[2] then 1 else double.nan;
def c = if close[2] > close[3] then 1 else double.nan;
def d = if close[3] > close[4] then 1 else double.nan;
def e = if close[4] > close[5] then 1 else double.nan;
def f = if close[5] > close[6] then 1 else double.nan;
def g = if close[6] > close[7] then 1 else double.nan;
def h = if close[7] > close[8] then 1 else double.nan;
def i = if close[8] > close[9] then 1 else double.nan;
def j = if close[9] > close[10] then 1 else double.nan;
def k = if close[10] > close[11] then 1 else double.nan;
def l = if close[11] > close[12] then 1 else double.nan;
def m = if close[12] > close[13] then 1 else double.nan;
def n = if close[13] > close[14] then 1 else double.nan;
def o = if close[14] > close[15] then 1 else double.nan;

def Gilmo = (a+b+c+d+e+f+g+h+i+j+k+l+m+n+o) >= 12 or (a+b+c+d+e+f+g+h+i+j+k+l+m) >= 13;

def tot = if (a+b+c+d+e+f+g+h+i+j+k+l+m+n+o) >= 12 or (a+b+c+d+e+f+g+h+i+j+k+l+m) >= 13 then GILMO else double.nan;
plot ants = tot;
 
H

HighBredCloud

Active member
VIP
@wtf_dude To make this a scan for stocks that are down would you just replace > with <?
 
wtf_dude

wtf_dude

Active member
@wtf_dude To make this a scan for stocks that are down would you just replace > with <?
that should do it. This is kind of a "sketch" scan I threw together in a few minutes just to see if I could. So have at it if you wanna throw some options and upgrades in there.
 
H

HighBredCloud

Active member
VIP
that should do it. This is kind of a "sketch" scan I threw together in a few minutes just to see if I could. So have at it if you wanna throw some options and upgrades in there.
@wtf_dude Not much of a coder...just basic copy and past and rearrange stuff...So I don't even know what to add. I can change the <> though...That much I can do.
 
A

amcno03

New member
Hello @korygill
Is there a way to count the times an indicator have been triggered in the day, using the 10 minutes time frame?
Let me try to explain it, I use this simple moving average:


Code:
input price = close;
input length = 15;
input displace = 0;
input showBreakoutSignals = yes;

plot SMA = Average(price[-displace], length);
plot UpSignal = price crosses above SMA;


UpSignal.SetHiding(!showBreakoutSignals);

SMA.SetDefaultColor(GetColor(5));
UpSignal.SetDefaultColor(Color.WHITE);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Like this example, where the BreakoutSignal had two occurrences. I would like to know if there is a way to only show an alert when this Breakout Signal has occurred at least twice in the day:



Thanks in advance for your help.
Best regards.
ps: English is not my mother tongue; please excuse any errors on my part.
 
Last edited by a moderator:
9

9ramone7

New member
Just add it to the bottom of the code in the original post by korygill. It just needs to be after the def barup/bardown and def barupcount/bardowncount since those are referenced in my post.
Do you mind posting the full code?
 
E

ext99k

Member
@korygill You are fantastic!

I was wondering if we can please get some more help!

Is it possible that you could create a strategy that counts the number of bars that have passed since there was a user defined % move, and the frequency of the event being true?

For example, for a given time period, it would display the number of bars until the user defined 10% daily price change occurred (with a bubble on the chart showing the actual % change with the count of bars it took to get there), and it would display the total frequency of occurrence over the time period.

Might get a little complicated, but if we could set the bubble color to vary based on ranges that would be a lot easier to visualize. For example, if the 10% criteria is met while actually being more than 15%, then we can set it to blue, and so on.

I think this would be very valuable as it would provide a better understanding of the frequency of large swings and how far in-between time they might occur, that might help in predicting when a next big swing might occur.

It would also be awesome if we can add Buy orders when the even is true, and a sell order on user defined X days later, so we could backtest

Thanks so much for all of your help, everyone truly appreciates your help! Cheers!
 
Last edited:
korygill

korygill

Active member
VIP
@ext99k this sounds like a new question or new request for an indicator. Not sure I totally understand the ask, but this might not be easy to build on TOS (at least for me). The issue is keeping track of the anchor(s) from which to determine the % price move. This seems like something easier to build in excel/powershell/python from freely downloadable data from yahoo (or exported from tos). You could also change your price axis to a percentage, but that is based on the start of the chart, not some interval. Also, if a bar is 10% and the stock moves up next day, that bar would also be signaled. How would one need to handle that? I am probably not understanding the question fully. Maybe someone else here has the know-how for solving this.
 
E

ext99k

Member
@ext99k this sounds like a new question or new request for an indicator. Not sure I totally understand the ask, but this might not be easy to build on TOS (at least for me). The issue is keeping track of the anchor(s) from which to determine the % price move. This seems like something easier to build in excel/powershell/python from freely downloadable data from yahoo (or exported from tos). You could also change your price axis to a percentage, but that is based on the start of the chart, not some interval. Also, if a bar is 10% and the stock moves up next day, that bar would also be signaled. How would one need to handle that? I am probably not understanding the question fully. Maybe someone else here has the know-how for solving this.

Thanks for the quick reply @korygill

Basically my goal is to identify every how often there's a big daily price change, that I could specify, let's say that's 10%.

I'd like to know the number of days (from the beginning of the period) it took to reach a 10% daily price change. Let's say that it happened in 15 days... the system would display the 15 days on the bar where the condition is true (the 10% change), and then it would also display the actual price change (this isn't as important as the 15 days it took to get there)...

Once the event is true, it starts counting again until the condition is met again. Let's say this time it took 25 days to experience at least a 10% daily price change... so again it would display the 25 days on the true bar... and the frequency would be 2 since it happened twice in the data period.

Maybe @JabronLames could take a quick look, he has code for something that appears similar https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/page-2 :) :)
 
Last edited:
M

MikeTea

New member
@korygill Thanks for your counting algorithm!

I tried to apply it for doing counts in multiple time frames.

I have the following that allows the user to select a secondary time frame that may be different from the primary time frame that is on the chart.

input timeframe = AggregationPeriod.MONTH;

I have all prices set to that time frame, e.g. close(period = timeframe).

However, I don't get consistent results.

For example, if I set AggregationPeriod.MONTH, the count will be correct when the primary time frame that is on a MONTH, WEEK, 4 DAYS or even 2 DAYS chart. But when the primary time frame is on a DAY or lower time chart, the count for AggregationPeriod.MONTH will no longer be correct.

I tried varying the AggregationPeriod (e.g. 2 HOUR), but at some lower primary time frame (e.g. 5 MIN), the count breaks down.

Do you or anyone here know why that is happening and is there a fix?

Thank-you so much!


Mike
 
Top