Range Sentiment Profile [LuxAlgo] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
Q1s1dnQ.png


Author Message: (Not Typical conversion, some scripts can't be converted to TOS)
The Range Sentiment Profile indicator is inspired from the volume profile and aims to indicate the degree of bullish/bearish variations within equidistant price areas inside the most recent price range.

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) #https://creativecommons.org/licenses/by-nc-sa/4.0/
#// © LuxAlgo
#indicator("Range Sentiment Profile [LuxAlgo]", overlay = true, max_boxes_count = 500)
# Converted by Sam4Cok@Samer800    - 07/2023 - Not exact results!

#//Settings
input length = 80;
input rows   = 20;
input useChartTimeframe = {Default "yes", "No"};
input manualTimeframe   = AggregationPeriod.FIFTEEN_MIN;
input showRange = yes;    # 'Show Range Levels'
input bullMax   = no;    # 'Maximum'
input bearMax   = no;    # 'Minimum'
input showFill = yes;     # 'Show Fill'

#//Function
def na = Double.NaN;
def c;
def h;
def l;
def o;

Switch (useChartTimeframe) {
Case "Yes" :
    c = close;
    h = high;
    l = low;
    o = open;
Case "No" :
    c = close(Period=manualTimeframe);
    h = high(Period=manualTimeframe);
    l = low(Period=manualTimeframe);
    o = open(Period=manualTimeframe);
}
#def get_close = close(Period=tf);
#def get_open = open(Period=tf);
def last = isNaN(close);
def int = inertiaAll(c, length);
def islast = !last;#!isNaN(int) and isNaN(int[-1]);#!isNaN(close);
#def isfirst = !isNaN(int) and isNaN(int[1]);
def rng = !isNaN(int);
def n = AbsValue(CompoundValue(1, BarNumber(), 0));

#--- Colors
DefineGlobalColor("up"   , CreateColor(33,87,243));
DefineGlobalColor("dn"  , CreateColor(255,93,0));
DefineGlobalColor("dup" , CreateColor(6,34,113));
DefineGlobalColor("ddn" , CreateColor(98,36,0));

def upper = highest(h, length);
def lower = lowest(l, length);
def sumad = sum(AbsValue(c - o), length);

def avg;def avg75; def avg25;def top; def btm;
def ltop;
def l75;
def l50;
def l25;
def lbtm;

#/Set profile
if islast {
    avg   = (upper + lower) / 2;
    avg75 = (upper + avg) / 2;
    avg25 = (lower + avg) / 2;
    top = upper;
    btm = lower;
    } else {
    avg = avg[1];
    avg75 = avg75[1];
    avg25 = avg25[1];
    top = top[1];
    btm = btm[1];
}
def toplvl = if !rng then na else highestAll(inertiaAll(top, 2));
def botlvl = if !rng then na else highestAll(inertiaAll(btm, 2));
def lvl75  = if !rng then na else highestAll(inertiaAll(avg75, 2));
def lvl50  = if !rng then na else highestAll(inertiaAll(avg, 2));
def lvl25  = if !rng then na else highestAll(inertiaAll(avg25, 2));
#//Display range levels
if showRange {
    ltop = toplvl;
    lbtm = botlvl;
    l75 = lvl75;
    l50 = lvl50;
    l25 = lvl25;
    } else {
    ltop = na;
    lbtm = na;
    l75 = na;
    l50 = na;
    l25 = na;
}
plot l75_ = l75;
plot l50_ = l50;
plot l25_ = l25;
plot ltop_ = ltop;
plot lbtm_ = lbtm;

l75_.SetStyle(Curve.SHORT_DASH);
l25_.SetStyle(Curve.SHORT_DASH);
l75_.SetDefaultColor(Color.GRAY);
l50_.SetDefaultColor(Color.GRAY);
l25_.SetDefaultColor(Color.GRAY);
ltop_.SetDefaultColor(Color.GRAY);
lbtm_.SetDefaultColor(Color.GRAY);

#//Loop trough most recent bars
def introw = inertiaAll(c, rows-1);
def rngrow = isNaN(introw);
def dn = if rngrow then upper else
         dn[1] - (upper - lower) / rows;

def sum = fold i = 0 to rows -1 with q=upper do
          fold j = 0 to length -1 with p do
          p + if h[j] > GetValue(dn,rows - i-1) and l[j] < if(i==0,upper, GetValue(dn,rows-i))
              then c[j] - o[j] else 0;
def sums = sum>0;

def css = if showFill then sums else na;
AddCloud(if css then toplvl else botlvl, if css then botlvl else toplvl, GlobalColor("dup"), GlobalColor("ddn"));

def sums_abs = AbsValue(sum);

def max = highest(sum, rows);
def min = lowest(sum, rows);

def up = fold k = 0 to rows -1  with r=(dn+dn[1])/2 do
         if GetValue(sum,rows-k) == max then (GetValue(dn,rows-k-1) + GetValue(dn,rows-k))/2 else r;
def dn1 = fold k1 = 0 to rows -1 with r1=(dn+dn[1])/2 do
         if GetValue(sum,rows-k1) == min then (GetValue(dn,rows-k1-1) + GetValue(dn,rows-k1))/2 else r1;

def  lvlMax = up;#if sum == max then up else lvlMax[1];
def  lvlMin = dn1;#if sum == min then dn1 else lvlMin[1];

plot BullBin = if !bullMax or !rng then na else highestAll(inertiaAll(lvlMax, 2));
plot BearBin = if !bearMax or !rng then na else highestAll(inertiaAll(lvlMin, 2));

BullBin.SetDefaultColor(GlobalColor("up"));
BearBin.SetDefaultColor(GlobalColor("dn"));

#--- END of CODE
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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