no such function getaverageprice no such function getquantity
def cost = GetAveragePrice();
def qty = GetQuantity();
def purchase = qty * cost ;
def present = qty * close ;
plot gainloss = present - purchase ;
gainloss.Hide();
def GLpct = Round(gainloss / purchase, 3) ;
AddLabel(yes, "gain " + gainloss + " " + AsPercent(GLpct), if gainloss > 0 then Color.GREEN else Color.RED );
# Plotting Average Actual Entry
# Mobius
# 01.01.2018
input HardStop = 3.00;
input Dir = {default long, short};
plot hide = double.nan;
hide.setDefaultColor(Color.Black);
def c = if isNaN(close[-1]) then close else c[1];
def Entry = if isNaN(GetAveragePrice())
then Entry[1]
else GetAveragePrice();
def LastEntryBar = if Entry != Entry[1]
then barNumber()
else LastEntryBar[1];
plot Entry_ = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1])
then Entry
else double.nan)
else double.nan;
Entry_.SetStyle(Curve.Long_Dash);
Entry_.SetLineWeight(3);
Entry_.SetDefaultColor(CreateColor(255,215,0));
Entry_.HideBubble();
Entry_.HideTitle();
def PL = if Entry > 0 then Entry - c else 0;
AddChartBubble(barNumber() == HighestAll(barNumber()), Entry_, "AVG " +AsDollars(Entry), Entry_.TakeValueColor());
#Alert(c crosses below Entry, "", Alert.Bar, Sound.Chimes);
#Alert(c crosses above Entry, "", Alert.Bar, Sound.Ring);
plot stop;
switch (Dir)
{
case long:
stop = Entry_ - HardStop;
case short:
stop = Entry_ + HardStop;
}
#Alert(close crosses stop, "STOP", Alert.Bar, Sound.Bell);
# End Code
# Average Actual Entry
# Mobius
# 01.01.2018
# Removed portions of Mobius' code, added quantity and replaced Mobius' P/L
# calculation with GetOpenPL().
# Color-coded label, edited study look/colors for personal preference
def PL = GetOpenPL();
def c = if isNaN(close[-1]) then close else c[1];
def Entry = if isNaN(GetAveragePrice()) then Entry[1] else GetAveragePrice();
def LastEntryBar = if Entry != Entry[1] then barNumber() else LastEntryBar[1];
plot Entry_ = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1]) then Entry else double.nan) else double.nan;
Entry_.SetStyle(Curve.SHORT_DASH);
Entry_.SetLineWeight(3);
Entry_.SetDefaultColor(color.BLUE);
Entry_.HideBubble();
Entry_.HideTitle();
AddLabel(1, "Qty: " + GetQuantity() +
" Avg Cost $" + Entry +
" P/L: " + AsDollars(PL),
if PL == 0 then color.cyan
else if PL > 0 then color.green
else color.red);
# end code
Ha! I also figured this out a couple days ago (I think I turned it on the day I posted my reply), but forgot to update this chain. It also fixes "Show Trades" and my mobile alerts. Been a life saver. Google should have this answer more readily!I had the same problem, getAveragePrice was always "N/A". I contacted support via live chat and they immediately pointed me to the "Advanced Features" setting which needs to be enabled: Ameritrade.com > Client Services > My Profile > General > Advanced Features
It took a few hours to kick in, but now I get the correct values from the Portfolio functions.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Short/Long Entry Line on Chart for ThinkorSwim | Indicators | 3 | ||
Bullish Market Entry Point for ThinkorSwim | Indicators | 36 | ||
N | Entries and Target For ThinkOrSwim | Indicators | 8 | |
Darvas Box with Target Levels for ThinkorSwim (Scalping Strategy) | Indicators | 19 | ||
Take Profit Indicator for ThinkorSwim | Indicators | 1 |
Start a new thread and receive assistance from our community.
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.
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.