Sentiment Range MA [ChartPrime] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
oO3WFp5.png

Author Message:
The "Sentiment Range MA" provides traders with a dynamic perspective on market activity, emphasizing both stability in chop zones and quick adaptability outside of them.
Key Features:
  1. Chop Zone Stability: In choppy markets, this indicator remains consistent, filtering out the noise to provide a clear view.
  2. Quick Adaptability: Should the price break out of these zones, the indicator recalibrates promptly.
  3. Dynamic Support and Resistance: Adapts based on the latest price action, serving as an evolving reference point.
  4. Emphasis on Recent Levels: The tool factors in the latest notable market levels to stay relevant and timely.
More Details : https://www.tradingview.com/v/LVsNPKBe/

CODE:

CSS:
# https://www.tradingview.com/v/LVsNPKBe/
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://moz
#// © ChartPrime
#indicator("Sentiment Range MA [ChartPrime]", overlay = true, timeframe = "", timeframe_gaps = false)
# Converted and Mod by Sam4Cok@Samer800    - 11/2023

input showSignals = no;
input colorBars = no;
input showBand = yes;
input timeframe = {Default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.DAY;
input source = FundamentalType.CLOSE;     # "Source"
input Length = 20;                        # "Length"
input DoubleFilter = yes;                 # "Double Filter"
input trueRangeType = {Default "Candle High/Low", "Volatility Adjustment"};
input CandleSmoothing = 4;                # "Trigger Smoothing"
input atrLength = 200;                    # "ATR Length"
input RangeMultiplier = 6.00;             # "Range Multiplier"
input RangeStyle = {default "Body", "Wick"};                             # "Range Style"
input LineColorStyle = {default "MA Direction", "MA Cross", "Solid"};    # "Color Style"

def na = Double.NaN;
def last = isNaN(close);
def useAtr = trueRangeType == trueRangeType."Volatility Adjustment";
def mtf = timeframe == timeframe."Custom";
def dir = LineColorStyle == LineColorStyle."MA Direction";
def cross = LineColorStyle == LineColorStyle."MA Cross";
def len = Length + 1;
def smoothing = CandleSmoothing + 1;
def multi = RangeMultiplier;
#-- Color
DefineGlobalColor("bull", CreateColor(33, 255, 120));   # "Bullish Color"
DefineGlobalColor("bear", CreateColor(255, 33, 33));    # "Bearish Color"
DefineGlobalColor("neut", CreateColor(137, 137, 137));  # "Neutral Color"
DefineGlobalColor("dbull", CreateColor(1, 50, 32));     # "Bullish Color"
DefineGlobalColor("dbear", CreateColor(63, 0, 0));      # "Bearish Color"
DefineGlobalColor("dneut", CreateColor(42, 42, 42));    # "Neutral Color"
#- MTF
def tfS = Fundamental(FundamentalType = source);
def tfO = Fundamental(FundamentalType = FundamentalType.OPEN);
def tfC = Fundamental(FundamentalType = FundamentalType.CLOSE);
def tfH = Fundamental(FundamentalType = FundamentalType.HIGH);
def tfL = Fundamental(FundamentalType = FundamentalType.LOW);
def mtfS = Fundamental(FundamentalType = source, Period = customTimeframe);
def mtfO = Fundamental(FundamentalType = FundamentalType.OPEN, Period = customTimeframe);
def mtfC = Fundamental(FundamentalType = FundamentalType.CLOSE, Period = customTimeframe);
def mtfH = Fundamental(FundamentalType = FundamentalType.HIGH, Period = customTimeframe);
def mtfL = Fundamental(FundamentalType = FundamentalType.LOW, Period = customTimeframe);

def s = if mtf then mtfS else tfC;
def o = if mtf then mtfO else tfO;
def c = if mtf then mtfC else tfC;
def h = if mtf then mtfH else tfH;
def l = if mtf then mtfL else tfL;

#sr_ma(float source, output_smoothing, trigger_smoothing, atr_length = 50, multiplier, string
script sr_ma {
    input source = close;
    input output_smoothing = 3;
    input smoothing = 1;
    input atr_length = 50;
    input multiplier = 1;
    input range_switch = "Body";
    input duel_filter =  no;
    input useAtr = no;
    input o = open;
    input c = close;
    input h = high;
    input l = low;
    def ntr = TrueRange(h, c, l);
    def nATR = WildersAverage(ntr, atr_length);
    def minVol = Min(nATR * 0.5, c * (0.3 / 100));
    def volAdj = minVol[20];
    def max = Max(o, c);
    def min = Min(o, c);
    def candle_top = if range_switch != "Body" then h else max;
    def candle_bot = if range_switch != "Body" then l else min;
    def smooth_top = Average(candle_top, smoothing);
    def smooth_bot = Average(candle_bot, smoothing);
    def tr = candle_top - candle_bot;
    def avgTr = Average(tr, atr_length);
    def atr = if useAtr then volAdj else avgTr;
    def sr_ma;
    def cur_range;
    def top_range;
    def bot_range;
    def flag = smooth_top > top_range[1] or smooth_bot < bot_range[1] or !cur_range[1];
    if flag {
        sr_ma = source;
        cur_range = atr * multiplier;
        top_range = sr_ma + cur_range;
        bot_range = sr_ma - cur_range;
    } else {
        sr_ma = if sr_ma[1] then sr_ma[1] else source;
        cur_range = if cur_range[1] then cur_range[1] else atr * multiplier;
        top_range = if top_range[1] then top_range[1] else sr_ma + cur_range;
        bot_range = if bot_range[1] then bot_range[1] else sr_ma - cur_range;
    }
    def AvgMa  = Average(sr_ma, output_smoothing);
    def AvgTop = Average(top_range, output_smoothing);
    def AvgBot = Average(bot_range, output_smoothing);
    def sr_WMA   = WMA(sr_ma, output_smoothing);
    def sr_dWMA  = WMA(AvgMa, output_smoothing);
    def top_WMA  = WMA(top_range, output_smoothing);
    def top_dWMA = WMA(AvgTop, output_smoothing);
    def bot_WMA  = WMA(bot_range, output_smoothing);
    def bot_dWMA = WMA(AvgBot, output_smoothing);
    def smooth_cur_range = if duel_filter then sr_dWMA else sr_WMA;
    def smooth_top_range = if duel_filter then top_dWMA else top_WMA;
    def smooth_bot_range = if duel_filter then bot_dWMA else bot_WMA;
    plot srm = if smooth_cur_range then smooth_cur_range else Double.NaN;
    plot top = if smooth_top_range then smooth_top_range else Double.NaN;
    plot bot = if smooth_bot_range then smooth_bot_range else Double.NaN;
}

def sr_ma = sr_ma(s, len, smoothing, atrLength, multi, RangeStyle, DoubleFilter, useAtr, o, c, h, l).srm;
def top_range = sr_ma(s, len, smoothing, atrLength, multi, RangeStyle, DoubleFilter, useAtr, o, c, h, l).top;
def bot_range = sr_ma(s, len, smoothing, atrLength, multi, RangeStyle, DoubleFilter, useAtr, o, c, h, l).bot;

def ma_delta;
def ma_cross;

def plot_neutral = h > sr_ma and l < sr_ma;
def plot_bullish = l > sr_ma;
def plot_bearish = h < sr_ma;

if plot_bullish {
    ma_cross = 1;
} else
if plot_bearish {
    ma_cross = -1;
} else
if plot_neutral {
    ma_cross = 0;
} else {
    ma_cross = if isNaN(ma_cross[1]) then 0 else ma_cross[1];
}
def nzSr_ma = if isNaN(sr_ma[1]) then 0 else sr_ma[1];
def ma_delta_neutral = (sr_ma - nzSr_ma) == 0;
def ma_delta_bullish = (sr_ma - nzSr_ma) > 0;
def ma_delta_bearish = (sr_ma - nzSr_ma) < 0;

if ma_delta_bullish {
    ma_delta = 1;
} else
if ma_delta_bearish {
    ma_delta = -1;
} else
if ma_delta_neutral {
    ma_delta = 0;
} else {
    ma_delta = if isNaN(ma_delta[1]) then 0 else ma_delta[1];
}

def ma_col = if cross then ma_cross else
             if Dir then ma_delta else 0;
       
plot ma = if last then na else sr_ma;        # "SR MA"
def top = if last or !showBand then na else top_range;    # "Top Range"
def bot = if last or !showBand then na else bot_range;    # "Bottom Range"
ma.SetLineWeight(2);
ma.AssignValueColor(if ma_col > 0 then GlobalColor("bull") else
                    if ma_col < 0 then GlobalColor("bear") else GlobalColor("neut"));
def halfTop = top - (top - ma) / 2;
def halfBot = bot + (ma - bot) / 2;
AddCloud(if ma_col > 0 then halfTop else na, halfBot, GlobalColor("dbull"));
AddCloud(if ma_col < 0 then halfTop else na, halfBot, GlobalColor("dbear"));
AddCloud(if !ma_col then halfTop else na, halfBot, GlobalColor("dneut"));

AddCloud(if ma_col > 0 then Top else na, Bot, GlobalColor("dbull"));
AddCloud(if ma_col < 0 then Top else na, Bot, GlobalColor("dbear"));
AddCloud(if !ma_col  then Top else na, Bot, GlobalColor("dneut"));

#-- BarColor
def barColor = if ma_cross>0 and ma_delta > 0 then 2 else
               if ma_cross>0 or  ma_delta > 0 then 1 else
               if ma_cross<0 and ma_delta < 0 then -2 else
               if ma_cross<0 or  ma_delta < 0 then -1 else 0;
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if barColor == 2 then Color.GREEN else
                 if barColor == 1 then Color.DARK_GREEN else
                 if barColor ==-2 then Color.RED else
                 if barColor ==-1 then Color.DARK_RED else Color.GRAY);
#-- Signals
def Bull = if barColor== 2 then Bull[1] + 1 else 0;
def Bear = if barColor==-2 then Bear[1] + 1 else 0;

AddChartBubble(showSignals and Bull==2, low, "B", Color.GREEN, no);
AddChartBubble(showSignals and Bear==2, high, "S", Color.RED);
#-- END of CODE
 
Last edited by a moderator:
Hello All,

Could you someone help us to get this indicator conversion to TOS platform, I found it very useful Indicator for swing trade and day trade.
(Please add arrows or crossover to get scanner)
Sentiment Range MA [ChartPrime]
Thank you in advance and appreciated.

mod note:
the indicator has already been converted, see above.
Here is how to search the forums to find if your future requests already exists:
https://usethinkscript.com/threads/search-the-forum.12626/
@Rrm411
 
Last edited by a moderator:

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
307 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