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

R

RDMercer

Member
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:
T

Tweak155

New member
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);
 
R

RDMercer

Member
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:
T

Tweak155

New member
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?
 

Similar threads

Top