input count_window_length = 100;
def condition = if close crosses above MovAvgExponential(length = 9) then 1 else 0;
def counter = sum(condition, count_window_length);
def condition = if close crosses above MovAvgExponential(length = 9) then 1 else 0;
def counter = if condition == 1 then counter[1] + 1 else counter[1];
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Have you found the answer?How would you count the number of times a conditon is met across timeframes? Example: Count the number of times MACD Crosses zero (only the most recent crosses) on the Daily, 3 Day and Weekly aggregations? Is this possible? Thanks.
Not yet. @samer800 can you suggest an approach?Have you found the answer?
Thank you HODL-Lay-HE-hoo! I appreciate your help.Input lookbacklength = 30;
Def condition = x;
def cross_lookback = fold index1 = 1 to lookbacklength with x1 do x1 + condition[index1];
Will store the number of times condition was met within the length.
How would you count the number of times a conditon is met across timeframes? Example: Count the number of times MACD Crosses zero (only the most recent crosses) on the Daily, 3 Day and Weekly aggregations? Is this possible? Thanks.
I'm really only looking to count the most recent occurence of, say the MACD Crossing across aggregations. I want to know how many aggregations had a MACD crossing within an editable window of 2 or 3 (or more) bars. So I have 4 aggregations: 4 Hour, Daily, 3 Day and Weekly. How many MACD crossings occurred across the time frames (but only looking at the most recent crossing on each. I only need to count 1 event per aggregation. Is that doable? Thanks!
Code:script m { input aggregationperiod = AggregationPeriod.TWO_MIN; input lookbacklength = 3; input fastLength = 12; input slowLength = 26; input MACDLength = 9; input averageType = AverageType.EXPONENTIAL; def Value = MovingAverage(averageType, close(period = aggregationperiod), fastLength) - MovingAverage(averageType, close(period = aggregationperiod), slowLength); def Avg = MovingAverage(averageType, Value, MACDLength); def Diff = Value - Avg; def condition = Crosses(Diff, 0, CrossingDirection.ANY); plot cross_lookback = Sum(condition, lookbacklength); } input lookbacklength = 6; AddLabel(1, "4hr: " + m(aggregationperiod = "FOUR_HOURS", lookbacklength = lookbacklength),color.white); AddLabel(1, "1D: " + m(aggregationperiod = "DAY", lookbacklength = lookbacklength),color.white); AddLabel(1, "3D: " + m(aggregationperiod = "THREE_DAYS", lookbacklength = lookbacklength),color.white); AddLabel(1, "W: " + m(aggregationperiod = "WEEK", lookbacklength = lookbacklength),color.white); input showvertical = yes; def lastbar = highestall(if isnan(close[-1]) then barnumber() else 0); addverticalLine(showvertical and barnumber() == lastbar - lookbacklength + 1); #
This is great! Thank you @SleepyZ . My set up has the aggs horizontally, and I need to get a total of the MACD Crossings in the watchlist column. Can you suggest how I can count them using what you've built? Maybe keep a running count, using +1 for an Up crossing and -1 for a down crossing, then placing the total in the watchlist column? Then I can sort by that column to see potential calls/puts in order of probability. I don't rely on any one indicator but this will be useful.
There's a method to my madness. When there are a higher number of up (or down) crossings that happen near-simultaneously, the move lasts longer (I do swing trading). This is due to more support at the beginning of the price move.
I attached my chart so you can see what I mean. Notice the confluence of indicators across the 4 aggs. This is CAT on June 1st. It showed a great setup for a Call that day.
Thanks again for your help.
Thanks! I'll check it out.Try this link that may have a watchlist setup with columns how you might want
https://tos.mx/JjANJiR
View attachment 20034
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.