Def Curve of 34/50 EMA Cloud

a1cturner

Well-known member
I noticed something today when looking at my flexible grid. I noticed that the curve of the 34/50 EMA cloud looked very similar on all stocks that trended up all day vs. a spike in the morning and flatten out. I would love to add this to my study as another possible confirmation of entry. Does anyone know how I could define the curve so I could tweak it to my liking?

For reference, the blue line on the bottom cloud is the 34 EMA and the yellow line on the bottom cloud is the 50 EMA. Pink markings are what I am looking for vs. Red markings.

QwJv109.png


This is what I tried so far but it doesn't really capture what I am looking for.

Code:
#def EMASlow1Prior = EMASlow1;
#def EMASlow2Now = EMASlow2;
#def EMAMoMo = EMASlow2Now crosses above EMASlow1Prior[5];
#AddChartBubble(EMABull and EMAMoMo, low, "Call", color.dark_green, no);

I tried EMASlow1Prior [10], EMASlow1Prior [20], EMASlow1Prior [30], EMASlow1Prior [50], and EMASlow1Prior [5].

This is the code I am currently working on: https://usethinkscript.com/threads/where-have-i-gone-wrong-sell-bar-not-displaying-properly.10596/

Obviously no-one knows how the curve will turn out but I would say if it's forming between 9:30-11:30 CST it's probably a good signal.

I am no geometry wiz (or math or coding wiz) but maybe something that would calculate the curve angle and the signal could be adjusted from the study inputs and options window to meet user preferences?!

I would also want something that works on downtrending stocks as well.

Am I over my head?
 
Solution
I noticed something today when looking at my flexible grid. I noticed that the curve of the 34/50 EMA cloud looked very similar on all stocks that trended up all day vs. a spike in the morning and flatten out. I would love to add this to my study as another possible confirmation of entry. Does anyone know how I could define the curve so I could tweak it to my liking?

this may be of use?
this draws a smoothed curved line, not an arc, on tomorrows bar space.

it is a double ema of the current days prices, with a length of 23 for both.
it plots the line on tomorrows bar space, so it isn't covering up any bars.
at first i drew the curve below the bars of today. but sometimes it would overlap the bars. i left that code in.

the...
I noticed something today when looking at my flexible grid. I noticed that the curve of the 34/50 EMA cloud looked very similar on all stocks that trended up all day vs. a spike in the morning and flatten out. I would love to add this to my study as another possible confirmation of entry. Does anyone know how I could define the curve so I could tweak it to my liking?

this may be of use?
this draws a smoothed curved line, not an arc, on tomorrows bar space.

it is a double ema of the current days prices, with a length of 23 for both.
it plots the line on tomorrows bar space, so it isn't covering up any bars.
at first i drew the curve below the bars of today. but sometimes it would overlap the bars. i left that code in.

the default is using a reference line that is a horizontal line, halfway between the days open and days close.
can change the reference line to be a diagonal line, from day open to day close.

this was done after hours, so not sure how it will look during the day, as the bars appear.


Ruby:
# curve_fit_day_emas_00e

# https://usethinkscript.com/threads/def-curve-of-34-50-ema-cloud.10652/

def na = double.nan;
def bn = barnumber();

# ---------------------------------

# chart agg , min .  bars in a day
input chart_stat_labels = no;
def chartagg = GetAggregationPeriod();
def chartmin = (chartagg / 1000) / 60;
AddLabel(chart_stat_labels, "chartmin " + chartmin, Color.MAGENTA);
# 390min in a day
def daybarqty = roundup(390 / chartmin, 0);
AddLabel(chart_stat_labels, "bars per day " + daybarqty, Color.MAGENTA);

#---------------------------------

# day count
def istoday = if GetLastDay() == GetDay() then 1 else 0;

def newday = if getday() != getday()[1] then 1 else 0;
def daycnt = if bn == 1 then 1 else if (!isnan(close) and newday) then daycnt[1] + 1 else daycnt[1];
#def maxdays = highestall(daycnt);
#def revdaycnt = maxdays - daycnt + 1;

def daybarcnt = if bn == 1 or newday then 1 else daybarcnt[1] +1;

def lastcls = if bn == 1 then na
  else if (!isnan(close) and isnan(close[-1])) then close
  else lastcls[1];

# ----------------------------------------

def daycnt2 = if bn == 1 then 1 else if newday then daycnt2[1] + 1 else daycnt2[1];
def tomorrow = if (daycnt2 - daycnt) == 1 then 1 else 0;
# this works, to plot a line on tomorrow
# plot rr = if tomorrow then lastcls else na;

#------------------------------------------

def agg = AggregationPeriod.day;

def dayopn = open(period = agg);
def dayhi = high(period = agg);
def daylo = low(period = agg);
def daycls = close(period = agg);

input show_todays_levels = no;
plot z1 = if show_todays_levels and istoday then dayopn else na;
plot z2 = if show_todays_levels and istoday then dayhi else na;
plot z3 = if show_todays_levels and istoday then daylo else na;
plot z4 = if show_todays_levels and istoday then daycls else na;

z1.setdefaultcolor(color.orange);
z1.SetStyle(Curve.MEDIUM_DASH);
z1.hidebubble();

z4.setdefaultcolor(color.cyan);
z4.SetStyle(Curve.MEDIUM_DASH);
z4.hidebubble();

z2.setdefaultcolor(color.light_gray);
z3.setdefaultcolor(color.light_gray);
z2.hidebubble();
z3.hidebubble();

# ---------------------------

def slope = (daycls - dayopn) / daybarqty;

def open_to_close = if bn == 1 then na
  else if istoday and newday then open
  else if istoday then open_to_close[1] + slope
  else na;

# diag line , open to close
input show_diag_line_open_to_close = no;
plot diag4 = if show_diag_line_open_to_close then open_to_close else na;
diag4.hidebubble();
diag4.SetDefaultColor(Color.gray);

#--------------------------

# recalc - using a horz line , mid way between day open and day close
def mid1 = if bn == 1 then na
  else if istoday and newday then ((dayopn+daycls)/2)
  else if istoday then mid1[1]
  else na;

#--------------------------

input ref_line_type = { diag , default horz };

def ref_line;
switch (ref_line_type) {
case diag:
ref_line = open_to_close;
case horz:
ref_line = mid1;
}

#--------------------------

# raw data
# line data shifted down - dont use
def histo1 = if istoday then (close - ref_line) else na;

# vert offset , plot below
def ref1 = dayopn * 0.01;
def historef = daylo - ref1;

input show_lower_ref_line = no;
plot ref2 = if istoday and show_lower_ref_line then historef else na;
ref2.SetDefaultColor(Color.gray);
ref2.hidebubble();

def histo2 = historef + histo1;

input ema_len = 23;
def h2 = ExpAverage(histo2, ema_len);

input show_h3 = no;
def h3 = ExpAverage(h2, ema_len);
plot h3a = if show_h3 then h3 else na;
h3a.SetDefaultColor(Color.magenta);
h3a.hidebubble();

# ----------------------------------------------------------

# line data , not shifted down. to be copied to tomorrow
def histo5 = ref_line + histo1;
def h4 = ExpAverage(histo5, ema_len);

input show_curve_on_today = no;
def h5 = ExpAverage(h4, ema_len);
plot h5a = if show_curve_on_today then h5 else na;
h5a.SetDefaultColor(Color.magenta);
h5a.hidebubble();

# ----------------------------------

# tomorrow
# draw todays curve on tomorrow

def curve_tom = if tomorrow then getvalue(h5, daybarqty) else na;
input show_curve_on_tomorrow = yes;
plot curv2 = if show_curve_on_tomorrow then curve_tom else na;
curv2.SetDefaultColor(Color.magenta);
curv2.hidebubble();
#


2 examples, a double average purple line drawn on tomorrow
PWefBAH.jpg


8MzaKor.jpg
 
Solution

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