TradingView
ImmortalFreedom
15 ספט׳ 2019 22:00

vline() Function for Pine Script v4.0+ 

American Eagle Outfitters, Inc.NYSE

תיאור

It's been a long time coming, but here is a versatile vline() function applicable to PSv4.0+ utilizing line.new(). I decided to finally figure this out at the request of another member recently. I have been waiting myself for months, but it's now time for an idea who's time has come to unleash upon planet Pine Script. It's a handy little function I believe will be very useful in the future. It only requires 4 parameters of BarIndex, Color, LineStyle, and LineWidth. Make sure you place it in an appropriate if() block to use it properly. As displayed above, this plots every 10 bars using a conditional statement employing the rarely used modulus operator.

Use it as you please, this is free code to implement into your new Pine projects. I don't require an credit for any one to use this function. I simply don't want any credit. I would however like to see some great ideas utilizing this when I randomly and accidentally come across them in the public library. I didn't know where to put this script, so I just tossed into the "Trend Analysis" category. I'm pondering we members need a "Miscellaneous" category some time in the future.

The comments section below is solely just for commenting and other remarks, ideas, compliments, etc... regarding only this indicator, not others. If you do have any questions or comments regarding this indicator, I will consider your inquiries, thoughts, and concepts presented below in the comments section, when time provides it. When my indicators achieve more prevalent use by TV members, I will implement more ideas when they present themselves as worthy additions. As always, "Like" it if you simply just like it with a proper thumbs up, and also return to my scripts list occasionally for additional postings. Have a profitable future everyone!

הערות שחרור

Provided recommended function permutations that might be suitable for study(overlay=true) and study(overlay=false) scenarios. In some situations with the original script release, auto-scaling was affected by line.new() with unintended expectations.
תגובות
Mayfair_Ventures
How could you start this from a specific day or date?
ahmedsindi
hello , how can i plot a single vertical line on chart for specific year , month , day determined by input function ?
ahmedsindi
@ahmedsindi, i mean how to input date like ( 24/3/2020) to make vertical line at that specific date ?
jasonjc
@ahmedsindi, try this
vline(TimeIndex, Color, LineStyle) =>
return = line.new(TimeIndex, low, TimeIndex, high, xloc.bar_time, extend.both, Color, LineStyle)
vline(timestamp(2020,3,24), #ff0000, line.style_solid)
MaxTse
@jasonjc, how I try to copy and paste this code directly . but It is not work.. could you show me how to make a vertical line at a specific date.
jasonjc
@MaxTse, try this one

//@version=4
study(title="test01", shorttitle="test01", overlay=true)

vline(TimeIndex, Color, LineStyle) =>
return = line.new(TimeIndex, low, TimeIndex, high, xloc.bar_time, extend.both, Color, LineStyle)
vline(timestamp(2021,11,2), #ff0000, line.style_solid)

1. version should be 4, not 5
2. add one "tab" before return

anyway copy and paste this code to pine editor, save, then you should be able to see one red vertical line on 2021/11/2

cheers
jasonjc
I notice the "tab" before return have been removed when I post the comment, please add it manually.
MaxTse
@jasonjc, thank you very much.
radha4336
@jasonjc, This is fantastic sir. Thank you very much for this code. It saves me a lot of time.

I need to mark lines at particular intervals. For example, The start date is 2022 Dec 25 & need to mark the dates which are 15 days, 28days, 37days, 46days and so on. I need to draw lines forward backward from the start date. Is this possible sir? Kindly help in this regard...
yikloong
Hi, how to modify to change for weekly interval start day of the week?
עוד