Days In Trade Custom Column

W

walksonair

New member
Hello, I haven't been able to find a solution so hoping someone could help me out or point me in the right direction.

I have both stocks and options that I monitor and would like a column that shows how many days I have been in that position. Meaning: the column should show 0 if the position was opened today and increment subsequently until closed (when closed it will be removed from my monitor page or watchlist). It can show "-1" or something else to show no position.

Thanks in advance for your help!
 
BenTen

BenTen

Administrative
Staff
VIP
At this time, I don’t think there is a way to incorporate current opening positions into a watchlist column.
 
W

walksonair

New member
Thanks, that was what all my research was telling me.
How’s about a chart label?
 
T

tomsk

Well-known member
VIP
@walksonair Unfortunately ThinkScript has no access to your trade data. However there is a workaround.
Here is a real quick way to display the number of trading days you are in a position.
This is done by calculating the number of bar numbers since the inception of your position
Then subtract that from the current bar number and you'll get the number of trading days.
Make sure you run this on a daily chart because you'd want the number of days, otherwise no info is displayed

Here is an example. Assume you purchase AAPL on 20191007. You can change that date in the user interface
Run this study and convince yourself

Code:
# Days in Trade
# tomsk
# 11.24.2019

declare hide_on_intraday;

input acquiredDate = 20191007;

def bar = barNumber();
def pos = if getYYYYMMDD() == acquiredDate then bar else Double.NaN;
addlabel(1, "Position Initiated on " + AsPrice(acquiredDate) + "  =  " + (bar - HighestAll(pos) + " Days in Trade"), Color.PINK);
# End Days in Trade
 
Last edited:

Similar threads

Top