How to determine biggest EMA difference of the trading day

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:


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.

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.

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.

@adii800 @generic
Last edited:


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.

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;
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;
plot newlow = if low then delta_low else nan;

AddLabel(yes, Round(delta_high, 2), color.GREEN);
AddLabel(yes, Round(delta_low, 2), color.RED);
@generic. Thank you yet again.

What charity would you like me to donate to? If you do not have a preference I can choose one.

Also, if you wouldn’t mind shooting me an email quick professor1215{at}, I will send you a confirmation of the donation.
Last edited:

Similar threads