Paint VFI based on RSI

PAYtience

New member
VIP
Need help merging VFI and RSI - I am not able to assign color in a right way, here is what I am trying to do -

1. When RSI crosses over 60 change the VFI color to Green as long as RSI doesn't close below 40.
2. When RSI crosses below 40 change the VFI color to Red as long as RSI doesn't close above 60.

Here is the code I am trying to work on -

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2024
#

declare lower;

input length = 130;
input maxVolumeCutOff = 2.5;

Assert(maxVolumeCutOff > 0, "'max volume cut off' must be positive: " + maxVolumeCutOff);

def cutOff = 0.2 * StDev(Log(hlc3) - Log(hlc3[1]), 30) * close;
def hlcChange = hlc3 - hlc3[1];
def avgVolume = Average(volume, length)[1];
def minVolume = Min(volume, avgVolume * maxVolumeCutOff);
def dirVolume = if hlcChange > cutOff
    then minVolume
    else if hlcChange < -cutOff
        then -minVolume
        else 0;

plot VFI = ExpAverage(Sum(dirVolume, length) / avgVolume, 3);
plot ZeroLine = 0;

VFI.SetDefaultColor(GetColor(3));
ZeroLine.SetDefaultColor(GetColor(8));

#
# TD Ameritrade IP Company, Inc. (c) 2007-2024
#



input length_RIS = 14;
input over_Bought = 60;
input over_Sold = 40;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length_RIS);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length_RIS);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
def DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

VFI.DefineColor("Above", Color.GREEN);
VFI.DefineColor("None", Color.YELLOW);
VFI.DefineColor("Below", Color.RED);
VFI.AssignValueColor(if RSI crosses above OverBought and (RSI > 60 or RSI > 40) then VFI.color("Above") else if RSI crosses below OverSold and (RSI < 40 or RSI < 60) then VFI.color("Below") else VFI.color("None"));
 
Last edited:
Need help merging VFI and RSI - I am not able to assign color in a right way, here is what I am trying to do -

1. When RSI crosses over 60 change the VFI color to Green as long as RSI doesn't close below 40.
2. When RSI crosses below 40 change the VFI color to Red as long as RSI doesn't close above 60.

Here is the code I am trying to work on -

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2024
#

declare lower;

input length = 130;
input maxVolumeCutOff = 2.5;

Assert(maxVolumeCutOff > 0, "'max volume cut off' must be positive: " + maxVolumeCutOff);

def cutOff = 0.2 * StDev(Log(hlc3) - Log(hlc3[1]), 30) * close;
def hlcChange = hlc3 - hlc3[1];
def avgVolume = Average(volume, length)[1];
def minVolume = Min(volume, avgVolume * maxVolumeCutOff);
def dirVolume = if hlcChange > cutOff
    then minVolume
    else if hlcChange < -cutOff
        then -minVolume
        else 0;

plot VFI = ExpAverage(Sum(dirVolume, length) / avgVolume, 3);
plot ZeroLine = 0;

VFI.SetDefaultColor(GetColor(3));
ZeroLine.SetDefaultColor(GetColor(8));

#
# TD Ameritrade IP Company, Inc. (c) 2007-2024
#



input length_RIS = 14;
input over_Bought = 60;
input over_Sold = 40;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length_RIS);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length_RIS);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
def DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

VFI.DefineColor("Above", Color.GREEN);
VFI.DefineColor("None", Color.YELLOW);
VFI.DefineColor("Below", Color.RED);
VFI.AssignValueColor(if RSI crosses above OverBought and (RSI > 60 or RSI > 40) then VFI.color("Above") else if RSI crosses below OverSold and (RSI < 40 or RSI < 60) then VFI.color("Below") else VFI.color("None"));

here is something to experiment with
it draws the RSI with changing colors

Code:
#vfi_rsi_crossing_move

#https://usethinkscript.com/threads/paint-vfi-based-on-rsi.18725/
#1. When RSI crosses over 60 change the VFI color to Green as long as RSI doesn't close below 40.
#2. When RSI crosses below 40 change the VFI color to Red as long as RSI doesn't close above 60.

declare lower;

input upper = 60;
input lower = 40;

def r = RSI();

def c = if R crosses above upper then 1
 else if R crosses below lower then -1
 else c[1];

plot z = r;
z.AssignValueColor( 
 if c > 0 then color.Green
 else if c < 0 then color.Red
 else color.gray);
z.setlineweight(3);
z.hidebubble();

plot zu = upper;
plot zl = lower;
#
 

Attachments

  • img1.JPG
    img1.JPG
    58.8 KB · Views: 63

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

here is something to experiment with
it draws the RSI with changing colors

Code:
#vfi_rsi_crossing_move

#https://usethinkscript.com/threads/paint-vfi-based-on-rsi.18725/
#1. When RSI crosses over 60 change the VFI color to Green as long as RSI doesn't close below 40.
#2. When RSI crosses below 40 change the VFI color to Red as long as RSI doesn't close above 60.

declare lower;

input upper = 60;
input lower = 40;

def r = RSI();

def c = if R crosses above upper then 1
 else if R crosses below lower then -1
 else c[1];

plot z = r;
z.AssignValueColor(
 if c > 0 then color.Green
 else if c < 0 then color.Red
 else color.gray);
z.setlineweight(3);
z.hidebubble();

plot zu = upper;
plot zl = lower;
#
Thank a lot!! I should be able to work with this... :)
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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