RicardoSantos

Function 2 Point Line using UNIX TIMESTAMP V1

experimental:
draws a line from 2 vectors(price, time)
update:
reformatted the function,
added automatic detection of the period multiplier by approximation(gets a bit goofy with stocks/week time),
example using timestamp() function.

offsetting is still bugged, i cant find a way around it atm.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
study(title='Function 2 Point Line using UNIX TIMESTAMP V1', shorttitle='f', overlay=true)
offset = input(100)

_p0 = 4.92
_t0 = timestamp(2011, 12, 19, 0, 0)
_p1 = 6.72
_t1 = timestamp(2012, 05, 21, 0, 0)


f_2p_line(_price0, _time0, _price1, _time1, _shift) =>
    _period_multiplier = lowest(change(time), 10)
    _diference_in_price = (_price1 - _price0)
    _diference_in_time = (_time1 - _time0)
    _fraction = (_diference_in_price / _diference_in_time)
    _current_time_plus_offset = (time + (_shift*_period_multiplier))
    _return = _price0 + (_fraction * (_current_time_plus_offset - _time0))

plot(f_2p_line(_p0, _t0, _p1, _t1, offset), color=color(blue, 0), offset=offset)