GetAveragePrice() Horizontal Line For ThinkOrSwim

RoachStock

New member
Folks,
Looking for GetAveragePrice() horizontal line
Any help you can provide would be greatly appreciated!
 
Last edited by a moderator:
Solution
@RoachStock Here goes the code to make the line straight regardless of the day you entered, this will draw a plot for a straight horizontal line at the average price you entered.

Code:
def plBuy = GetAveragePrice();
def plStraightLine = highestall(plBuy);

plot x=plStraightLine;
x.SetDefaultColor(Color.RED);
x.SetLineWeight(3);

# pl1 is Price Level 10%
plot pl1 = x * 1.10;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);
@RoachStock Here goes the code to make the line straight regardless of the day you entered, this will draw a plot for a straight horizontal line at the average price you entered.

Code:
def plBuy = GetAveragePrice();
def plStraightLine = highestall(plBuy);

plot x=plStraightLine;
x.SetDefaultColor(Color.RED);
x.SetLineWeight(3);

# pl1 is Price Level 10%
plot pl1 = x * 1.10;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);
 
Solution
is there any indicator or anyway in TOS that when i purchase an option contract at lets say 0.50 (stock is at $100) that it can place a mark on the main chart showing me where i entered and possible sl or is that asking too much of this software
 
Code:
#Example of Average Entry Price with stops

 # Plotting Average Actual Entry with ATR stops

# Mobius

# 01.01.2018

input AtrMultiplier = 2.00;

input Atr_Length = 5;

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 ATR = Average(TrueRange(high, close, low), Atr_Length) * AtrMultiplier;

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());

plot stop;

     stop.SetLineWeight(2);

     stop.SetdefaultColor(color.red);

switch (Dir)

{

case long:

    stop = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0

           then highestAll(if isNaN(close[-1])

                           then Entry - ATR

                           else double.nan)

           else double.nan;;

case short:

    stop = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0

           then highestAll(if isNaN(close[-1])

                           then Entry + ATR

                           else double.nan)

           else double.nan;;

}



plot tgt;

     tgt.SetLineWeight(2);

     tgt.SetdefaultColor(color.green);

switch (Dir)

{

case long:

    tgt = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0

           then highestAll(if isNaN(close[-1])

                           then Entry + ATR

                           else double.nan)

           else double.nan;;

case short:

    tgt = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0

           then highestAll(if isNaN(close[-1])

                           then Entry - ATR

                           else double.nan)

           else double.nan;;

}

# End Code
 
Last edited by a moderator:
Or, if you have Chart Settings > General >Show Trades checked then your chart will show all active orders for that symbol...

However, both this method and the one provided by @Mark1126 can only display trades for the actual symbol, not an Option trade on an underlying Stocks chart... TOS does not have such a feature...

I use a trading Chart Grid, which I have posted images of several times, that has the underlying Stock chart on the left and the Option chart above Active Trader on the right... This gets around the problem and gives me a good overall feel for the trade...
 
Last edited by a moderator:
GetAveragePrice Horizontal Line
Hello,

Is it possible to have a line on the chart that shows your current average price in a position in a trade? Kinda like this horizontal line, but it appears after you take a position and updates every time your avg price per share changes (if you buy/sell more shares).

Code:
# Dynamic Line
# zzz
# 11.18.2015

# Plots a horizontal line beginning on the closing value x number of bars ago
# Set Detrend to the number of bars ago you want to begin drawing the line
# Add code to plot a continuous price line into the right expansion area by
# the specified number of bars
#
# This version is actually simpler and works better than the previous version
# as it would not work if you chose detrend (unlikely choice). If "linefrom"
# is a negative number, it will plot back into the chart bars; if you use a
# positive number, it will plot only in the expansion area.

input linefrom = -60;#Hint linefrom: negative numbers plot in candle area, positive in expansion
input lineto  = 60;#Hint lineto: limits how far into expansion the line will plot
input detrend = 0;#Hint detrend: usually zero. if you want a prior period, then enter a positive number
input price = close;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
              then BarNumber()
              else lastbar[1];

def c = HighestAll(if IsNaN(close[-1]) and !IsNaN(close)
                   then price[detrend]
                   else Double.NaN);

plot Data = if BarNumber() >= highestall(lastbar + linefrom) and
               BarNumber() <= highestall(lastbar + lineto)
            then c
            else Double.NaN;

# End Study

I don't want the horizontal line to show what it is showing now, I just need it to draw the horizontal line for GetAveragePrice(); but I am not sure what to remove and where to add GetAveragePrice();

I have also tried this, but still, no line is being drawn for the average price. Is that weird?
Code:
plot plBuy;
#plBuy = 791.5533;
plBuy = GetAveragePrice();

plBuy.SetDefaultColor(Color.RED);
plBuy.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);

Any help would be greatly appreciated!
 
Last edited by a moderator:
GetAveragePrice Horizontal Line
Hello,

Is it possible to have a line on the chart that shows your current average price in a position in a trade? Kinda like this horizontal line, but it appears after you take a position and updates every time your avg price per share changes (if you buy/sell more shares).

Code:
# Dynamic Line
# zzz
# 11.18.2015

# Plots a horizontal line beginning on the closing value x number of bars ago
# Set Detrend to the number of bars ago you want to begin drawing the line
# Add code to plot a continuous price line into the right expansion area by
# the specified number of bars
#
# This version is actually simpler and works better than the previous version
# as it would not work if you chose detrend (unlikely choice). If "linefrom"
# is a negative number, it will plot back into the chart bars; if you use a
# positive number, it will plot only in the expansion area.

input linefrom = -60;#Hint linefrom: negative numbers plot in candle area, positive in expansion
input lineto  = 60;#Hint lineto: limits how far into expansion the line will plot
input detrend = 0;#Hint detrend: usually zero. if you want a prior period, then enter a positive number
input price = close;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
              then BarNumber()
              else lastbar[1];

def c = HighestAll(if IsNaN(close[-1]) and !IsNaN(close)
                   then price[detrend]
                   else Double.NaN);

plot Data = if BarNumber() >= highestall(lastbar + linefrom) and
               BarNumber() <= highestall(lastbar + lineto)
            then c
            else Double.NaN;

# End Study

I don't want the horizontal line to show what it is showing now, I just need it to draw the horizontal line for GetAveragePrice(); but I am not sure what to remove and where to add GetAveragePrice();

I have also tried this, but still, no line is being drawn for the average price. Is that weird?
Code:
plot plBuy;
#plBuy = 791.5533;
plBuy = GetAveragePrice();

plBuy.SetDefaultColor(Color.RED);
plBuy.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);

Any help would be greatly appreciated!

Did you ever figure out a way to do this??? I would like the horizontal price level to show my current average position and extend forever to the right. Appear upon entry. Disappear upon exiting the position.

Any help here would be greatly appreciated!

Thanks!

I've found a few other posts that shared script code for similar things, but I'm wanting a horizontal price level to show my current average position and extend forever to the right. Appear upon entry. Adjust to my average as I add to my position. Disappear upon exiting the position.

Any help here would be extremely appreciated! Thanks!!
 
Last edited:
@RoachStock Here goes the code to make the line straight regardless of the day you entered, this will draw a plot for a straight horizontal line at the average price you entered.

Code:
def plBuy = GetAveragePrice();
def plStraightLine = highestall(plBuy);

plot x=plStraightLine;
x.SetDefaultColor(Color.RED);
x.SetLineWeight(3);

# pl1 is Price Level 10%
plot pl1 = x * 1.10;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);
It plots and shows on my Daily time frame chart, but doesn't show on my weekly or monthly chart. Is this something that can be adjusted to work on a weekly or monthly, or does the GetAveragePrice() not work on those chart periods?

UPDATED: found my answer
You can't display it. According to the Release Note July 9 2016:
"As of now, the data is available for non-custom time based charts that have an aggregation of Daily or less"
 
Last edited by a moderator:

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
374 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