Page 1 of 3

Daystart vertical line

PostPosted: Mon Dec 12, 2011 3:51 pm
by Nikolay.Gekht
The simple indicator which just draws a vertical line at the beginning of chose hour (17:00EST by default).

daystartline.PNG


Download:
daystartline.lua
(2.36 KiB) Downloaded 3351 times


Code: Select all
function Init()
    indicator:name("Day Start Line");
    indicator:description("The indicator draws a vertical line at the specified time");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Parameters");
    indicator.parameters:addInteger("hour", "Hour (EST)", "Hour at start of which the line must be drawn", 17, 0, 23);
    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clr", "Color", "", core.rgb(0, 127, 0));
    indicator.parameters:addInteger("width", "Width", "", 1, 1, 5);
    indicator.parameters:addInteger("style", "Style", "", core.LINE_DOT);
    indicator.parameters:setFlag("style", core.FLAG_LEVEL_STYLE);
end

local source;
local dummy, host;
local hour, clr, width, style;
local canwork, error;

function Prepare(onlyname)
    source = instance.source;
    clr = instance.parameters.clr;
    width = instance.parameters.width;
    style = instance.parameters.style;
    hour = instance.parameters.hour;
    host = core.host;

    local s, e = core.getcandle(source:barSize(), 0, host:execute("getTradingDayOffset"), 0);
    canwork = not(math.floor(e - s) >= 1);

    if not canwork then
        errtext = "The indicator must be applied on intraday charts";
        if onlyname then
            assert(false, errtext);
        else
            core.host:execute("setStatus", "error:" .. errtext);
        end
    end

    local name;
    name = profile:id() .. "(" .. source:name() .. "," .. hour .. ")";
    instance:name(name);

    if onlyname then
        return ;
    end


    dummy = instance:addStream("D", core.Line, name .. ".D", "D", clr, 0);
end

local last_s = nil;
local id = 0;

function Update(period, mode)
    if not canwork then
        return ;
    end

    -- calculation restarted
    if period == 0 then
        host:execute("removeAll");
        id = 0;
    end

    local s = source:serial(period);

    if last_s ~= nil and s == last_s then
        return ;
    end

    last_s = s;

    local date = source:date(period);
    local t = core.dateToTable(date);
    if t.min == 0 and t.hour == hour then
        id = id + 1;
        host:execute("drawLine", id, date, 0, date, 100000, clr, style, width, core.formatDate(host:execute("convertTime", core.TZ_EST, core.TZ_TS, date)));
    end
end

Re: Daystart vertical line

PostPosted: Mon Dec 12, 2011 4:53 pm
by mfoste1
as borat would say...."Very Nice!"

thanks nikolay

Re: Daystart vertical line

PostPosted: Mon Dec 12, 2011 5:23 pm
by nazaar
Brilliant, thank you!

Re: Daystart vertical line

PostPosted: Thu Dec 15, 2011 1:27 pm
by nazaar
thank you again for making this simple yet very useful tool.

Is it possible, on the daily chart, add the option to place a vertical line on the 1st of each month?

Re: Daystart vertical line

PostPosted: Mon Dec 19, 2011 9:46 am
by santanae
Love this Indicator thanks

I just started learning how to create (code) indicators and going through the docs and downloaded the tools to code.I wanted to ask you if there is away to create an indicator to just draw a horizontal line at exactly the close of each trading day (17:00 EST). I'm trying to work on something and I wanted to see if there was a way to do that.
Any assistance is apprecaited

Re: X bars back

PostPosted: Wed Jan 11, 2012 12:30 pm
by nazaar
Thanks again for the useful and very helpful indicator.

Taking the concept of this indicator I was wondering if you could create another indicator similar to it?

I am looking for an indicator that can count and indicate X bars back. For example, identify the 9th or 13th or 21st bar back. The identifying mark can be a vertical line running through the bar only (instead of a full vertical line) or an symbol place by above or below the X bar back.

thanks in advance.

Re: Daystart vertical line

PostPosted: Wed Jan 11, 2012 4:41 pm
by Apprentice
Your request has been added to the developmental cue.

Re: Daystart vertical line

PostPosted: Sat Jan 14, 2012 6:51 am
by Apprentice
Requested can be found here.
viewtopic.php?f=17&t=11079&p=23420#p23420

Re: WEEK START LINE - vertical line

PostPosted: Tue Feb 28, 2012 1:18 pm
by nazaar
Hello,

The daystarline time divider has served very well on the lower time line charts but it produces to many lines to frequently on the higher time lines.

could you please add a new time divider indicator similar to the daystartline?

Please add a week start line tool. The weekly start would be Sunday 17:00 or 18:00.

thanks in advance.

Re: Daystart vertical line

PostPosted: Wed Feb 29, 2012 5:14 am
by Apprentice
Your request is added to the development list.