This ONLY WORKS for showing purchase price if the purchase happened on the chart somewhere, i.e. in the last 5 days if the chart shows 5 days of data.
I can't seem to find position size automatically. You'll need to adjust the input of your position size to match your position (unless you have something entirely other in mind. But give this a try.
IT REQUIRES YOU TO SET THE SIZE
IT REQUIRES THE PURCHASE TO BE ON THE CURRENT CHART
AND IT DOESN"T PLOT THE PAID PRICE EXACTLY
I offer it as a starting point ONLY
I suppose you could always set your expected position size
before you enter, so that it'll graph immediately.
Code:
declare upper;
# ThinkOrSwim Mobile Style Position Price Indicator
# For Desktop
# Mashume
# 2020-02-28
declare upper;
input size = 100;
def liq = positionNetLiq();
def position = liq / size;
def enter = if position != 0 then
if position[1] == 0 then position
else enter[1]
else double.nan ;
plot entryPrice = enter;
It only works for securities for which the actual purchase candle appears on the chart.
Additionally, I can't get it to give me a proper calculation for the size of a position given the price when the position was opened. That is, I can get a number, round it, and it displays, graphs, etc.. properly, but I can't use it as a divisor without breaking the position calculation.
THIS DOESN"T WORK. Any ideas?
Code:
def s = if !isnan(liq) then round(liq / ((OPEN + CLOSE) / 2), numberOfDigits = 0) else double.nan;
def position = positionNetLiq() / s;
Happy Trading
Mashume