code help, candle colors RSI

Nari2007

Member
hello fellow traders, seeking help with basic coding,,,

i am trying to get the candles to change red(BEARISH) when rsi is below 50line bullish(green) when above 50 line candles change to (cyan)when overbought70
change to yellow when oversold30

i have started to code below which is partially successful however it doesnt seem to change colors when above70 or below30, it is only changing green/red when above or below the 50 line,,

please see code below

declare upper;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input ColoredCandlesOn = yes;

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

def RSI = 50 * (ChgRatio + 1);
def OverSold = 70;
def OverBought = 30;

def UP = RSI > 50;
def DN = RSI < 50;
def UpCalc = UP - DN;

AssignPriceColor (if UP then Color.GREEN else if DN then Color.RED else if OverBought then Color.CYAN else if OverSold then Color.YELLOW
else Color.CURRENT
);
 
@Nari2007
You never defined what OverSold and OverBought were in relation to RSI.
The AssignPriceColor conditions are in the wrong order, in the logic of the if then else statement RSI will always meet criteria of UP or DN and will never check OverBought or OverSold. ( ie: Overbought is also UP and OverSold is also DN, but UP is not also OverBought and DN is not also OverSold).

mYeEvf6.png

Ruby:
declare upper;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input ColoredCandlesOn = yes;

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

def RSI = 50 * (ChgRatio + 1);

def OverSold = RSI <= 30;
def OverBought = RSI >= 70;

def UP = RSI > 50;
def DN = RSI < 50;
def UpCalc = UP - DN;

AssignPriceColor (if OverBought then Color.CYAN else if OverSold then Color.YELLOW else if UP then Color.GREEN else if DN then Color.RED else Color.CURRENT);
 

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

@Nari2007
You never defined what OverSold and OverBought were in relation to RSI.
The AssignPriceColor conditions are in the wrong order, in the logic of the if then else statement RSI will always meet criteria of UP or DN and will never check OverBought or OverSold. ( ie: Overbought is also UP and OverSold is also DN, but UP is not also OverBought and DN is not also OverSold).

mYeEvf6.png

Ruby:
declare upper;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input ColoredCandlesOn = yes;

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

def RSI = 50 * (ChgRatio + 1);

def OverSold = RSI <= 30;
def OverBought = RSI >= 70;

def UP = RSI > 50;
def DN = RSI < 50;
def UpCalc = UP - DN;

AssignPriceColor (if OverBought then Color.CYAN else if OverSold then Color.YELLOW else if UP then Color.GREEN else if DN then Color.RED else Color.CURRENT);
i am impressed... cant thank you enough, this is something i was really having a hard time with...
 
@Nari2007
You never defined what OverSold and OverBought were in relation to RSI.
The AssignPriceColor conditions are in the wrong order, in the logic of the if then else statement RSI will always meet criteria of UP or DN and will never check OverBought or OverSold. ( ie: Overbought is also UP and OverSold is also DN, but UP is not also OverBought and DN is not also OverSold).

mYeEvf6.png

Ruby:
declare upper;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input ColoredCandlesOn = yes;

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

def RSI = 50 * (ChgRatio + 1);

def OverSold = RSI <= 30;
def OverBought = RSI >= 70;

def UP = RSI > 50;
def DN = RSI < 50;
def UpCalc = UP - DN;

AssignPriceColor (if OverBought then Color.CYAN else if OverSold then Color.YELLOW else if UP then Color.GREEN else if DN then Color.RED else Color.CURRENT);
Good Morning, having same issue with Addlabel Feature,,

please see code below, any assistance would be greatly appreciated

declare upper;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input ColoredCandlesOn = yes;

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

def RSI = 50 * (ChgRatio + 1);

def OverSold = RSI <= 30;
def OverBought = RSI >= 70;

def UP = RSI > 50;
def DN = RSI < 50;
def UpCalc = UP - DN;

AssignPriceColor (if OverBought then Color.CYAN else if OverSold then Color.YELLOW else if UP then Color.GREEN else if DN then Color.RED else Color.CURRENT);

AddLabel (if OverBought then Color.CYAN else if OverSold then Color.YELLOW else if UP then Color.GREEN else if DN then Color.RED else Color.CURRENT);
 
@Nari2007
AddLabel needs 3 parameters.
Try this, I'm currently on my phone, so I cannot test.
Ruby:
AddLabel (yes, RSI, if OverBought then Color.CYAN else if OverSold then Color.YELLOW else if UP then Color.GREEN else if DN then Color.RED else Color.CURRENT);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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