carey3
New member
#hint: This draws a horizontal bar at the close or PinValue and 3 set percentages above and below that value./n I wanted a visual line to show where plus and minus 6%, 10% and 15% or 20% was when walking through my watch list./n The PinValue will be used instead of the close value if it is set to anything other than 0.0.
Code:
#hint: This draws a horizontal bar at the close or PinValue and 3 set precentages above and below that value./n I wanted a visual line to show where plus and minus 6%, 10% and 15% or 20% was when walking through my watch list./n The PinValue will be used instead of the close value if it is set to anything other than 0.0.\n# this started with only 2 values above and below close, decided to add 6% and 15% later. \n Then I added Stochastic, HullMovingAvg and Exponential MovingAverage
# (c) Carey Lynch 2026
# updated with Stochastic, HMA, and EMA in
# shared on ToS as !Cp1EghKu
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
input PinValue = 0.00;
input Hig1percent = 1.06;input ShowHig1 = yes;
input Hig2percent = 1.10;input ShowHig2 = yes;
input Hig3percent = 1.15;input ShowHig3 = yes;
input Low1percent = 0.94;input ShowLow1 = yes;
input Low2percent = 0.90;input ShowLow2 = yes;
input Low3percent = 0.85;input ShowLow3 = yes;
input lineWeight = 2;
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
def price = close[1];# because the horizontals are one bar past the last bar.
def centerPt = if PinValue == 0 then price else PinValue;
def lastClose = if isNaN(close) and !isNaN(close[1]) then centerPt else Double.NaN;
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
plot UC = Double.NaN;# I started with different colors, but decided on bright yellow for all lines
UC.DefineColor("BrightYellow", CreateColor(255,255,150));
UC.DefineColor("up10%", CreateColor(255,255,150));
UC.DefineColor("up20%", CreateColor(255,255,150));
UC.DefineColor("dn10%", CreateColor(255,255,150));
UC.DefineColor("dn20%", CreateColor(255,255,150));
UC.DefineColor("Purple", CreateColor(164,000,255));
UC.DefineColor("DrkGrn", CreateColor(000, 128, 000));
UC.DefineColor("SpringGrn", CreateColor(000,255,127));
UC.DefineColor("HotPink", CreateColor(255,020,147));
UC.DefineColor("HMaMagenta", CreateColor(200, 000, 200));
UC.DefineColor("HMaCyan", CreateColor(000, 200, 200));
UC.DefineColor("DrkGray", CreateColor(128, 128, 128));
#<-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> HMA
input HmaLength = 9;
def HMAvalue = HullMovingAvg(length = HmaLength);
def hma = if HMAvalue[1] > HMAvalue[2] then 1.0
else if HMAvalue[1] < HMAvalue[2] then -1.0
else 0.0;
#def HmaBuy = hma > 0 and hma[1] <= 0;
def Hma2CxBuy = HMAvalue[1]> HMAvalue[2] and HMAvalue[2] < HMAvalue[3];
def Hma2CxSel = HMAvalue[1] < HMAvalue[2] and HMAvalue[2] > HMAvalue[3];
#<-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> Stochastic
input KPeriod = 7;#
input DPeriod = 3;
input slowingPeriod = 1;
input over_bought = 80;
def over_sold = 100 - over_bought;
def priceH = high()[1];#(period = aggregationPeriodS);# AggregationPeriod.DAY);
def priceL = low()[1];#(period = aggregationPeriodS);# AggregationPeriod.DAY);
def priceC = close()[1];#(period = aggregationPeriodS);# AggregationPeriod.DAY);
input averageType = AverageType.SIMPLE;
def lowest_k = Lowest(priceL[1], KPeriod );
def c1 = priceC[1] - lowest_k;
def c2 = Highest(priceH[1], KPeriod ) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def SchK = MovingAverage(averageType, FastK, slowingPeriod);
def SchD = MovingAverage(averageType, SchK, DPeriod );
#<-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> <-=-> EMA
input EMA0 = 3;
input EMA1 = 9;
input EMA2 = 21;
input AvgType = averageType.EXPONENTIAL;
def AVG0 = MovingAverage(AvgType, price, EMA0);
def AVG1 = MovingAverage(AvgType, price, EMA1);
def AVG2 = MovingAverage(AvgType, price, EMA2);
def EMA_Bull = AVG0 >= AVG1 or AVG1 >= AVG2;# or AVG1 >= priceH or AVG2 >= priceH;
def EMA_Bear = AVG0 <= AVG1 or AVG1 <= AVG2;# or AVG1 <= priceL or AVG2 <= priceL;
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
plot PIN = lastClose;
PIN.AssignValueColor( if (SchK > SchD or SchK crosses above over_Sold)
and (hma > 0 or Hma2CxBuy) and EMA_Bull
and price > Price[1] then UC.Color("SpringGrn")
else if price > Price[1] then UC.Color("DrkGrn")
else if (SchK < SchD or SchK crosses below over_bought)
and (hma < 0 or Hma2CxSel) and EMA_Bull
and price < Price[1] then UC.Color("HotPink")
else if price < Price[1] then UC.Color("Purple")
else UC.Color("BrightYellow") );
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
plot Pin1P = lastClose * Hig3percent; # 6% Stochastic
plot Pin2P = lastClose * Hig2percent; # 10% Hull MA
plot Pin3P = lastClose * Hig1percent; # 15% EMA
plot Pin4P = lastClose * Low1percent; # -6% Stochastic
plot Pin5P = lastClose * Low2percent; #-10% Hull MA
plot Pin6P = lastClose * Low3percent; #-15% EMA
PIN.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin1P.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin2P.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin3P.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin4P.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin5P.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin6P.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pin1P.AssignValueColor( if SchK > SchD or SchK crosses above over_sold then UC.Color("SpringGrn")
else if price > Price[1] then UC.Color("DrkGrn")
else UC.Color("BrightYellow") );
Pin2P.AssignValueColor( if hma > 0 or Hma2CxBuy then UC.Color("HMaCyan")
else if price > Price[1] then UC.Color("DrkGrn")
else UC.Color("BrightYellow") );
Pin3P.AssignValueColor( if EMA_Bull then UC.Color("SpringGrn")
else if price > Price[1] then UC.Color("DrkGrn")
else UC.Color("BrightYellow") );
Pin4P.AssignValueColor( if SchK < SchD or SchK crosses below over_bought then UC.Color("HotPink")
else if price < Price[1] then UC.Color("Purple")
else UC.Color("dn10%") );
Pin5P.AssignValueColor( if hma < 0 or Hma2CxSel then UC.Color("HMaMagenta")
else if price < Price[1] then UC.Color("Purple")
else UC.Color("BrightYellow") );
Pin6P.AssignValueColor( if EMA_Bear then UC.Color("HotPink")
else if price < Price[1] then UC.Color("Purple")
else UC.Color("BrightYellow") );
PIN.SetLineWeight(lineWeight);
Pin1P.SetLineWeight(lineWeight);
Pin2P.SetLineWeight(lineWeight);
Pin3P.SetLineWeight(lineWeight);
Pin4P.SetLineWeight(lineWeight);
Pin5P.SetLineWeight(lineWeight);
Pin6P.SetLineWeight(lineWeight);
Pin1P.setHiding(!ShowHig3);
Pin2P.setHiding(!ShowHig2);
Pin3P.setHiding(!ShowHig1);
Pin4P.setHiding(!ShowLow1);
Pin5P.setHiding(!ShowLow2);
Pin6P.setHiding(!ShowLow3);
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
input showLabels = no; # You could add High and low 3, but I didn't need it on the label bar.
input showStudies = yes;
AddLabel(showLabels or showStudies,"/|\^._.^/|\",
if EMA_Bull and SchK > SchD and hma > 0 then UC.Color("SpringGrn") else
if EMA_Bear and SchK < SchD and hma < 0 then UC.Color("HotPink")
else UC.Color("DrkGray") );
AddLabel(showLabels, " "+(Hig1Percent-1)*100+"% "+round(centerPt * Hig1Percent,1)+
" "+(Hig2Percent-1)*100+"% "+round(centerPt * Hig2Percent,1)+" Hma"+hma, UC.Color("SpringGrn") );
AddLabel(showLabels, " "+(Low1Percent-1)*100+"% "+round(centerPt * Low1Percent,1)+
" "+(Low2Percent-1)*100+"% "+round(centerPt * Low2Percent,1), UC.Color("HotPink") );
AddLabel(showStudies, "Hma" ,if hma > 0 or Hma2CxBuy then UC.Color("SpringGrn")
else if hma < 0 or Hma2CxSel then UC.Color("HotPink")
else UC.Color("BrightYellow") );
AddLabel(showStudies, "Sch" , if SchK > SchD or SchK crosses above over_sold then UC.Color("SpringGrn")
else if SchK < SchD or SchK crosses below over_bought then UC.Color("HotPink")
else UC.Color("BrightYellow") );
AddLabel(showStudies, "Ema" , if EMA_Bull then UC.Color("SpringGrn")
else if EMA_Bear then UC.Color("HotPink")
else UC.Color("BrightYellow") );
#<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-> That's All Folks
Last edited: