The Desire to Learn
Since you have included your code and have given it your best shot I see that you are trying to learn something here. So let's begin by examining your code and see where you went wrong. From this, we'll explore methods we can use to patch things up.
Code Review
In the following lines of code you take the user input for targetTime and use it to grab and hold the close of the last bar on the 5 min chart. That's great. The problem is you don't use any of these variables for the rest of the code. You use that value to plot on the chart. But it's never used again for the rest of the code.
def targetBar = SecondsFromTime(targetTime) == 0;
rec targetClose = if targetBar then close else targetClose[1];
plot data = targetClose;
Next, I'll skip ahead a few lines to show you another place where you just barely missed hitting your goal:
rec targetPeriodClose = marketClose;
rec targetPeriodOpen = marketOpen;
You tagged these as 'rec' however there is no recursion used in their formation. It is clear from the variable names what you intended them to hold but you have only assigned them the value of the user inputs: marketClose and marketOpen. So what you end up with is this:
targetPeriodClose = 935
targetPeriodOpen = 1555
But that's really a moot point, because once again we see that neither of these two variables are being used later on in the code. Then you repeat this exact same thing in the next two lines:
plot today = marketClose;
plot yesterday = marketOpen;
But it's pretty clear you actually intended the two variables to contain the 16:00 close and the close of 9:35. We can see that from the very next line of code:
def range = if !targetHours then today – yesterday else Double.NaN;
You are trying to compute the range between the 16:00 and 9:35 close however this is really what you end up with:
range = if targetHours is true then 935 - 1555 otherwise N/A
If I remove all the lines of code that are not being used for the very last statement here is what remains:
input fibOne = 50.0;
input marketOpen = 1555;
input marketClose = 935;
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
plot today = marketClose;
plot yesterday = marketOpen;
def range = if !targetHours then today – yesterday else Double.NaN;
plot fibLevelOne = if range > 0 then (range * (fibOne * 0.01)) + yesterday else Double.NaN;
It still doesn't work but you can see how that makes things so much easier to diagnose. You don't have a bunch of unused lines of code cluttering things up. Always reduce things to their most simplistic form. Only once you get that part working should you add to it.
The Solution
To solve this, I took the elements of your code that was working and added a few lines to fill in the gaps. You already had yesterday's close. So I duplicated those lines and tweaked them to grab today's 9:35 close. Then I took those values and assigned them to your plots, yesterday and today. Which then trickled down into the remaining lines of code to compute your 50% fibonacci level.
input targetTime = 1555;
input fibOne = 50.0;
input marketOpen = 1555;
input marketClose = 935;
def targetBarStart = SecondsFromTime(targetTime) == 0;
def targetBarEnd = SecondsFromTime(marketClose) == 0;
rec targetCloseStart = if targetBarStart then close else targetCloseStart[1];
rec targetCloseEnd = if targetBarEnd then close else targetCloseEnd[1];
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
plot today = targetCloseEnd;
plot yesterday = targetCloseStart;
def range = if !targetHours then today – yesterday else Double.NaN;
plot fibLevelOne = if range > 0 then (range * (fibOne * 0.01)) + yesterday else Double.NaN;
So, you had it right at some point. But as you added lines of code you lost track of stuff that was crucial to your success. Screenshot below shows the result.