Looking for a 50% retracement line of pervious candle coded

Hi All,

I wanted to know if someone can please write a basic code for a tradeovate chart where the previous candles 50% level will show just a little yellow line. I have this code with Thinkorswim and will add a picture of what I am looking for also the code its self if that helps.

Here is the TOS code. Also I just need the 50% retracement not the 25% or 75% levels… Thanks

def last = if isnan(close[-1]) and !isnan(close) then barnumber() else last[1];
def hilo = if hl2 then barnumber() else hilo[1];

def cond = if barNumber() == hilo then barNumber()-1 else double.nan;
def pbar = if barNumber() >= HighestAll(cond) and !last then 1 else double.nan;

input show50 = yes;
plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(color.Yellow);
HalfBack.SetLineWeight(3);
def hbext = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(3);

input show75 = yes;
plot Back75 = if show75 and !isnan(pbar) then low+(high-low)*.75 else double.nan;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(color.white);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if show25 and !isnan(pbar) then low+(high-low)*.25 else double.nan;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(color.white);
Back25.SetLineWeight(1);

input bubblemover = 1;
def n1 = bubblemover + 1;
input showbubble_candle = no;
input showbubble_expansion = no;
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),high,"H: " +high,color.white,yes);
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),low,"L: " +low,color.white,no);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),high[n1+1],"H: " +high[n1+1],color.white,yes);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),low[n1+1],"L: " +low[n1+1],color.white,no);
def h1 = if isnan(close) then h1[1] else high[1];
plot h1p = if barnumber()>=highestall(last) then h1 else double.nan;
h1p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
h1p.setdefaultColor(color.white);
input showcolor_light_gray = yes;
h1p.assignvalueColor(if showcolor_light_gray then color.Black else color.white);
def l1 = if isnan(close) then l1[1] else low[1];
plot l1p = if barnumber()>=highestall(last) then l1 else double.nan;
l1p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
l1p.setdefaultColor(color.white);
l1p.assignvalueColor(if showcolor_light_gray then color.Black else color.white);

Thank you
Jason

I just uploaded this to the community indicators.

I am also using this indicator as a basis for my tutorial series on how to write custom indicators for Tradovate. Like and subscribe. :grin:

Hey Latter-day Trader, about a year and a half ago you helped to create this code for me and I don’t know what happened but it is now showing the 50% retracement bar on the previous candle but when I hover the mouse on it it will show the mid value of the previous candle. It should be when I hover over the previous candle it should show that candles 50% value of that candle. I hope that makes sense… in short I want to be able to look at the current candle being made and the previous candle will have the line at 50% and I want those vales. Thank you

Hi. I am not sure I understand the problem. I haven’t updated the indicator since last year. Are you saying it doesn’t work as before or are you asking for something new?

It’s not working the same anymore. Meaning as the line shows on the previous candles 50% correct but when i put my mouse cursor over the 2nd candle where the line is and I pull up the data box on the chart and you look at the high and low are correct but the mid price value it will show the next candle, aka the 3rd candles 50% level. Hope that makes sense.

Hmmm. Like I said before, the code has not been updated for over a year, so I don’t know what to say. And it is hard for me to follow with the words you described. I just have been jumping back and forth between too many things to get the right context. If you can make a video with a voice over, that would be easiest for me to follow along.

Here is a quick video of what the issue is, thank you again for help on this and also sorry about the background noise…haha

Video link

Jason

Thanks for the video. It will be a couple days before I can get to this.

ok, sounds good, Thanks again for the help.

@latter-day-trader can the code be edited to show the 50% retrace of the candle open and close instead of the high and low?