• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

GetAveragePrice() Horizontal line not being displayed correctly

RoachStock

New member
Folks,

I have an interesting situation regarding the Horizontal line and am hoping that maybe one of you guys know why this is happening to me.

I've been doing some basic testing with the following codes which the horizontal line was displayed correctly as straight line from left to right on my chart when I set my plBuy to a hard value such as 791.5533 which is the buy price of TSLA that I bought. The plBuy line is displayed as red horizontal line.

I also have a second line which is green and represents 10% profit line as represented by pl1.

I used AddLabel to display my plBuy value which showed up correctly.

Code:
plot plBuy;
plBuy = 791.5533;
#plBuy = GetAveragePrice();

plot pl1;

plBuy.SetDefaultColor(Color.RED);
plBuy.SetLineWeight(3);

pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);

# pl1 is Price Level 10%
pl1 = plBuy * 1.10;

vPRdJlP.jpg


Now here is my interesting situation. I changed my plBuy to equals the GetAveragePrice() on 3rd line instead of using plBuy = 791.5533, both my plBuy and pl1 lines are not straight lines but look like this:

9CD5MvS.jpg


Please note that my plBuy was showing same value of 791.5533 as evidenced in the yellow label in top-left corner (see the AddLabel statement).

Any help or explanation you can provide would be greatly appreciated!
 

rad14733

Well-known member
VIP
Well, what you are asking for isn't a "horizontal line" then is it...??? Horizontal lines are just that, horizontal, and vertical lines are just that, vertical... You want a line between price points...
 

RoachStock

New member
@rad14733 No sir, I'm only wanting a pure horizontal line for each level (Buy price, 10%, 20%, etc). I only changed the plBuy and this is what I got. I just found something interesting after scrolling through my held positions on my current chart with my above study displayed. I found that some stocks, it showed as perfect horizontal lines like the first picture but for some other stocks, it get shown as above 2nd picture. It's really strange.
 

XeoNoX

Well-known member
VIP
I'd venture to say it has something to do with the day you bought it, its showing avg as 0 because that day you had 0 next day you had xyz amount.
 

RoachStock

New member
I'd venture to say it has something to do with the day you bought it, its showing avg as 0 because that day you had 0 next day you had xyz amount.
That was my first suspect, that it might have to do with my trades which matched the dates for TSLA. I think it is actually useful info because the way I see this, I see two information. One is the Buy Price, 10%, 20%, etc AND the trades that were made which sort of give me historical info to show my progresses/failures. Thank you very much for your valuable feedback and I want to thank rad14733 as well!
 

XeoNoX

Well-known member
VIP
@RoachStock Here goes the code to make the line straight regardless of the day you entered, this will draw a plot for a straight horizontal line at the average price you entered.

Code:
def plBuy = GetAveragePrice();
def plStraightLine = highestall(plBuy);

plot x=plStraightLine;
x.SetDefaultColor(Color.RED);
x.SetLineWeight(3);

# pl1 is Price Level 10%
plot pl1 = x * 1.10;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);
 

Similar threads

Top