Plots Line that is interrupted, when no values are available
betaDescription
This command plots a line that is interrupted, when you provide no values.
It might be usefull, for instance, when you have a trailing stop loss active during an active position.
When there is no placed position, then you don't need the trailing stop loss marker.
Warning: The plot might be sometimes inaccurate. I haven't figured you, yet, what the error criteria is.
HaasScript
-- Name: Plot Line Interrupted #001
-- Author: romdisc
-- Date: 07/22/2022
-- Update: 07/23/2022
-- haven't figured out, why it's sometimes inaccurate
DefineCommand('plot_line_interrupted_001', 'Plot a Line with missing parts #001')
local chart_id = DefineParameter(NumberType, 'chart_id', 'Chart Id', true, 0)
local name = DefineParameter(StringType, 'name', 'Name of Plot', true, '')
local value = DefineParameter(ListNumberType, 'value', 'Value to plot', true, 0)
local draw = DefineParameter(BooleanType, 'draw', 'actually draw', true, false)
local color = DefineParameter(StringType, 'color', 'color', false, 'white')
local style = DefineParameter(EnumType, 'style', 'style', false, Spiked)
local deco = DefineParameter(EnumType, 'deco', 'deco', false, Solid)
local color_to_enum = function(color)
if color == 'aqua' then return Aqua end
if color == 'black' then return Black end
if color == 'blue' then return Blue end
if color == 'cyan' then return Cyan end
if color == 'darkGray' then return DarkGray end
if color == 'darkGreen' then return DarkGreen end
if color == 'fuchsia' then return Fuchsia end
if color == 'gold' then return Gold end
if color == 'gray' then return Gray end
if color == 'green' then return Green end
if color == 'maroon' then return Maroon end
if color == 'olive' then return Olive end
if color == 'orange' then return Orange end
if color == 'purple' then return Purple end
if color == 'red' then return Red end
if color == 'skyblue' then return SkyBlue end
if color == 'teal' then return Teal end
if color == 'white' then return White end
if color == 'yellow' then return Yellow end
end
local plot = function(chart_id, name, value, draw, color, style, deco)
local guid = Load('plot-guid', '')
if draw and guid == '' then
guid = NewGuid()
end
if draw then
Plot(chart_id, name, value, LineOptions({
color = color,
style = style,
deco = deco,
behind = false,
id = guid,
}))
end
if not draw and guid != '' then
guid = ''
end
Save('plot-guid', guid)
end
plot(chart_id, name, value, draw, color_to_enum(color), style, deco)
DefineOutput(VoidType)
1 Comment
Sign in to leave a comment.
Nice utility script! But I'm not sure why you would need to take the color input as a StringType, when you could just use EnumType directly? Then you do not have to use color_to_enum function.
EDIT: AAHH, silly me! I understand why that function exists... ;)