 # 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:
• #### BenTen

Staff member
Staff
VIP
Just a quick note that EMA is short for Exponential Moving Average, not Expected Moving Average.

• AssassinAR15

##### Member
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 #### AssassinAR15

##### Member
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);``````

#### AssassinAR15

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

And instead of actually getting this for free, I would be willing to donate \$25 to a charitable cause for this info.

lmk what charity, and I’ll post a screenshot here or email.

Last edited:

#### generic

##### Active member
• AssassinAR15

#### AssassinAR15

##### Member
@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.

#### generic

##### Active member
@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 and RTH and today), MA_delta, delta_high), MA_delta);
rec delta_low = compoundValue(1, if((MA_delta < delta_low and RTH and today), MA_delta, delta_low), MA_delta);

def high = delta_high > delta_high;
def low = delta_low < delta_low;

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