I agree the above code works...The code doesn't work when I use X_date and Y_date ;basically calculating the number of days from high to low.
def num_trading_days = absValue(CountTradingDays(X_Date, Y_Date));
def num_calendar_days = absvalue(DaysFromDate(X_Date) - DaysFromDate(Y_Date) + 1);
Ruby:input anchor_date = 20210801; input to_date = 20210831; input...
there is a study like that somewhere here on the forums. do a search for consecutive in the forumsWhat is the script (or command) for counting consecutive bars?
I have a custom study I’m trying to find a way to make a chart label that shows how many consecutive red/green bars it has on an intraday chart. “Green 3, Red 0”
I did see that one. I am not really in need of a lower study.there is a study like that somewhere here on the forums. do a search for consecutive in the forums
https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/
That's my fault. I believe I had the original code posted on another thread. Here is what I was referencing. Sorry for the confusion.your original questions was
"What is the script (or command) for counting consecutive bars?"
i sent you an example of the code
now you are requesting a different request and requesting:
a chart label. Ultimately looking for a watchlist column with a red/green box with the consecutive bar count for the zscore volume study posted above.
im not familiar with zscore and i dont see any prior mentions on this thread stating the word "zscore" nor "volume" prior to your post#11.
#Computes and plots the Zscore
#Provided courtesy of ThetaTrend.com
#Feel free to share the code with a link back to thetatrend.com
declare lower;
input price = close;
input length = 20;
input ZavgLength = 20;
#Initialize values
def oneSD = StDev(price, length);
def avgClose = SimpleMovingAvg(price, length);
def ofoneSD = oneSD * price[1];
def Zscorevalue = ((price - avgClose) / oneSD);
def avgZv = Average(Zscorevalue, 20);
#Compute and plot Z-Score
plot Zscore = ((price - avgClose) / oneSD);
Zscore.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Zscore.SetLineWeight(2);
Zscore.AssignValueColor(if Zscore > 0 then Color.GREEN else Color.RED);
plot avgZscore = Average(Zscorevalue, ZavgLength);
avgZscore.SetPaintingStrategy(PaintingStrategy.LINE);
#This is an optional plot that will display the momentum of the Z-Score average
#plot momZAvg = (avgZv-avgZv[5]);
#Plot zero line and extreme bands
plot zero = 0;
plot two = 2;
plot negtwo = -2;
plot three = 3;
plot negthree = -3;
zero.SetDefaultColor(Color.BLACK);
def nan = double.nan;
def barUp = Zscore > 0;
def barDown = Zscore < 0;
def barUpCount = CompoundValue(1, if barUp then barUpCount[1] + 1 else 0, 0);
def pBarUpCount = if barUpCount > 0 then barUpCount else nan;
def barDownCount = CompoundValue(1, if barDown then barDownCount[1] - 1 else 0, 0);
def pBarDownCount = if barDownCount < 0 then barDownCount else nan;
AddLabel(yes, "Consecutive Bar Count: " +(" "+(Round(barDownCount + barUpCount, 1))), if barUpCount >= 1 then color.green else if barDownCount <= -1 then color.red else Color.gray);
DID you go the response for this mate ? I am looking for the sameHello. Can anyone in the community help me modify the thinkscript below to return the current number of trading days (vs calendar days) or the number of bars “after” a predefined low, and assign a desired color to the label?
declare upper;
input anchor_date = 20201030;
def num_days = DaysFromDate(anchor_date);
AddLabel(yes, (DaysFromDate(anchor_date) + " TD from Low"));
Given the above, today (11/19/20) is 14 trading days or bars “after” the 10/30/20 low.
Thanks very much!
DID you go the response for this mate ? I am looking for the same
Ruby:input anchor_date = 20201030; def last_trading_day = HighestAll(if !IsNaN(close) and IsNaN(close[-1]) then GetYYYYMMDD() else Double.NaN); def num_days = CountTradingDays(anchor_date, last_trading_day); AddLabel(yes, (num_days + " TD from & including " + asprice(anchor_date)));
Thank you Bud......My actual question in the forum if you figure out let me know.This uses counttradingdays function, which counts trading days from and including the dates in it. You can adjust that computation if you want to exclude either the from or to dates from the computation.
Thank you Bud......My actual question in the forum if you figure out let me know.
Dear friends,
From previous month I want to calculate two things No of trading days from High to low (or low to high whichever comes first) and same no. of calendar days. I am working on a project I want to finish this weekend.
For example : In August Spy have low of 300 on august 1st and high of 400 august 13th . Then the trading days will be 10 days and calendar days = 13 days..
Ruby:input anchor_date = 20210801; input to_date = 20210813; def num_trading_days = CountTradingDays(anchor_date, to_date); def num_calendar_days = DaysFromDate(anchor_date) - DaysFromDate(to_date) + 1; AddLabel(yes, "TDays: " + num_trading_days + " | CDays: " + num_calendar_days + " - from & including ... " + AsPrice(anchor_date) + " to " + AsPrice(to_date), color.white );
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
K | Candlestick trading daily count | Questions | 4 | |
Z | Sum function to count throughout the trading session | Questions | 2 | |
B | Count green candles | Questions | 1 | |
S | RoundDown(HL2,0) as Loop Count Limit in Fold Not Working | Questions | 4 | |
M | Count number of active RSI chart bubbles and create alert | Questions | 6 |
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.