#score_avg_0
#help with finding average based on legnth
#jonshank62 4/2
#am trying to find a average of the previous actual values defined by legnth then devide that by legnth (note ) each finalscore is different
#https://usethinkscript.com/threads/5‑factor-market-bias-for-thinkorswim.22267/
#Indicators Custom
#5‑Factor Market Bias For ThinkOrSwim
#jonshank62 Mar 25, 2026
#mod note:
#This indicator reads the market’s bias and tells you whether the current bar is neutral, bullish, or bearish.
#It converts five different pressures into a single weighted score, colors the line and the price bars based on that score, and prints a label that tells you the current state.
#I have come up with this bar-by-bar grading system with a lag time of 1 bar.
#I have added different colors for different grades.
#The lower study is choppy and hard to follow but does accurately display the choppiness of the market .
#I have also added a label and color bar options.
#I'm not usually a fan of color bars, but wow, for me, it is an eye-opener. It makes it easy to distinguish institutional bars from the common noise.
#Also, yellow = natural is very interesting.
#So far, every time a yellow is posted, the price, if not interfered with, will revert to the 20 PMA.
#This is the code I am using with good success on all time frames
# WEIGHTED ENSEMBLE SYSTEM
# 5‑Factor Market Bias Model
# bar by bar analysis
declare lower;
# These defaults reflect real-world behavioral importance:
# 200 Sma >9 sma > rsi 4 > Obv > Break out >
input w1 = 4.0; # Weight for 200 Sma
input w2 = 4.0; # Weight for 9 SMA
input w3 = 4.0; # Weight for rsi (4)
input w4 = 4.0; # Weight for OBV direction
input w5 = 8.0; # Weight for Breakout Range
def score1 =
if close > Average(close, 200) then 0.5 else -0.5;
def score2 =
if Average(close, 8) > Average(close, 9)[1] then 0.5 else -0.5;
def score3 =
if RSI(4) > RSI(4)[1] then 0.5 else -0.5;
def score4 =
if OnBalanceVolume() > OnBalanceVolume()[1] then 0.5 else -0.5;
def score5 =
if close > Highest(high, 5)[1] then 0.5 else
if close < Lowest(low, 5)[1] then -0.5 else 0;
def finalScore =
score1 * w1
+ score2 * w2
+ score3 * w3
+ score4 * w4
+ score5 * w5;
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetLineWeight (4);
plot pLine = 4.0;
pLine.SetDefaultColor(Color.GREEN);
pLine.SetLineWeight (3);
plot nLine = -4.0;
nLine.SetDefaultColor(Color.RED);
nLine.SetLineWeight (3);
plot Score = finalScore;
Score.SetLineWeight(3);
Score.SetPaintingStrategy(PaintingStrategy.LINE);
Score.AssignValueColor(
if finalScore > -2 and finalScore < 2 then Color.YELLOW else
if finalScore > 2.1 and finalScore <= 4 then Color.LIME else
if finalScore > 4.1 and finalScore <= 8 then Color .GREEN else
if finalScore > 8.1 then Color.DARK_GREEN else
if finalScore < -2.1 and finalScore >= -4 then Color.PINK else
if finalScore < -4.1 and finalScore >= -8 then Color.RED else
if finalScore < -8.1 then Color.DARK_RED else Color.GRAY);
input colorbars = yes;
AssignPriceColor(if !colorbars then Color.CURRENT else
if finalScore > -2 and finalScore < 2 then Color.YELLOW else
if finalScore > 2.1 and finalScore <= 4 then Color.LIME else
if finalScore > 4.1 and finalScore <= 8 then Color .GREEN else
if finalScore > 8.1 then Color.DARK_GREEN else
if finalScore < -2.1 and finalScore >= -4 then Color.PINK else
if finalScore < -4.1 and finalScore >= -8 then Color.RED else
if finalScore < -8.1 then Color.DARK_RED else
Color.GRAY );
# note if yellow printed then nutural and price will attempt to revert to movingAverage
input showLabel = yes ;
AddLabel(showLabel ,
if finalScore > -2 and finalScore < 2 then "neutral" else
if finalScore > 2.1 and finalScore <= 4 then "neutral +" else
if finalScore > 4.1 and finalScore <= 8 then "bull" else
if finalScore > 8.1 then "strong bull" else
if finalScore < -2.1 and finalScore >= -4 then "neutral -" else
if finalScore < -4.1 and finalScore >= -8 then "bear" else
if finalScore < -8.1 then "strong bear" else "unknown",
if finalScore > -2 and finalScore < 2 then Color.YELLOW else
if finalScore > 2.1 and finalScore <= 4 then Color.LIME else
if finalScore > 4.1 and finalScore <= 8 then Color.GREEN else
if finalScore > 8.1 then Color.DARK_GREEN else
if finalScore < -2.1 and finalScore >= -4 then Color.PINK else
if finalScore < -4.1 and finalScore >= -8 then Color.RED else
if finalScore < -8.1 then Color.DARK_RED else Color.GRAY , Location.TOP_RIGHT
, FontSize.LARGE);
#-------------------------------
def na = double.nan;
def bn = barnumber();
def data = finalscore;
input avg1_len = 20;
input avg1_type = AverageType.Simple;
def avg1 = MovingAverage(avg1_type, data, avg1_len);
input factor = 40;
def avg1_div = factor * avg1 / avg1_len;
plot z1 = avg1_div;
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(1);
z1.hidebubble();
#https://toslc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#input avg1_type = AverageType.Simple;
#input avg1_type = AverageType.exponential;
#input avg1_type = AverageType.hull;
#input avg1_type = AverageType.weighted;
#input avg1_type = AverageType.wilders;
#