Setting Deadline Timer on Candle Chart
stableDescription
I've come over a problem, I wanted to solve, that has to do with reaching deadlines in the future, like canceling a position or something the like.
I have implemented a Custom Command library function and the corresponding code. (See below)
Setting uses the same parameters as AdjustTimestamp().
I hope you enjoy it
PS: @phsai, Thanks for pointing out, that StartTimer, StopTimer, and GetTimer is for measuring process time within a script.
HaasScript
-- Author: romdisc
DefineCommand('TimeUtils', 'Time Utils')
local out = {
trim = function(time, interval)
return time - time % (interval * 60)
end,
set_deadline_from_now = function(name, adjustment)
if adjustment == nil then adjustment = {} end
Save('--deadline-'..name, AdjustTimestamp(adjustment))
end,
is_deadline_reached = function(name)
return Time() >= Load('--deadline-'..name, NumberMax)
end,
clear_deadline = function(name)
Delete('--deadline-'..name)
end,
}
DefineOutput(ListDynamicType, out, 'Time Utils')
-- Production Code:
local now = Time()
if now == time_utils.trim(now, greater_interval) then
time_utils.set_deadline_from_now('timer', { addMinutes = 5 })
Log('starting deadline')
end
if time_utils.is_deadline_reached('timer') then
Log('deadline reached')
time_utils.clear_deadline('timer')
end
1 Comment
Sign in to leave a comment.
Hey, I tried saving your script but I'm getting the following errors:
"4. Sep 29, 24, 19:05:56 Compiling script...
3. Sep 29, 24, 19:05:56 ERROR: - time_utils
2. Sep 29, 24, 19:05:56 ERROR: - greater_interval
1. Sep 29, 24, 19:05:56 ERROR: Unknown references"
What am I missing exactly?