# How to determine biggest EMA difference of the trading day

#### AssassinAR15

##### Member
Hello. I have been doing ongoing research with the Exponential Moving Average. (Accidentally wrote Expected)

Is there a way to determine what point of the day had the biggest difference between specific averages? I have been doing this manually and wanted to see if I could make it any quicker.

@generic was nice enough to share a EMA distance indicator, but I am trying to evolve my theory and have moved to studying this a little more deeply.

Last edited:
Just a quick note that EMA is short for Exponential Moving Average, not Expected Moving Average.

first define your EMA difference as a variable.Ex:
def EMADiff = EMA1 - EMA2;
and then set the days on your chart to 1D or Today(end of last trading session to current (I think lol)).
Then make use of the function HighestAll(EMADIff) which will return the value of the highest EMADiff in the available data.

Hope this helps

I know this is way off, but this is where I am at. Really new at this, but giving it a shot.

Code:
``````input price = close;
input length_1 = 3;
input length_2 = 9;
input AverageType = AverageType.EXPONENTIAL;

def MA_1 = MovingAverage(AverageType, price, length_1);
def MA_2 = MovingAverage(AverageType, price, length_2);

def MA_delta = Round(MA_1 - MA_2, 2);

def HighestAll = MA_delta

AddLabel(yes, HighestAll, if HighestAll > 0 then Color.GREEN else Color.RED);``````

In addition to knowing the highest EMA difference of the day, I would also like to plot this EMA difference on a lower study.

Last edited by a moderator:
@generic Thank you!

I’ve been thinking about it, but here is what I think I will need:

1. Chart Label for HOD/LOD
2. Ability to input different EMA/SMA
3. Lower Study so we can see the fluctuation.

@ProfessorAR15 Combined 1 and 3. New high and low are plotted as histograms and they only show for the current day and during RTH. 2) The original script already had average type as a input so just change it but I separated them into if you wanted different types for both.

Code:
``````declare lower;

input price = close;
input length_1 = 3;
input length_2 = 9;
input AverageType1 = AverageType.EXPONENTIAL;
input AverageType2 = AverageType.EXPONENTIAL;

def nan = Double.NaN;
def RTH_start = 0930;
def RTH_end = 1600;
def RTH = SecondsFromTime(RTH_start) >= 0 and
SecondsTillTime(RTH_end) >=0;
def today = getday() == getlastDay();
def MA_1 = MovingAverage(AverageType1, price, length_1);
def MA_2 = MovingAverage(AverageType2, price, length_2);

plot zero = if !isNaN(close) then 0 else nan;
zero.HideBubble();
zero.HideTitle();
plot MA_delta = MA_1 - MA_2;

rec delta_high = compoundValue(1, if((MA_delta > delta_high[1] and RTH and today), MA_delta, delta_high[1]), MA_delta);
rec delta_low = compoundValue(1, if((MA_delta < delta_low[1] and RTH and today), MA_delta, delta_low[1]), MA_delta);

def high = delta_high > delta_high[1];
def low = delta_low < delta_low[1];

plot newhigh = if high then delta_high else nan;
newhigh.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot newlow = if low then delta_low else nan;
newlow.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

87k+ Posts
208 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?