Hi All,
What I want to do is pretty simple: I want to define a variable as the percentage of the trading session (from 9:30am to 4:00pm) that has already elapsed at the current time. So for example, the trading session is 6.5 hours and so at 12:45pm, 50% of the trading day (3 hours and 15 minutes) has elapsed, so I want the value "50% to be returned at 12:45pm.
This is the code I am trying:
Seems really simple, right? So I don't understand why I'm getting "Expected double" error when defining "TimeElapsedPercent" that way. Does anyone have insight they'd kindly share into how to fix this, or how to do what I'm trying to do?
EDIT: I'm just going to give up on making TOS convert the value into a percentage, and for display purposes will format the label this way whenever I'll show the percentage on a label (based on the example of how XeoNoX showed a percentage in a label for his volume forecast indicator):
What I want to do is pretty simple: I want to define a variable as the percentage of the trading session (from 9:30am to 4:00pm) that has already elapsed at the current time. So for example, the trading session is 6.5 hours and so at 12:45pm, 50% of the trading day (3 hours and 15 minutes) has elapsed, so I want the value "50% to be returned at 12:45pm.
This is the code I am trying:
Code:
input OpenTime = 0930;
input CloseTime = 1600;
def secondsPassed = SecondsFromTime(OpenTime);
def secondsLeft = SecondsTillTime(CloseTime);
def TimeElapsedPercent = AsPercent((secondsPassed) / (secondsPassed+secondsLeft));
Seems really simple, right? So I don't understand why I'm getting "Expected double" error when defining "TimeElapsedPercent" that way. Does anyone have insight they'd kindly share into how to fix this, or how to do what I'm trying to do?
EDIT: I'm just going to give up on making TOS convert the value into a percentage, and for display purposes will format the label this way whenever I'll show the percentage on a label (based on the example of how XeoNoX showed a percentage in a label for his volume forecast indicator):
Code:
input OpenTime = 0930;
input CloseTime = 1600;
def secondsPassed = SecondsFromTime(OpenTime);
def secondsLeft = SecondsTillTime(CloseTime);
def TimeElapsed = ((secondsPassed) / (secondsPassed+secondsLeft));
AddLabel (yes, if secondsPassed <= 0 then "% Time: NA" else "% Time: " + round(TimeElapsed*100,0), CreateColor(150,150,150));
Last edited: