# Profit Target Based on Slope of EMA

#### a1cturner

##### Well-known member
I am trying to plot a price target based on the slope of the 50EMA from 11:30 CST until 15:30 CST.

I have the formula for the slope but I can’t figure out for the life of me how to get the average price of the 10 minute bar at 11:30 CST so I can multiply it by (slope/360).

I have tried:
if barnumber(18) then (open+close)/2
if secondsfromtime(930) between 10200 and 10800 then (open+close)/2

I already have a properly configured label for slope

I have created a label and know I can calculate the current bar ((open+close)/2) * (slope/360)

I just can’t figure out how to define that specific bars average price and plot the price target from 11:30 CST until 15:30 CST.

Obviously if I can get the avg price * (slope/360) I would need to multiply that by the remaining number of bars left in the day and then add that to my avg price to get my target price.

My current attempts have resulted in no plot and N/A on my label if I use double.nan in my definitions or a plot at 0 and 0 on my label if I use 0 in my definitions.

Hope this is clear enough.

Solution
I am trying to plot a price target based on the slope of the 50EMA from 11:30 CST until 15:30 CST.

I have the formula for the slope but I can’t figure out for the life of me how to get the average price of the 10 minute bar at 11:30 CST so I can multiply it by (slope/360).

I have tried:
if barnumber(18) then (open+close)/2
if secondsfromtime(930) between 10200 and 10800 then (open+close)/2

I already have a properly configured label for slope

I have created a label and know I can calculate the current bar ((open+close)/2) * (slope/360)

I just can’t figure out how to define that specific bars average price and plot the price target from 11:30 CST until 15:30 CST.

Obviously if I can get the avg price * (slope/360) I would need to...
I am trying to plot a price target based on the slope of the 50EMA from 11:30 CST until 15:30 CST.

I have the formula for the slope but I can’t figure out for the life of me how to get the average price of the 10 minute bar at 11:30 CST so I can multiply it by (slope/360).

I have tried:
if barnumber(18) then (open+close)/2
if secondsfromtime(930) between 10200 and 10800 then (open+close)/2

I already have a properly configured label for slope

I have created a label and know I can calculate the current bar ((open+close)/2) * (slope/360)

I just can’t figure out how to define that specific bars average price and plot the price target from 11:30 CST until 15:30 CST.

Obviously if I can get the avg price * (slope/360) I would need to multiply that by the remaining number of bars left in the day and then add that to my avg price to get my target price.

My current attempts have resulted in no plot and N/A on my label if I use double.nan in my definitions or a plot at 0 and 0 on my label if I use 0 in my definitions.

Hope this is clear enough.

sorry, no , it is not clear.

i think this might be similar to what you want. guessing you want a line only on the current day.

-------

I'm going to type a lot of words here. some of them are just meant to help people to think about what they are trying to explain. my only goal is to help people communicate effectively.
Sometimes when you have an idea in your head, the words don't come out right. some things that can help to communicate an idea, reread it, look it over, sketch something out, have someone else read it.

--------
you say you have several pieces of data, but you don't list them, so we are left wondering.

-------
1.
trying to plot a price target based on the slope of the 50EMA from 11:30 CST until 15:30 CST.

do you mean ,
find 2 price values from an ema,
then draw a straight line through them,
and extend it to the last candle of the day?
-------------
2.
I have the formula for the slope but I can’t figure out for the life of me how to get the average price of the 10 minute bar at 11:30 CST so I can multiply it by (slope/360).

if you have the slope formula, then post it. then we will know if you are right.

why would you multiply it by (slope/360).? why /360?
why tell us what you're going to do, without telling us why.

i'm guessing you are trying to convert to angles. but why?
Tos can't draw vectors, a point and an angle. It draws lines between 2 price levels.
To draw straight line, you would figure out what change in price is needed, and then add that to the previous level, bar after bar.

this has an example that calcs an angle.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/ATan
----------
3.
if barnumber(18) then (open+close)/2
if secondsfromtime(930) between 10200 and 10800 then (open+close)/2

I would suggest using the function called between, instead of the word.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Between

the following codes are untested

def x = if barnumber() == 18 then (open+close)/2 else x;

you know the time you want to read data, why not try to use it.
midbodyval() is equal to (open+close)/2

def starttime = if secondsfromtime(1130) == 0 then midbodyval() else starttime;

def endtime = if secondsfromtime(1530) == 0 then midbodyval() else endtime;

Now you have the price levels for the start time and the end time, so you can calculate the difference in price, after the end time.

def periodpricediff = if secondsfromtime(1130) == 0 then endtime - starttime else periodpricediff;

count how many bars are in the period.

def barqty = if secondsfromtime(1130) == 0 then 1 else if secondsfromtime(1130) > 0 and
secondstilltime(1530) <= 0 then barqty + 1 else barqty;

then divide by the quantity of bars in the Period between start and end, to get the average price gain per bar, the slope.

def slopeprice = periodpricediff / barqty;

def na = double.nan;
def ema50= ...
def line1 = if secondsfromtime(1530) == 0 then ema50 else if secondsfromtime(1530) > 0 then line1 + slopeprice else na;
plot z = line1;

option
keep starting price in a var and add some price factor.
come up with some multiplayer as you go along to get the correct price change.. You can count the bars after the end time and multiply it by the price difference.

barsafter = if secondsfromtime(1530) == 0 then 0 else barsafter + 1;

-------------
4.
I already have a properly configured label for slope

why mention something, but not show it.
-------
5.
Obviously if I can get the avg price * (slope/360)

you keep mentioning this slope/360?
where did it come from. it isn't obvious.
I think you are trying to make it too complicated by calculating an angle and using that to somehow to draw a line.

every time someone says, simply or obviously, it isn't. If you find yourself using these words, reread your last few sentences and see if you can expand on them.

-----------------

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MidBodyVal

4 examples, draw lines in expansion area

-------
I typed this out on my phone, so I hope I don't have too many types

• MerryDay
This is what ended up working.

Code:
``````#PRICE TARGET
def AvgPrice = (open+close)/2;
def TgtTimeAvgPrice = if secondsfromtime(1230) == 0 then AvgPrice else TgtTimeAvgPrice;
def TgtTimeSlope = if secondsfromtime(1230) == 0 then SlopeDeg else TgtTimeSlope;
def PriceIncrease = TgtTimeAvgPrice * (TgtTimeSlope/360);
def PriceTarget = TgtTimeAvgPrice + PriceIncrease;
plot PriceTargetLine = if secondsfromtime(1230) > 0 and secondstilltime(1630) > 0 then PriceTarget else double.nan;
PriceTargetLine.SetStyle(curve.Short_Dash);
PriceTargetLine.SetDefaultColor(color.red);``````

This is my code for slope.

Code:
``````#EMA SLOPE
input SlopeThrHld = 4;
input ShowSlopeBubble = no;
def Height = EMASlow2 - EMASlow2;
def SlopeDeg = Round((ATan(height/10) * 180 / Double.Pi), 0);``````

And my code for Arc Length (trying to use this to determine if I think the stock will run all day vs. pop and flatten out

Code:
``````#EMA ARC LENGTH
def ArcLength = SlopeDeg * (Double.Pi/180) * (Height/2);``````

Now to respond to some of your points.

1. do you mean ,find 2 price values from an ema, then draw a straight line through them, and extend it to the last candle of the day?

No. I should have been more clear and explain that I already had a value for the slope and was trying to predict what the price would be at the end of the day using the average price at 11:30 along with the previous 10 bars slope at 11:30.

2. I posted the slope formula above. I divided by 360 because my slope is in degrees and I am trying to basically convert it to a percentage in order to calculate the possible price increase. (I am sure there are easier ways, but this is what I wanted to do because of how my larger study is being built and coming together)

3. Your suggestions definitely got me going in a better direction and cleared up some of my confusion.

4. and 5. Slope degree is posted in the second code above and I believe I also answered how I am using it in number 2.

Sorry for any confusion. I was also on my phone but sometimes need to get my thoughts on paper and out there before I completely forget what I am trying to do.

The red dashed line is what I was trying to plot and here is one example of it working properly. This is just another tool in the tool box. I personally am just using it to "guess" the close price so I don't overbuy on my calls or puts. Thanks for your help as always

• halcyonguy

### Not the exact question you're looking for?

87k+ Posts
186 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?