Help Needed. Script to calc cost of position will not run

RDMercer

Member
Plus
The below script will not work because I really don't know WTF I'm doing.:unsure: Thus, I've humbly come here seeking help...

So --- This is a simple script that originated with Mobius in TOS chatroom that places the "AddLabel" items into a box on a chart. I modified the script so now there is a calc that results in also providing the "Cost" of prior for an equity. (For some unfathomable dumb reason TOS doesn't think this value is an important data point so it is missing from the platform. It should be in the Monitor area but its MIA. Go figure.) I'd like to calc the percentage of this "Cost" value v Account Liquidity. In other words, what percentage of total liquidity & Day Trades does an individual holding represent. "Calc" is the current def label used for the calc and that term / lamel or anything else tried crashes the script. In a perfect world I'd also like to have these values available to add as columns to the Monitor area > Account Statement and Activity & Positions. The math is basic; the ability to make this calc behave is a dark mystery to yours truly. ANY and ALL help much appreciated and welcome. Thanks in advance.

PS_If I rem out the "Laid" lines the script runs fine.... but, like the greedy old fool that I am, I want more!

def GetAveragePrice = GetAveragePrice();
def GetOpenPL = GetOpenPL();
def GetQuantity = GetQuantity();
def Liquidity = GetNetLiq ();
def Cost = (GetQuantity * GetAveragePrice);
def Calc = (GetQuantity * PriceType.LAST)/Liquidity;
AddLabel(1, "AvgPrice = " + GetAveragePrice +
" Cost = " + Cost +
" OpenPL = " + GetOpenPL +
" Laid = " + Laid, Color.WHITE);
 
Last edited:
The below script will not work because I really don't know WTF I'm doing.:unsure: Thus, I've humbly come here seeking help...

So --- This is a simple script that originated with Mobius in TOS chatroom that places the "AddLabel" items into a box on a chart. I modified the script so now there is a calc that results in also providing the "Cost" of prior for an equity. (For some unfathomable dumb reason TOS doesn't think this value is an important data point so it is missing from the platform. It should be in the Monitor area but its MIA. Go figure.) I'd like to calc the percentage of this "Cost" value v Account Liquidity. In other words, what percentage of total liquidity & Day Trades does an individual holding represent. "Calc" is the current def label used for the calc and that term / lamel or anything else tried crashes the script. In a perfect world I'd also like to have these values available to add as columns to the Monitor area > Account Statement and Activity & Positions. The math is basic; the ability to make this calc behave is a dark mystery to yours truly. ANY and ALL help much appreciated and welcome. Thanks in advance.

PS_If I rem out the "Laid" lines the script runs fine.... but, like the greedy old fool that I am, I want more!

def GetAveragePrice = GetAveragePrice();
def GetOpenPL = GetOpenPL();
def GetQuantity = GetQuantity();
def Liquidity = GetNetLiq ();
def Cost = (GetQuantity * GetAveragePrice);
def Calc = (GetQuantity * PriceType.LAST)/Liquidity;
AddLabel(1, "AvgPrice = " + GetAveragePrice +
" Cost = " + Cost +
" OpenPL = " + GetOpenPL +
" Laid = " + Laid, Color.WHITE);

PriceType.LAST is a constant that tells ThinkScript which price you want from a fundamental. In this case, I think what you might be looking for is:

def Calc = (GetQuantity * close)/Liquidity;

Close should always be the current price on the most recent bar, as it will follow the price until it closes. However, close() will accept a price type if you want to modify it, I.E close(PriceType = priceType.LAST);
 
THANKS! "Cost" is a calc to obtain the total original outlay for a position. Against my better judgement and after hours of crash & burn, I was finally able to accidentally get the below script to place a label at the top of a chart. This imperfect script gives a snapshot of Avg price of an equity purchase, Account liquidity, Cost of initial trade, P&L for holding, Acct Buying Power, Equity's percentage of total liquidity. The percentage of total account position is what I was most interested in for portfolio management.

Now I need some help formatting output to place a percent sign (%) after the the PortPct value? It's always something...
This bad boy will not run on intraday charts. :eek:


#By Roy D McAvoy

declare upper;

def AvgPrice = round(GetAveragePrice(),2);
def PL = round(GetOpenPL(),0);
def Quantity = GetQuantity();
def Liq = round(GetNetLiq (),0);
def Cost = round(Quantity * AvgPrice,0);
def PctPort = round((Cost / Liq) * 100,1);
def SBP = round(GetTotalCash (),0);

AddLabel(1, "AvgPrice = " + AvgPrice +
" Liq = " + Liq +
" Cost = " + Cost +
" PL = " + PL +
" SBP = " + SBP +
" PortPct = " + PctPort, Color.WHITE);
 
Last edited:
THANKS! "Cost" is a calc to obtain the total original outlay for a position. Against my better judgement and after hours of crash & burn, I was finally able to accidentally get the below script to place a label at the top of a chart. This imperfect script gives a snapshot of Avg price of an equity purchase, Account liquidity, Cost of initial trade, P&L for holding, Acct Buying Power, Equity's percentage of total liquidity. The percentage of total account position is what I was most interested in for portfolio management.

Now I need some help formatting output to place a percent sign (%) after the the PortPct value? It's always something...
This bad boy will not run on intraday charts. :eek:


#By Roy D McAvoy

declare upper;

def AvgPrice = round(GetAveragePrice(),2);
def PL = round(GetOpenPL(),0);
def Quantity = GetQuantity();
def Liq = round(GetNetLiq (),0);
def Cost = round(Quantity * AvgPrice,0);
def PctPort = round((Cost / Liq) * 100,1);
def SBP = round(GetTotalCash (),0);

AddLabel(1, "AvgPrice = " + AvgPrice +
" Liq = " + Liq +
" Cost = " + Cost +
" PL = " + PL +
" SBP = " + SBP +
" PortPct = " + PctPort, Color.WHITE);

AddLabel(1, "AvgPrice = " + AvgPrice +
" Liq = " + Liq +
" Cost = " + Cost +
" PL = " + PL +
" SBP = " + SBP +
" PortPct = " + PctPort + "%", Color.WHITE);

Does that work?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
287 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top