SVSI displacement

dsvitale

New member
VIP
I have merged the SVSI and the TDI to plot together. How can I get the SVSI to plot a certain number of candles forward or backward?
Ruby:
# LS_TradersDynamIcIndex_long
# Traders Dynamic Index
# 2 smoothed RSIs Plotted on OverBought / OverSold Grid
# with Bollinger Band of unsmoothed RSIs

declare lower;
input averageType = {default SMA, EMA, wildersAverage};
input over_bought = 68;
input over_sold = 32;

# RSI (Relative Strength Index)====================

input Period = 13;
def RegRSI = reference RSI(Period);

# Compute 2 smoothed (by averaging) RSIs------------------
# 2 Smoothers--------------------------------------------------------
input sm1 = 2; # 1st RSI smoother
input sm2 = 7; # 2nd RSI smoother

# 1st smoothed RSI--------------------------------------------------
# Either ----------------------------------------------------------------
# (1) a simple averaging (SMA) or -------------------------
# (2) an exponential averaging (EMA)---------------------

def smRSI1 = if averageType == averageType.SMA then Average(RegRSI, sm1 ) else ExpAverage(RegRSI, sm1);

# 2nd smoothed RSI------------------------------------------------
# Either ---------------------------------------------------------------
# (1) a simple averaging (SMA) or ---------------------
# (2) an exponential averaging (EMA)-----------------

def smRSI2 = if averageType == averageType.SMA then Average(RegRSI, sm2) else ExpAverage(RegRSI, sm2);

# So far we have:
# 1. RegRSI = RSI
# 2. smRSI1 = 1st smoothed RSI, smoother = 2
# 3. smRSI2 = 2nd smoothed RSI, smoother = 7

#--------------------------------------------------------------------------
# PLOTS---------------------------------------------------------------
#---------------------------------------------------------------------------


# RSI1---1st smoothed RSI----------------------------------------
plot RSI1 = smRSI1;
RSI1.SetDefaultColor(Color.GREEN);
RSI1.SetLineWeight(2);
RSI1.SetStyle(Curve.FIRM);
RSI1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
RSI1.HideBubble();
RSI1.HideTitle();

# RSI2---2nd smoothed RSI---------------------------------------
plot RSI2 = smRSI2;
RSI2.SetDefaultColor(Color.CYAN);
RSI2.SetLineWeight(2);
RSI2.SetStyle(Curve.FIRM);
RSI2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
RSI2.HideBubble();
RSI2.HideTitle();

#============================================
# Bollinger Bands of RSI=========================
#============================================

# Length of Bollinger Averaging---------------------------------
input BBlength = 34;
# Width of Bollinger Band in Standard Deviations----------
input BBsdMult = 1.5;
# Mid-line for the Bollinger Band of the RegRSIs -----------

plot BBmidline = Average(RegRSI, BBlength);
BBmidline.SetDefaultColor(Color.CYAN);
BBmidline.SetLineWeight(5);
BBmidline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
BBmidline.SetStyle(Curve.FIRM);
BBmidline.HideBubble();
BBmidline.HideTitle();

#BBmidline.AssignValueColor(if BBmidline < BBmidline [1] then Color.red else (if BBmidline == BBmidline [1] then Color.green else Color.white));

#--------------------------------------------------------------------------
# Upper and Lower Bollinger Bands---------------------------
#---------------------------------------------------------------------------

# Standard Deviation of unsmoothed RSIs-------------------
def SDBB = StDev(RegRSI, BBlength);

# Upper Line of Bollinger Band----------------------------------
plot uBBline = BBmidline + BBsdMult * SDBB;

uBBline.SetDefaultColor(Color.WHITE);
uBBline.SetStyle(Curve.LONG_DASH);
uBBline.SetLineWeight(1);
uBBline.HideBubble();
uBBline.HideTitle();

# Lower Line of Bollinger Band---------------------------------
plot lBBline = BBmidline - BBsdMult * SDBB;

lBBline.SetDefaultColor(Color.WHITE);
lBBline.SetStyle(Curve.LONG_DASH);
lBBline.SetLineWeight(1);
lBBline.HideBubble();
lBBline.HideTitle();

#--------------------------------------------------------------------------
# GRID-----------------------------------------------------------------
#--------------------------------------------------------------------------

plot OB = 68; # OverBought
plot ML = 50; # Mid-Line
plot OS = 32; # OverSold

OB.SetStyle(Curve.FIRM);
OB.SetDefaultColor(Color.VIOLET);
OB.SetLineWeight(1);
#OB.HideBubble();
OB.HideTitle();

ML.SetStyle(Curve.LONG_DASH);
ML.SetDefaultColor(Color.WHITE);
ML.SetLineWeight(3);
#ML.HideBubble();
ML.HideTitle();


OS.SetStyle(Curve.FIRM);
OS.SetDefaultColor(Color.LIGHT_GREEN);
OS.SetLineWeight(1);
#OS.HideBubble();
OS.HideTitle();

#---------------------------------------------------------------------------
# Cloud between RSI2 and BBmidline-------------------------
#---------------------------------------------------------------------------

#AddCloud (RSI2, BBmidline, Color.WHITE, Color.YELLOW);

#plot OverSold = over_sold;
#plot OverBought = over_bought;


AddLabel (yes, " RSI1 " + Round (RSI1 , 2) , Color.GREEN);

AddLabel (yes, " RSI2 " + Round (RSI2 , 2) , Color.light_RED);

input emaLength = 6;
input vsiLength = 14;
input over_b = 80;
input over_s = 20;
input Extreme_High = 95;
input Extreme_Low = 15;


def ema = ExpAverage(close, emaLength);
def avgVolUp = WildersAverage(if close > ema then volume else 0, vsiLength);
def avgVolDown = WildersAverage(if close < ema then volume else 0, vsiLength);

plot SlowVSI = if avgVolUp + avgVolDown == 0 then 50 else 100 * avgVolUp / (avgVolUp + avgVolDown);
plot OverBought = over_b;
plot MiddleLine = 50;
plot OverSold = over_s;
plot EH = Extreme_High;
plot EL = Extreme_Low;

SlowVSI.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(5));
MiddleLine.SetDefaultColor(GetColor(5));
MiddleLine.SetStyle(Curve.LONG_DASH);
OverSold.SetDefaultColor(GetColor(5));

AddLabel (yes, " SVSI " + Round (SLowVSI , 2) , Color.viOLET);

# END ======================================
 
Last edited by a moderator:
Solution
I have merged the SVSI and the TDI to plot together. How can I get the SVSI to plot a certain number of candles forward or backward?
Ruby:
# LS_TradersDynamIcIndex_long
# Traders Dynamic Index
# 2 smoothed RSIs Plotted on OverBought / OverSold Grid
# with Bollinger Band of unsmoothed RSIs

declare lower;
input averageType = {default SMA, EMA, wildersAverage};
input over_bought = 68;
input over_sold = 32;

# RSI (Relative Strength Index)====================

input Period = 13;
def RegRSI = reference RSI(Period);

# Compute 2 smoothed (by averaging) RSIs------------------
# 2 Smoothers--------------------------------------------------------
input sm1 = 2; # 1st RSI smoother
input sm2 = 7; # 2nd RSI smoother

# 1st smoothed...
I have merged the SVSI and the TDI to plot together. How can I get the SVSI to plot a certain number of candles forward or backward?
Ruby:
# LS_TradersDynamIcIndex_long
# Traders Dynamic Index
# 2 smoothed RSIs Plotted on OverBought / OverSold Grid
# with Bollinger Band of unsmoothed RSIs

declare lower;
input averageType = {default SMA, EMA, wildersAverage};
input over_bought = 68;
input over_sold = 32;

# RSI (Relative Strength Index)====================

input Period = 13;
def RegRSI = reference RSI(Period);

# Compute 2 smoothed (by averaging) RSIs------------------
# 2 Smoothers--------------------------------------------------------
input sm1 = 2; # 1st RSI smoother
input sm2 = 7; # 2nd RSI smoother

# 1st smoothed RSI--------------------------------------------------
# Either ----------------------------------------------------------------
# (1) a simple averaging (SMA) or -------------------------
# (2) an exponential averaging (EMA)---------------------

def smRSI1 = if averageType == averageType.SMA then Average(RegRSI, sm1 ) else ExpAverage(RegRSI, sm1);

# 2nd smoothed RSI------------------------------------------------
# Either ---------------------------------------------------------------
# (1) a simple averaging (SMA) or ---------------------
# (2) an exponential averaging (EMA)-----------------

def smRSI2 = if averageType == averageType.SMA then Average(RegRSI, sm2) else ExpAverage(RegRSI, sm2);

# So far we have:
# 1. RegRSI = RSI
# 2. smRSI1 = 1st smoothed RSI, smoother = 2
# 3. smRSI2 = 2nd smoothed RSI, smoother = 7

#--------------------------------------------------------------------------
# PLOTS---------------------------------------------------------------
#---------------------------------------------------------------------------


# RSI1---1st smoothed RSI----------------------------------------
plot RSI1 = smRSI1;
RSI1.SetDefaultColor(Color.GREEN);
RSI1.SetLineWeight(2);
RSI1.SetStyle(Curve.FIRM);
RSI1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
RSI1.HideBubble();
RSI1.HideTitle();

# RSI2---2nd smoothed RSI---------------------------------------
plot RSI2 = smRSI2;
RSI2.SetDefaultColor(Color.CYAN);
RSI2.SetLineWeight(2);
RSI2.SetStyle(Curve.FIRM);
RSI2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
RSI2.HideBubble();
RSI2.HideTitle();

#============================================
# Bollinger Bands of RSI=========================
#============================================

# Length of Bollinger Averaging---------------------------------
input BBlength = 34;
# Width of Bollinger Band in Standard Deviations----------
input BBsdMult = 1.5;
# Mid-line for the Bollinger Band of the RegRSIs -----------

plot BBmidline = Average(RegRSI, BBlength);
BBmidline.SetDefaultColor(Color.CYAN);
BBmidline.SetLineWeight(5);
BBmidline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
BBmidline.SetStyle(Curve.FIRM);
BBmidline.HideBubble();
BBmidline.HideTitle();

#BBmidline.AssignValueColor(if BBmidline < BBmidline [1] then Color.red else (if BBmidline == BBmidline [1] then Color.green else Color.white));

#--------------------------------------------------------------------------
# Upper and Lower Bollinger Bands---------------------------
#---------------------------------------------------------------------------

# Standard Deviation of unsmoothed RSIs-------------------
def SDBB = StDev(RegRSI, BBlength);

# Upper Line of Bollinger Band----------------------------------
plot uBBline = BBmidline + BBsdMult * SDBB;

uBBline.SetDefaultColor(Color.WHITE);
uBBline.SetStyle(Curve.LONG_DASH);
uBBline.SetLineWeight(1);
uBBline.HideBubble();
uBBline.HideTitle();

# Lower Line of Bollinger Band---------------------------------
plot lBBline = BBmidline - BBsdMult * SDBB;

lBBline.SetDefaultColor(Color.WHITE);
lBBline.SetStyle(Curve.LONG_DASH);
lBBline.SetLineWeight(1);
lBBline.HideBubble();
lBBline.HideTitle();

#--------------------------------------------------------------------------
# GRID-----------------------------------------------------------------
#--------------------------------------------------------------------------

plot OB = 68; # OverBought
plot ML = 50; # Mid-Line
plot OS = 32; # OverSold

OB.SetStyle(Curve.FIRM);
OB.SetDefaultColor(Color.VIOLET);
OB.SetLineWeight(1);
#OB.HideBubble();
OB.HideTitle();

ML.SetStyle(Curve.LONG_DASH);
ML.SetDefaultColor(Color.WHITE);
ML.SetLineWeight(3);
#ML.HideBubble();
ML.HideTitle();


OS.SetStyle(Curve.FIRM);
OS.SetDefaultColor(Color.LIGHT_GREEN);
OS.SetLineWeight(1);
#OS.HideBubble();
OS.HideTitle();

#---------------------------------------------------------------------------
# Cloud between RSI2 and BBmidline-------------------------
#---------------------------------------------------------------------------

#AddCloud (RSI2, BBmidline, Color.WHITE, Color.YELLOW);

#plot OverSold = over_sold;
#plot OverBought = over_bought;


AddLabel (yes, " RSI1 " + Round (RSI1 , 2) , Color.GREEN);

AddLabel (yes, " RSI2 " + Round (RSI2 , 2) , Color.light_RED);

input emaLength = 6;
input vsiLength = 14;
input over_b = 80;
input over_s = 20;
input Extreme_High = 95;
input Extreme_Low = 15;


def ema = ExpAverage(close, emaLength);
def avgVolUp = WildersAverage(if close > ema then volume else 0, vsiLength);
def avgVolDown = WildersAverage(if close < ema then volume else 0, vsiLength);

plot SlowVSI = if avgVolUp + avgVolDown == 0 then 50 else 100 * avgVolUp / (avgVolUp + avgVolDown);
plot OverBought = over_b;
plot MiddleLine = 50;
plot OverSold = over_s;
plot EH = Extreme_High;
plot EL = Extreme_Low;

SlowVSI.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(5));
MiddleLine.SetDefaultColor(GetColor(5));
MiddleLine.SetStyle(Curve.LONG_DASH);
OverSold.SetDefaultColor(GetColor(5));

AddLabel (yes, " SVSI " + Round (SLowVSI , 2) , Color.viOLET);

# END ======================================

i think this is what you are asking for.

input vsi_offset = 7;
this picks how many bars to shift the svsi line sideways

i added this, it extends the horizontal lines past the last bar, for x bars.
def off2 = 10;


Code:
#svsi_and_tdi

#https://usethinkscript.com/threads/svsi-displacement.18511/
#SVSI displacement
#dsvitale  4/23  #1

#I have merged the SVSI and the TDI to plot together. How can I get the SVSI to plot a certain number of candles forward or backward?

# LS_TradersDynamIcIndex_long
# Traders Dynamic Index
# 2 smoothed RSIs Plotted on OverBought / OverSold Grid
# with Bollinger Band of unsmoothed RSIs

declare lower;

def na = double.nan;
def bn = barnumber();
def is = if isnan(close) then 0 else 1;

# offset for vsi
input vsi_offset = 7;
# min offset for horz lines
def off2 = 10;
# horz line offset 
def off3 = max(vsi_offset, off2);
def is2 = if !isnan(close) then 1
 else if (isnan(close[0]) and !isnan(close[off3])) then 1
 else 0;

input averageType = {default SMA, EMA, wildersAverage};
input over_bought = 68;
input over_sold = 32;

# RSI (Relative Strength Index)====================

input Period = 13;
def RegRSI = reference RSI(Period);

# Compute 2 smoothed (by averaging) RSIs------------------
# 2 Smoothers--------------------------------------------------------
input sm1 = 2; # 1st RSI smoother
input sm2 = 7; # 2nd RSI smoother

# 1st smoothed RSI--------------------------------------------------
# Either ----------------------------------------------------------------
# (1) a simple averaging (SMA) or -------------------------
# (2) an exponential averaging (EMA)---------------------

def smRSI1 = if averageType == averageType.SMA then Average(RegRSI, sm1 ) else ExpAverage(RegRSI, sm1);

# 2nd smoothed RSI------------------------------------------------
# Either ---------------------------------------------------------------
# (1) a simple averaging (SMA) or ---------------------
# (2) an exponential averaging (EMA)-----------------

def smRSI2 = if averageType == averageType.SMA then Average(RegRSI, sm2) else ExpAverage(RegRSI, sm2);

# So far we have:
# 1. RegRSI = RSI
# 2. smRSI1 = 1st smoothed RSI, smoother = 2
# 3. smRSI2 = 2nd smoothed RSI, smoother = 7

#--------------------------------------------------------------------------
# PLOTS---------------------------------------------------------------
#---------------------------------------------------------------------------


# RSI1---1st smoothed RSI----------------------------------------
plot RSI1 = smRSI1;
RSI1.SetDefaultColor(Color.GREEN);
RSI1.SetLineWeight(2);
RSI1.SetStyle(Curve.FIRM);
RSI1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
RSI1.HideBubble();
RSI1.HideTitle();

# RSI2---2nd smoothed RSI---------------------------------------
plot RSI2 = smRSI2;
RSI2.SetDefaultColor(Color.CYAN);
RSI2.SetLineWeight(2);
RSI2.SetStyle(Curve.FIRM);
RSI2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
RSI2.HideBubble();
RSI2.HideTitle();

#============================================
# Bollinger Bands of RSI=========================
#============================================

# Length of Bollinger Averaging---------------------------------
input BBlength = 34;
# Width of Bollinger Band in Standard Deviations----------
input BBsdMult = 1.5;
# Mid-line for the Bollinger Band of the RegRSIs -----------

plot BBmidline = Average(RegRSI, BBlength);
BBmidline.SetDefaultColor(Color.CYAN);
BBmidline.SetLineWeight(5);
BBmidline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
BBmidline.SetStyle(Curve.FIRM);
BBmidline.HideBubble();
BBmidline.HideTitle();

#BBmidline.AssignValueColor(if BBmidline < BBmidline [1] then Color.red else (if BBmidline == BBmidline [1] then Color.green else Color.white));

#--------------------------------------------------------------------------
# Upper and Lower Bollinger Bands---------------------------
#---------------------------------------------------------------------------

# Standard Deviation of unsmoothed RSIs-------------------
def SDBB = StDev(RegRSI, BBlength);

# Upper Line of Bollinger Band----------------------------------
plot uBBline = BBmidline + BBsdMult * SDBB;

uBBline.SetDefaultColor(Color.WHITE);
uBBline.SetStyle(Curve.LONG_DASH);
uBBline.SetLineWeight(1);
uBBline.HideBubble();
uBBline.HideTitle();

# Lower Line of Bollinger Band---------------------------------
plot lBBline = BBmidline - BBsdMult * SDBB;

lBBline.SetDefaultColor(Color.WHITE);
lBBline.SetStyle(Curve.LONG_DASH);
lBBline.SetLineWeight(1);
lBBline.HideBubble();
lBBline.HideTitle();

#--------------------------------------------------------------------------
# GRID-----------------------------------------------------------------
#--------------------------------------------------------------------------

plot OB = if is2 then 68 else na; # OverBought
plot ML = if is2 then 50 else na; # Mid-Line
plot OS = if is2 then 32 else na; # OverSold

OB.SetStyle(Curve.FIRM);
OB.SetDefaultColor(Color.VIOLET);
OB.SetLineWeight(1);
#OB.HideBubble();
OB.HideTitle();

ML.SetStyle(Curve.LONG_DASH);
ML.SetDefaultColor(Color.WHITE);
ML.SetLineWeight(3);
#ML.HideBubble();
ML.HideTitle();


OS.SetStyle(Curve.FIRM);
OS.SetDefaultColor(Color.LIGHT_GREEN);
OS.SetLineWeight(1);
#OS.HideBubble();
OS.HideTitle();

#---------------------------------------------------------------------------
# Cloud between RSI2 and BBmidline-------------------------
#---------------------------------------------------------------------------

#AddCloud (RSI2, BBmidline, Color.WHITE, Color.YELLOW);

#plot OverSold = over_sold;
#plot OverBought = over_bought;


AddLabel (yes, " RSI1 " + Round (RSI1 , 2) , Color.GREEN);
AddLabel (yes, " RSI2 " + Round (RSI2 , 2) , Color.light_RED);

input emaLength = 6;
input vsiLength = 14;
input over_b = 80;
input over_s = 20;
input Extreme_High = 95;
input Extreme_Low = 15;


def ema = ExpAverage(close, emaLength);
def avgVolUp = WildersAverage(if close > ema then volume else 0, vsiLength);
def avgVolDown = WildersAverage(if close < ema then volume else 0, vsiLength);

#plot SlowVSI = if avgVolUp + avgVolDown == 0 then 50 else 100 * avgVolUp / (avgVolUp + avgVolDown);
def SlowVSI_ = if avgVolUp + avgVolDown == 0 then 50 else 100 * avgVolUp / (avgVolUp + avgVolDown);


plot slowvsi = getvalue(slowvsi_, vsi_offset);
plot OverBought = if is2 then over_b else na;
plot MiddleLine = if is2 then 50 else na;
plot OverSold = if is2 then over_s else na;
plot EH = if is2 then Extreme_High else na;
plot EL = if is2 then Extreme_Low else na;

SlowVSI.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(5));
MiddleLine.SetDefaultColor(GetColor(5));
MiddleLine.SetStyle(Curve.LONG_DASH);
OverSold.SetDefaultColor(GetColor(5));

AddLabel (yes, " SVSI " + Round (SLowVSI , 2) , Color.viOLET);

# END ======================================
 

Attachments

  • Capture.JPG
    Capture.JPG
    129.3 KB · Views: 56
Solution

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

Thread starter Similar threads Forum Replies Date
D STC plot with displacement Questions 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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