Horizontal Lines At High & Low of Candle

MTG

New member
VIP
Hey all. I've been trying to add horizontal lines to this modified indicator but am having some trouble. When I use the horizontal painting strategy instead of boolean arrows it compresses the chart and adds the lines at the very bottom. Instead, I'd prefer for the lines to begin at the high or low of the candle and extend to the right until the line is touched. Can someone assist with this issue?

Code:
# # Sources:
# best with 5 mins timeframe.
# concept from shadowtrader.net
# coded by TWOO
# https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data
# sector-breakdown
# modified by CWPARKER23
# Modified by MTG to include DTSScalpersVolume and $Tick

input startTime = 0400;
input endTime = 0929;

input open_time = 930;
input length = 12;
input ShowLabel = yes;
input PriceChannel = yes;
input ShowArrow = no;
input ShowCloud = no;

input InformationTechnology = 26.8; # xlkwt
input HealthCare = 15.1; # xlvwt
input Financials = 10.8; # xlfwt
input ConsumerDiscretionary = 10.5; # xlywt
input Communications = 8.9; # xlcwt
input Industrials = 7.8; # xliwt
input ConsumerStaples = 7.0; # xlpwt
input Energy = 4.4; # xlewt
input Utilities = 3.1; # xluwt
input RealEstate = 2.9; # xlrewt
input Materials = 2.6; # xlbwt

def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
def BV = Buying;
def SV = Selling;

def VolumeHistogram = volume;


# Average Volume Line
def AverageVolume = Average(VolumeHistogram, 40);
def isTickChart = if GetAggregationPeriod() <= 3200 then 1 else 0;

def na = double.NaN ;
def SectorCount = 11;
def Scale = 5000;
def displace = 0;

#### COLORS
DefineGlobalColor("Bullish", Color.cyan);
DefineGlobalColor("Bearish", Color.pink);
DefineGlobalColor("Channel", CreateColor(100, 181, 246));

#SP500 ETF sectors percent change
script PC {
input Symbol = "SPX";
def isFirstBar = GetTime() == RegularTradingStart(GetYYYYMMDD()) + 1;
def O = if isFirstBar then close(Symbol) else O[1];
def C = close(Symbol);
plot PctChg = (C - O) / O;
}
def xlkPctChg = PC("XLK");
def xlyPctChg = PC("XLY");
def xlvPctChg = PC("XLV");
def xlfPctChg = PC("XLF");
def xlcPctChg = PC("XLC");
def xliPctChg = PC("XLI");
def xlpPctChg = PC("XLP");
def xlrePctChg = PC("XLRE");
def xlePctChg = PC("XLE");
def xlbPctChg = PC("XLB");
def xluPctChg = PC("XLU");

def xlkSizing = xlkPctChg * InformationTechnology;
def xlvSizing = xlvPctChg * HealthCare;
def xlySizing = xlyPctChg * ConsumerDiscretionary;
def xlfSizing = xlfPctChg * Financials;
def xlcSizing = xlcPctChg * Communications;
def xliSizing = xliPctChg * Industrials;
def xlpSizing = xlpPctChg * ConsumerStaples;
def xleSizing = xlePctChg * Energy;
def xlreSizing = xlrePctChg * RealEstate;
def xlbSizing = xlbPctChg * Materials;
def xluSizing = xluPctChg * Utilities;

def combinedSizing = Scale * (
xlkSizing +
xlvSizing +
xlySizing +
xlfSizing +
xlcSizing +
xliSizing +
xlpSizing +
xleSizing +
xlreSizing +
xlbSizing +
xluSizing
) / SectorCount;

# Weighted_AD
def Weighted_AD = if !IsNaN(combinedSizing) then combinedSizing else na;
#Zeroline
def zero = 0;

# SPX Non_Weighted_AD
def spxcombinedSizing = Scale *
(xlkPctChg +
xlvPctChg +
xlyPctChg +
xlfPctChg +
xlcPctChg +
xliPctChg +
xlpPctChg +
xlePctChg +
xlrePctChg +
xlbPctChg +
xluPctChg);

def Non_Weighted_AD = if !IsNaN(spxcombinedSizing) then spxcombinedSizing else na;

# divergence Weighted_AD
def isbulldiv = (weighted_AD - weighted_AD[1] )>0 and (LOW[1] - LOW)>0;
def isbeardiv = (weighted_AD[1] - weighted_AD )>0 and (HIGH - HIGH[1])>0;

def PositveDivergence = if isbulldiv then non_Weighted_AD else na;

plot PD = if ShowArrow then PositveDivergence else na;
PD.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
PD.SetDefaultColor(Color.WHITE);
PD.HideBubble();
PD.HideTitle();

def NegativeDivergence = if isbeardiv then non_Weighted_AD else na;

plot ND = if ShowArrow then NEGativeDivergence else na;
ND.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ND.SetDefaultColor(Color.YELLOW);
ND.HideBubble();
ND.HideTitle();

#SP500 ETF sectors BUBBLE
Script pct {
input Symbol = "SPX";
def aggregationPeriod = AggregationPeriod.DAY;
def price = open(Symbol, period = aggregationPeriod);
def diff = close (Symbol) - open(Symbol, period = aggregationPeriod);
plot d_pct = 100 * diff / price;
}

def XLK_d_pct = pct(“XLK”) ;
def XLV_d_pct = pct(“XLV”) ;
def XLY_d_pct = pct(“XLY”) ;
def XLC_d_pct = pct(“XLC”) ;
def XLF_d_pct = pct(“XLF”) ;
def XLI_d_pct = pct(“XLI”) ;
def XLP_d_pct = pct(“XLP”) ;
def XLRE_d_pct = pct(“XLRE”) ;
def XLB_d_pct = pct(“XLB”) ;
def XLU_d_pct = pct(“XLU”) ;
def XLE_d_pct = pct(“XLE”) ;
 
def TickLow = low("$TICK");
def TickHigh = high ("$TICK");

def Condition = if
weighted_AD>=40  and ticklow <=-450
then 1 else Double.NaN;
plot A = Condition;
A.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_up);

def Condition1 = if
weighted_AD<=-40  and tickhigh >=450
then 1 else Double.NaN;
plot B = Condition1;
B.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_down);
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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