Asked  2 Months ago    Answers:  5   Viewed   631 times

I would like to draw a vertical line, every day at a certain local time (e.g. 08:00 GMT+1).

Since my last post about vertical lines, pine-script has been updated to include vline(), however, the issue here is getting the time right. Most servers (for FX) seem to be US based and the Trading view local time settings (shown on bottom left) seem totally independent of what is done in pine-script.

//@version=4
study("Time Adjusted Vertical Line", overlay=true)

vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line, 54 lines maximum allowable per indicator
    return = line.new(BarIndex, -1000, BarIndex, 1000, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)

if(bar_index%10==0.0)
    vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required

I couldn't get the above to work, but I got this to at least show the lines:

//@version=4
study(title="Time Based Session Bars", shorttitle="NowOpen", overlay=true)
line_height = 2    // We must define a height that reaches far above the highest price level in main chart!

gmt_offs = 2 // GMT + X
nys_offs = 6 // EST (in GMT)

t1 = time(timeframe.period, "0930-0935:23456")
//t1 = time(timeframe.isintraday, "0930-0935:23456")
//t2 = t1 + gmt_offs*60*60*60
t2 = t1 + 2
plot(na(t2) ? 0 : line_height, title='Hello!', color=#101010, linewidth=1, style=plot.style_histogram, transp=50, offset=0, trackprice=false)

However, the lines are totally wrong:

enter image description here

How can I extend the above code, to plot a vertical line, every day at a certain time, and get the correct time placement?


Possibly Useful links:

  • Sessions and time functions (The official Documentation)

  • Sessions_and_time_functions (The Github Repo Docs)

  • Introducing Pine-script-4


UPDATE

Thanks to PineCoders-LucF, I was able to get approximately what I wanted, with the following code:

//@version=4
study("Line at time",overlay=true)

t1 = timestamp("GMT+2", year, month, dayofmonth, 07, 00, 00)
//t2 = timestamp("GMT+2", year, month, dayofmonth, 10, 00, 00)  // Uncomment this to make a range
t2=t1                                                           // Comment out this to use a range
bgcolor( (time >= t1) and (time <= t2) ? color.silver : na, transp = 0)

However, there are two issues wit this code.

  1. It doesn't use the nice timeframe.period functionality that allow you to specify certain days and time intervals in one place.
  2. It put the line in the "middle" of a candle so if you're on the 1H chart and want a line at 08.00 it will just place it in the middle. Thus not suitable as an alarm/signal, unless you use a <= 1 minute time frame.

 Answers

59

Version 1

One version of the timestamp() function can use a timezone parameter:

//@version=4
study("Line at time", overlay=true)
targetTime = timestamp("GMT+1", year, month, dayofmonth, 08, 00, 00)
bgcolor(targetTime == time ? color.silver : na, transp = 0)

// Debugging: these plots lines in separate window
plot(targetTime, "targetTime", color.orange)
plot(time, "time")

Chart is shown with UTC+1 times and indicator is set to "No Scale" not to disrupt price scale:

enter image description here

Version 2

With this version you can choose:

  • A from/to hour range
  • To show the line on weekdays only
  • Between bgcolor or vline mode
//@version=4
study("Line at time",overlay=true)
fromHour = input(7)
toHour = input(10)
weekdaysOnly = input(true)
useVline = input(false)
dayIsOk = not weekdaysOnly or (dayofweek != dayofweek.saturday and dayofweek != dayofweek.sunday)
t1 = timestamp("GMT+2", year, month, dayofmonth, fromHour, 00, 00)
t2 = timestamp("GMT+2", year, month, dayofmonth, toHour, 00, 00)
timeIsOk = (time >= t1) and (time <= t2)
bgcolor( not useVline and timeIsOk and dayIsOk ? color.orange : na, transp = 80)
if useVline and timeIsOk and dayIsOk
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, #FF8000ff, line.style_solid, 1)

enter image description here

Sunday, August 15, 2021
 
ritch
answered 2 Months ago
60

If anyone is interested in using the new v4 line.new() function:

Note: Adjust LineLengthMult as desired.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marketscripters

//@version=4
study("My Script", overlay=true)
LineLengthMult = 10
LineLength = atr(100) * LineLengthMult

drawVerticalLine(offset) =>
    line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(color.yellow, 50), width=3)

if bar_index % 21 == 0
    drawVerticalLine(0)

tradingview chart showing vertical lines by marketscripters.com

EDIT: Answer updated with code that auto-scales the vertical lines.

Saturday, July 31, 2021
 
Envin
answered 3 Months ago
51

Detailed description in the documentation

Help Center•Alerts•Alerts settings• How to use a variable value in alert

The ability to generate variable text in alerts is very limited. I couldn't output a string variable in the alerts. In the following snippet, a workaround is how to output a color type variable in an alert.

plot(ColorS == #FF8C00 ? 1 : -1, title="colorA", display=display.none)
alertcondition(cross(LagFF,LagFS) and ColorF==ColorS, title='LagF', message='LagF cross {{ticker}} {{interval}} Up/Down {{plot("colorA")}}' )

Leave a feature request with TradingView via their support ticketing system. I think it is possible to add a placeholder {{label}}.

[ADDED]

Now you can do it like this

if scr_label!=""
    alert("Screener Alert:"+scr_label, alert.freq_once_per_bar_close)
Saturday, July 31, 2021
 
Jesse
answered 3 Months ago
32

Here's a way to do it.
I've included 2 methods:

  • f_fill_array_all_tickers()
    • Looks cleaner
    • Might be slower.
  • f_fill_array_current_ticker_only()
    • Looks less clean
    • Might be faster, depending on how far down the list the ticker is.

The script has an input checkbox i_fill_array_all_tickers to let you choose between the 2 methods.

I'd personally go for f_fill_array_all_tickers() because of readability/maintainability.

//@version=4
study("Lines", "LI", true)

var bool        i_fill_array_all_tickers    = input(false, "Fill array with ALL tickers")

var string[]    a_ticker    = array.new_string()
var int[]       a_x1        = array.new_int()
var int[]       a_x2        = array.new_int()

var line        myLine      = line.new(na, na, na, na, extend=extend.both)

f_add(_ticker, _x1, _x2) =>
    if array.includes(a_ticker, _ticker)
        // update existing ticker
        idx = array.indexof(a_ticker, _ticker)
        array.set(a_x1, idx, _x1)
        array.set(a_x2, idx, _x2)
    else
        // insert new ticker
        array.push(a_ticker,    _ticker)
        array.push(a_x1,        _x1)
        array.push(a_x2,        _x2)


f_fill_array_all_tickers() =>
    //fill array with data for ALL tickers
    f_add("AAPL", 20, 6)
    f_add("MSFT", 20, 6)
    f_add("OPEN", 20, 6)
    f_add("SPY" , 20, 6)
    
f_fill_array_current_ticker_only() =>
    //fill array with data for only the CURRENT tickers
    if      syminfo.ticker == "AAPL" 
        f_add(syminfo.ticker, 20, 6)
    else if syminfo.ticker == "MSFT"
        f_add(syminfo.ticker, 20, 6)
    else if syminfo.ticker == "OPEN"
        f_add(syminfo.ticker, 20, 6)
    else if syminfo.ticker == "MSFT"
        f_add(syminfo.ticker, 20, 6)

f_fill_array() =>
    if i_fill_array_all_tickers
        f_fill_array_all_tickers()
    else
        f_fill_array_current_ticker_only()
        
if barstate.isfirst
    f_fill_array() 

if barstate.islast and array.includes(a_ticker, syminfo.ticker)
    idx = array.indexof(a_ticker, syminfo.ticker)
    x1  = array.get(a_x1, idx)
    x2  = array.get(a_x2, idx)
    line.set_xy1(myLine, bar_index - x1, high[x1])
    line.set_xy2(myLine, bar_index - x2, high)

Minimized code

//@version=4
study("Lines", "LI", true)

var a_ticker = array.new_string()
var a_x1 = array.new_int()
var a_x2 = array.new_int()
var myLine = line.new(na, na, na, na, extend=extend.both)

ai(a,v) => array.includes(a,v)
ax(a,v) => array.indexof(a,v)
as(a,i,v) => array.set(a,i,v)
ag(a,i) => array.get(a,i)
ap(a,v) => array.push(a,v)

f(t,a,b) =>
    if ai(a_ticker,t)
        i = ax(a_ticker,t),as(a_x1,i,a),as(a_x2,i,b) 
    else 
        ap(a_ticker,t),ap(a_x1,a),ap(a_x2,b)

a() => f("AAPL",20,6),f("MSFT",20,6),f("OPEN",20,6),f("SPY",20,6)
    
if barstate.isfirst
    a() 

if barstate.islast and ai(a_ticker, syminfo.ticker)
    idx = ax(a_ticker, syminfo.ticker)
    x1  = ag(a_x1, idx)
    x2  = ag(a_x2, idx)
    line.set_xy1(myLine, bar_index - x1, high[x1])
    line.set_xy2(myLine, bar_index - x2, high)

This seems to work, with 10 lines of 100 elements each

//@version=4
study("Lines", "LI", true)

var a_ticker = array.new_string()
var a_x1 = array.new_int()
var a_x2 = array.new_int()
var myLine = line.new(na, na, na, na, extend=extend.both)

ai(a,v) => array.includes(a,v)
ax(a,v) => array.indexof(a,v)
as(a,i,v) => array.set(a,i,v)
ag(a,i) => array.get(a,i)
ap(a,v) => array.push(a,v)

f(t,a,b) =>
    if ai(a_ticker,t)
        i = ax(a_ticker,t),as(a_x1,i,a),as(a_x2,i,b) 
    else 
        ap(a_ticker,t),ap(a_x1,a),ap(a_x2,b)

a() => 
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),
    f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6),f("AAPL",20,6)

if barstate.isfirst
    a()
    
if barstate.islast and ai(a_ticker, syminfo.ticker)
    idx = ax(a_ticker, syminfo.ticker)
    x1  = ag(a_x1, idx)
    x2  = ag(a_x2, idx)
    line.set_xy1(myLine, bar_index - x1, high[x1])
    line.set_xy2(myLine, bar_index - x2, high)

Little improvement.
When calling a() on the last bar instead of barstate.isfirst, the runtime doesn't have to keep the arrays in memory on all the historical bars.

if barstate.islast
    a()
    if ai(a_ticker, syminfo.ticker)
        idx = ax(a_ticker, syminfo.ticker)
        x1  = ag(a_x1, idx)
        x2  = ag(a_x2, idx)
        line.set_xy1(myLine, bar_index - x1, high[x1])
        line.set_xy2(myLine, bar_index - x2, high)
Thursday, September 2, 2021
 
zhartaunik
answered 2 Months ago
67

You have to find out the math behind that figures. The triangle and the star are quite easy to draw. Here is how you can draw a heart: http://www.mathematische-basteleien.de/heart.htm

To draw special paths you should create them by adding points, ellipses etc. The canvas supports a clipping mask of a specified path, so you can set the clipping mask of a heart, push the paths to the matrix, draw the content of the heart, and then pop it again.

That's what I'm doing to achieve a simulated 2D page curl effect on andriod: http://code.google.com/p/android-page-curl/

Hope this helps!

Sunday, September 5, 2021
 
Xavi
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :