Horizontal lines at high volume candles

Sircruse

New member
Hello, im looking for a script that will plot horizontal lines at some price levels. I want the script to take the chart data (I want to use daily chart) and look at the values of the opens, the highs, the lows, and the closes of candles that have 125% relative volume from the 50 day average, and to see which of those are closest to current price (so as to see only the closest support/resistance levels) and plot those as horizontal lines. I was trying to make it using chatgpt but was running into problems, it was saying it cant really use current price, so first i asked if it could use the close from the latest 1 minute candle, it said it can't so i settled with previous close on daily chart. Then it also was saying that it can't really find what values are closest to previous days close. So im just wondering if anyone could help me or if this has been made or something. I also wanted all the 125% rvol candles to be cyan if they were green and magenta if they were red, and for specifically the candles that have the horizontal lines coming from them, violet if they were green/cyan and plum if they were red/magenta
 
@Sircruse reworked some old code from other projects.
0fUsgOq.jpeg

Ruby:
input Length = 50;
input Increase = 1.25;
def VolAvg = Average(volume, Length);
def AbvTarget = volume/VolAvg >= Increase;
def ADClose = CompoundValue(1, close, Double.NaN);
def LastBar = !IsNaN(close) && IsNaN(close[-1]);
def NHigh = CompoundValue(1, if AbvTarget && !LastBar then high else 0, Double.NaN);
def NLow = CompoundValue(1, if AbvTarget && !LastBar then low else 0, Double.NaN);
def NOpen = CompoundValue(1, if AbvTarget && !LastBar then open else 0, Double.NaN);
def NClose = CompoundValue(1, if AbvTarget && !LastBar then close else 0, Double.NaN);
#######################################################################################
script TargetsA {
    
    input LastBar = 0;
    input Bar = 0;
    input Cross = 0;
    input ADClose = 0;   

    def TA = if LastBar then
            fold a = 0 to Bar
            with inta = Double.POSITIVE_INFINITY
            do if IsNaN(GetValue(Cross, a)) then inta
            else if GetValue(Cross, a) < ADClose then inta
            else if GetValue(Cross, a) > inta then inta
            else if GetValue(Cross, a) < inta and GetValue(Cross, a) >= ADClose
            then GetValue(Cross, a)
            else inta
            else TA[1];
    plot Targets = if !TA then Double.POSITIVE_INFINITY else TA;}
#######################################################################################
script TargetsB {
    
    input LastBar = 0;
    input Bar = 0;
    input Cross = 0;
    input ADClose = 0;

    def TA = if LastBar then
            fold a = 0 to Bar
            with inta = Double.NEGATIVE_INFINITY
            do if IsNaN(GetValue(Cross, a)) then inta
            else if GetValue(Cross, a) > ADClose then inta
            else if GetValue(Cross, a) < inta then inta
            else if GetValue(Cross, a) > inta and GetValue(Cross, a) <= ADClose
            then GetValue(Cross, a)
            else inta
            else TA[1];
    plot Targets = if !TA then Double.NEGATIVE_INFINITY else TA;}
##########################################
def CACH = TargetsA(1,Length, NHigh, ADClose);
def CACL = TargetsA(1,Length, NLow, ADClose);
def CACO = TargetsA(1,Length, NOpen, ADClose);
def CACC = TargetsA(1,Length, NClose, ADClose);
#########################################
def CBCH = TargetsB(1,Length, NHigh, ADClose);
def CBCL = TargetsB(1,Length, NLow, ADClose);
def CBCO = TargetsB(1,Length, NOpen, ADClose);
def CBCC = TargetsB(1,Length, NClose, ADClose);
###########################################
def PACH1 = TargetsA(LastBar,Length, CACH, ADClose);
def PBCH1 = TargetsB(LastBar,Length, CBCH, ADClose);
def PACL1 = TargetsA(LastBar,Length, CACL, ADClose);
def PBCL1 = TargetsB(LastBar,Length, CBCL, ADClose);
def PACO1 = TargetsA(LastBar,Length, CACO, ADClose);
def PBCO1 = TargetsB(LastBar,Length, CBCO, ADClose);
def PACC1 = TargetsA(LastBar,Length, CACC, ADClose);
def PBCC1 = TargetsB(LastBar,Length, CBCC, ADClose);
#############################################
def CH = if LastBar then if PACH1 == Double.POSITIVE_INFINITY then PBCH1 else if PBCH1 == Double.NEGATIVE_INFINITY then PACH1
            else if Min(close-PACH1,close-PBCH1)>=0 then PBCH1 else PACH1 else CH[1];
def CL = if LastBar then if PACL1 == Double.POSITIVE_INFINITY then PBCL1 else if PBCL1 == Double.NEGATIVE_INFINITY then PACL1
            else if Min(close-PACL1,close-PBCL1)>=0 then PBCL1 else PACL1 else CL[1];
def CO = if LastBar then if PACO1 == Double.POSITIVE_INFINITY then PBCO1 else if PBCO1 == Double.NEGATIVE_INFINITY then PACO1
            else if Min(close-PACO1,close-PBCO1)>=0 then PBCO1 else PACO1 else CO[1];
def CC = if LastBar then if PACC1 == Double.POSITIVE_INFINITY then PBCC1 else if PBCC1 == Double.NEGATIVE_INFINITY then PACC1
            else if Min(close-PACC1,close-PBCC1)>=0 then PBCC1 else PACC1 else CC[1];
###########################################
def ClosestHigh = fold H = 0 to 1000 while !IsNaN(GetValue(close, -h)) do GetValue(CH,-h);
def ClosestLow = fold l = 0 to 1000 while !IsNaN(GetValue(close, -l)) do GetValue(CL,-l);
def ClosestOpen = fold o = 0 to 1000 while !IsNaN(GetValue(close, -o)) do GetValue(CO,-o);
def ClosestClose = fold c = 0 to 1000 while !IsNaN(GetValue(close, -c)) do GetValue(CC,-c);
#############################################
def HighLine = if AbvTarget && high==ClosestHigh then ClosestHigh else HighLine[1];
def LowLine = if AbvTarget && low==ClosestLow then ClosestLow else LowLine[1];
def OpenLine = if AbvTarget && open==ClosestOpen then ClosestOpen else OpenLine[1];
def CloseLine = if AbvTarget && close==ClosestClose then ClosestClose else CloseLine[1];
##############################################
plot PCH = if CH then CH else if !IsNaN(close[-1]) && HighLine then HighLine else double.nan;
PCH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PCH.SetLineWeight(1);
plot PCL = if CL then CL else if !IsNaN(close[-1]) && LowLine then LowLine else Double.NaN;
PCL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PCL.SetLineWeight(1);
plot PCO = if CO then CO else if !IsNaN(close) && OpenLine then OpenLine else Double.NaN;
PCO.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PCO.SetLineWeight(1);
plot PCC = if CC then CC else if !IsNaN(close) && CloseLine then CloseLine else Double.NaN;
PCC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PCC.SetLineWeight(1);
################################
AssignPriceColor(if AbvTarget then if close>open then color.CYAN else color.Magenta else color.Current);
AssignPriceColor(if AbvTarget && high==PCH then if close>open then color.VIOLET else color.PLUM else color.Current);
AssignPriceColor(if AbvTarget && low==PCL then if close>open then color.VIOLET else color.PLUM else color.Current);
AssignPriceColor(if AbvTarget && open==PCO then if close>open then color.VIOLET else color.PLUM else color.Current);
AssignPriceColor(if AbvTarget && close==PCC then if close>open then color.VIOLET else color.PLUM else color.Current);
##########################################
 

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