Volume Based S/R For ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
uJjKb7S.png

Author Message:

The indicator compares the size of volume bars so that if there is a noticeable increase in volume (noticeable here meaning above the indicator threshold) it marks the bar high and low prior to the bigger volume candle.

CODE:

CSS:
# https://www.tradingview.com/v/XchidFiQ/
#//@shtcoinr
#study(title="Volume Based S/R", shorttitle="VSR", precision=0, overlay=true)
# Converted and mod by Sam4Cok@Samer800    - 07/2023
input length = 20;#, minval=1)
input Threshold = 5.0;
input DisplayType = {"Support Lines Only", "Resistance Lines Only",Default "Show Both S/R", "Fair S/R"};
input useVwma = {"Yes",default "No"};
input useChartTimeframe = {default "Yes", "No"};
input ManualTimeframe = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
def last = isNaN(close);
def tf = ManualTimeframe;

DefineGlobalColor("SDColor"    , CreateColor(23, 105, 170));

def v; def h; def l; def c;def o;
Switch(useChartTimeframe) {
Case "Yes" :
    v = volume;
    h = high;
    l = low;
    c = close;
    o = open;
Case "No" :
    v = volume(Period=tf);
    h = high(Period=tf);
    l = low(Period=tf);
    c = close(Period=tf);
    o = open(Period=tf);
}
def VWMA = Average(c * v, length) / Average(v, length);
def vol;
Switch (useVwma) {
Case "Yes" :
    vol     = VWMA;
Case "No" :
    vol     = v;
}
def change = vol / vol[1] - 1;
def stdev = StDev(change, length);
def difference = change / stdev[1];
def signal = AbsValue(difference);
def cond = (signal > Threshold);
def upCandle = c > o;

def fairHi = if cond then h[1] else fairHi[1];
def fairLo = if cond then l[1] else fairLo[1];
def BullHi;
def BullLo;
def BearHi;
def BearLo;
if cond {
    BullHi = if upCandle then h[1] else BullHi[1];
    BullLo = if upCandle then l[1] else BullLo[1];
    } else {
    BullHi = BullHi[1];
    BullLo = BullLo[1];
}
if cond {
    BearHi = if !upCandle then h[1] else BearHi[1];
    BearLo = if !upCandle then l[1] else BearLo[1];
    } else {
    BearHi = BearHi[1];
    BearLo = BearLo[1];
}

def upHi; def upLo; def DnHi; def DnLo;
Switch (DisplayType) {
Case "Support Lines Only" :
    upHi = BullHi;
    upLo = BullLo;
    DnHi = na;
    DnLo = na;
Case "Resistance Lines Only" :
    upHi = na;
    upLo = na;
    DnHi = BearHi;
    DnLo = BearLo;
Case "Show Both S/R" :
    upHi = BullHi;
    upLo = BullLo;
    DnHi = BearHi;
    DnLo = BearLo;
Case "Fair S/R" :
    upHi = fairHi;
    upLo = fairLo;
    DnHi = na;
    DnLo = na;
}
#//plot(UpperTreshold, color=black)
plot s1 = if !upHi or last then na else upHi;
plot s2 = if !upLo or last then na else upLo;
def sMid = (s1 + s2) / 2;
plot s3 = sMid;
s1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s3.SetStyle(Curve.SHORT_DASH);
s1.SetDefaultColor(GlobalColor("SDColor"));
s2.SetDefaultColor(GlobalColor("SDColor"));
s3.SetDefaultColor(GlobalColor("SDColor"));

plot r1 = if !DnHi or last then na else DnHi;
plot r2 = if !DnLo or last then na else DnLo;
def rMid = (r1 + r2) / 2;
plot r3 = rMid;
r1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3.SetStyle(Curve.SHORT_DASH);
r1.SetDefaultColor(Color.DARK_RED);
r2.SetDefaultColor(Color.DARK_RED);
r3.SetDefaultColor(Color.DARK_RED);

AddCloud(if s1!=s1[1] then na else s1, s2,  GlobalColor("SDColor"));
AddCloud(if r1!=r1[1] then na else r1, r2,  Color.DARK_RED);


#-- 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
457 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