Bullish and Bearish statistics based on time

Alfreddy

New member
If there is someone on this forum that can create a label, showing bullish/bearish time ratio and/or time of possession, based on the amount of time a bullish or bearish move is made during RTH. Giving a visual look at average time for buying and selling and also giving sight as to how long of time to hold a move, bullish or bearish, based the label's average time stamp.
This idea is based on watching sports such as stats and time possession that I think may be a possibility to transfer that system and stats to the stock market. If there is such a label already coded, please guide me. TIA
 
Interesting concept. Comparing market action to sports possession stats isn't something I've seen done much. You'll likely need to find someone to code this for your platform since it’s pretty custom.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

If there is someone on this forum that can create a label, showing bullish/bearish time ratio and/or time of possession, based on the amount of time a bullish or bearish move is made during RTH. Giving a visual look at average time for buying and selling and also giving sight as to how long of time to hold a move, bullish or bearish, based the label's average time stamp.
This idea is based on watching sports such as stats and time possession that I think may be a possibility to transfer that system and stats to the stock market. If there is such a label already coded, please guide me. TIA

here's a study i got from Chatgp, based on my post above, it works on S&P and SPY and i think that there is some of you that can improve this study.

https://tos.mx/!iyGnUQTv
View attachment 27236


.
Code:
DECLARE UPPER;

input length = 50;
input minATRFactor = 0.2;
input extensionFactor = 1.0;
input alertZ = 1.5;
input minCycles = 5;

# --- Core indicators ---
def vwap = VWAP();
def atr = Average(TrueRange(high, close, low), 14);
def rsi = RSI(14);

# --- Time per bar (minutes) ---
def barMinutes = GetAggregationPeriod() / 60000;

# --- Price movement ---
def move = close - close[1];
def tr = TrueRange(high, close, low);

# --- Filters ---
def strongMove = AbsValue(move) > (atr * minATRFactor);
def bodySize = AbsValue(close - open);
def strongCandle = bodySize > (tr * 0.6);

# --- VWAP bias ---
def up = close > vwap and move > 0 and strongMove and strongCandle;
def down = close < vwap and move < 0 and strongMove and strongCandle;

# --- Extension from VWAP ---
def vwapDist = AbsValue(close - vwap);
def extended = vwapDist > (atr * extensionFactor);

# --- Phase tracking ---
def buyPhase = if up then buyPhase[1] + 1 else 0;
def sellPhase = if down then sellPhase[1] + 1 else 0;

# --- Convert to time ---
def buyTime = buyPhase * barMinutes;
def sellTime = sellPhase * barMinutes;

# --- Reversals ---
def buyToSell = down and up[1];
def sellToBuy = up and down[1];

# =========================
# 🔥 STABLE STATS ENGINE
# =========================

# --- Capture cycles (NO NaN) ---
def buyCycle = if buyToSell then buyTime[1] else 0;
def sellCycle = if sellToBuy then sellTime[1] else 0;

# --- Counts ---
def buyCount = CompoundValue(1,
if buyToSell then buyCount[1] + 1 else buyCount[1],
0);

def sellCount = CompoundValue(1,
if sellToBuy then sellCount[1] + 1 else sellCount[1],
0);

# --- Sums ---
 
Last edited by a moderator:
If there is someone on this forum that can create a label, showing bullish/bearish time ratio and/or time of possession, based on the amount of time a bullish or bearish move is made during RTH. Giving a visual look at average time for buying and selling and also giving sight as to how long of time to hold a move, bullish or bearish, based the label's average time stamp.
This idea is based on watching sports such as stats and time possession that I think may be a possibility to transfer that system and stats to the stock market. If there is such a label already coded, please guide me. TIA

this lower study counts the up and down movements, bar to bar, on each day.
it calcs a ratio of the 2 numbers. it subtracts 1, to center the ratio line around 0.
it draws colored dots on the 0 line, green or red, for each bar to bar movement.
labels show the numbers.
the lines skip the first bar of the day, so the lines are not connected day to day.


Code:
# label_bull_bear_time_ratio
# https://usethinkscript.com/threads/bullish-and-bearish-statistics-based-on-time.22186/
#Bullish and Bearish statistics based on time

declare lower;

def na = Double.NaN;
def bn = BarNumber();

#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------

def grn = close > close[1];
def red = close < close[1];


def start = 0930;
def end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def startbar = (secondsfromTime(start) == 0);
addverticalline(startbar, "-", color.cyan);

def daynum = getday();
def newday = daynum != daynum[1];


def grncnt;
def redcnt;
if startbar then {
 grncnt = 0;
 redcnt = 0;
} else if daytime and newday then {
# day first bar
 grncnt = 0;
 redcnt = 0;
} else if daytime and grn then {
 grncnt = grncnt[1] + 1;
 redcnt = redcnt[1];
} else if daytime and red then {
 grncnt = grncnt[1];
 redcnt = redcnt[1] + 1;
} else {
 grncnt = grncnt[1];
 redcnt = redcnt[1];
}


input ratio_factor = 1;
#  ratio of green red. adjusted to be cenetered on 0
def xcnt = if (grncnt == 0 or redcnt == 0) then 0
else ((grncnt / redcnt) - 1) * ratio_factor;


input show_grn_red_lines = yes;
input show_ratio_line = yes;

def l1 = if !show_grn_red_lines or newday then na else grncnt;
def l2 = if !show_grn_red_lines or newday then na else redcnt;
def l3 = if !show_ratio_line or newday then na else xcnt;

plot z1 = l1; 
plot z2 = l2;
plot z3 = l3;
z1.SetDefaultColor(Color.green);
z1.setlineweight(1);
z1.hidebubble();
z2.SetDefaultColor(Color.red);
z2.setlineweight(1);
z2.hidebubble();
z3.SetDefaultColor(Color.cyan);
z3.setlineweight(1);
z3.hidebubble();


addlabel(1, "daily count", color.white);
addlabel(1, " ", color.black);
addlabel(1, grncnt, z1.takevaluecolor());
addlabel(1, (grncnt * chartmin) + "min", z1.takevaluecolor());
addlabel(1, " ", color.black);
addlabel(1, redcnt, z2.takevaluecolor());
addlabel(1, (redcnt * chartmin) + "min", z2.takevaluecolor());
addlabel(1, " ", color.black);
addlabel(1, "ratio " + xcnt, z3.takevaluecolor());
addlabel(1, " ", color.black);


plot z0 = 0;
z0.SetDefaultColor(Color.GRAY);

input show_bar_dots = yes;
plot zdots = if !show_bar_dots then na else 0;
zdots.AssignValueColor( if grn then color.green else if red then color.red else color.black);
zdots.SetPaintingStrategy(PaintingStrategy.POINTS);
zdots.setlineweight(2);
zdots.hidebubble();


#---------------------------

addchartbubble(0, 4,
"G " + grncnt + "\n" +
"R " + redcnt + "\n" +
xcnt
, color.cyan, 1);

#
 

Attachments

  • 01-a bac 15min.png
    01-a bac 15min.png
    154.2 KB · Views: 93
this lower study counts the up and down movements, bar to bar, on each day.
it calcs a ratio of the 2 numbers. it subtracts 1, to center the ratio line around 0.
it draws colored dots on the 0 line, green or red, for each bar to bar movement.
labels show the numbers.
the lines skip the first bar of the day, so the lines are not connected day to day.


Code:
# label_bull_bear_time_ratio
# https://usethinkscript.com/threads/bullish-and-bearish-statistics-based-on-time.22186/
#Bullish and Bearish statistics based on time

declare lower;

def na = Double.NaN;
def bn = BarNumber();

#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------

def grn = close > close[1];
def red = close < close[1];


def start = 0930;
def end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def startbar = (secondsfromTime(start) == 0);
addverticalline(startbar, "-", color.cyan);

def daynum = getday();
def newday = daynum != daynum[1];


def grncnt;
def redcnt;
if startbar then {
 grncnt = 0;
 redcnt = 0;
} else if daytime and newday then {
# day first bar
 grncnt = 0;
 redcnt = 0;
} else if daytime and grn then {
 grncnt = grncnt[1] + 1;
 redcnt = redcnt[1];
} else if daytime and red then {
 grncnt = grncnt[1];
 redcnt = redcnt[1] + 1;
} else {
 grncnt = grncnt[1];
 redcnt = redcnt[1];
}


input ratio_factor = 1;
#  ratio of green red. adjusted to be cenetered on 0
def xcnt = if (grncnt == 0 or redcnt == 0) then 0
else ((grncnt / redcnt) - 1) * ratio_factor;


input show_grn_red_lines = yes;
input show_ratio_line = yes;

def l1 = if !show_grn_red_lines or newday then na else grncnt;
def l2 = if !show_grn_red_lines or newday then na else redcnt;
def l3 = if !show_ratio_line or newday then na else xcnt;

plot z1 = l1;
plot z2 = l2;
plot z3 = l3;
z1.SetDefaultColor(Color.green);
z1.setlineweight(1);
z1.hidebubble();
z2.SetDefaultColor(Color.red);
z2.setlineweight(1);
z2.hidebubble();
z3.SetDefaultColor(Color.cyan);
z3.setlineweight(1);
z3.hidebubble();


addlabel(1, "daily count", color.white);
addlabel(1, " ", color.black);
addlabel(1, grncnt, z1.takevaluecolor());
addlabel(1, (grncnt * chartmin) + "min", z1.takevaluecolor());
addlabel(1, " ", color.black);
addlabel(1, redcnt, z2.takevaluecolor());
addlabel(1, (redcnt * chartmin) + "min", z2.takevaluecolor());
addlabel(1, " ", color.black);
addlabel(1, "ratio " + xcnt, z3.takevaluecolor());
addlabel(1, " ", color.black);


plot z0 = 0;
z0.SetDefaultColor(Color.GRAY);

input show_bar_dots = yes;
plot zdots = if !show_bar_dots then na else 0;
zdots.AssignValueColor( if grn then color.green else if red then color.red else color.black);
zdots.SetPaintingStrategy(PaintingStrategy.POINTS);
zdots.setlineweight(2);
zdots.hidebubble();


#---------------------------

addchartbubble(0, 4,
"G " + grncnt + "\n" +
"R " + redcnt + "\n" +
xcnt
, color.cyan, 1);

#
Thank you for the reply and will use your lower study as it is and see how it interacts with the CHATGP
 
I updated the CHATGP study as a price only study. gives me more precise information and works well with SPX, SPY, /ES, /NQ and QQQ. Make the changes to fit your trading style.
 
Interesting concept. Comparing market action to sports possession stats isn't something I've seen done much. You'll likely need to find someone to code this for your platform since it’s pretty custom.
Check out the new update on my CHATGP study. Works well on stocks and futures. Make adjustments to fit your trading style.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1309 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