I want to code an indicator in ThinkScript for use on TOS charts. I want to get the close of (whatever the bar name is) at 5PM. It seems the candles on TOS are called by the open and use an aggregate time to set the close. The problem is using an open to determine a close means the indicator will not work from one time frame to the next. I had a stock indicator and it was always frustrating because the indicator started at 0:45 bar. I have tried to change it but it does not fall on the close of any candle. In fact some days the indicator is far away from what should be the bar that closed. It is very confusing to me, when I look at any other platform, the time shown is the closing time for the candle that is open. Here is the code:
I have also attached a chart which shows the result.
Code:
# Inputs
input targetTime = 1700; # Target time in HHMM format (5:00 PM ET)
input showOnlyLastPeriod = no;
# Determines if the current candle is the exact bar that closes at 17:00 ET
def is1700Close = SecondsTillTime(targetTime) == 0;
# Holds the close price of the 1700 candle as soon as it completes
def level1700 = if is1700Close then close else level1700[1];
# Projects the previous day's 1700 close forward until the next 1700 candle closes
def prior1700Close = if is1700Close then level1700[1] else prior1700Close[1];
# Plotting
plot Line1700Close;
if showOnlyLastPeriod and !IsNaN(close[-1]) {
Line1700Close = Double.NaN;
} else {
Line1700Close = prior1700Close;
}
Line1700Close.SetDefaultColor(GetColor(9));
Line1700Close.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
I have also attached a chart which shows the result.