# Thread: Trying to 'reverse' a formula....

1. ## Trying to 'reverse' a formula....

I am trying work out a formula based on the information below that will help me to answer the question... "What PRICE is required today that will make the difference between two exponential moving averages the same value as yesterday?" I can work out the formula 'forwards' as I've shown below with my calculations, but I am trying to create a formula where TODAYS PRICE is the unknown variable. Any help would be most appreciated, Thank you.

YP = Yesterday price (=4.29)
YEMA1 = yesterdays 3 day exponential moving average (=4.28)
YEMA2 = yesterdays 5 day exponential moving average (=4.20)
YDiff = YEMA1/YEMA2 (=1.01905)

TP = Todays price (=4.29)
TEMA1 = Today's 3 day exponential moving average =2/4*(TP-YEMA1)+YEMA1 (=4.285)
TEMA2 = Today's 5 day exponential moving average =2/6*(TP-YEMA2)+YEMA2 (=4.23)
TDiff = TEMA1/TEMA2 (=1.013002)

So, just to clarify, I am trying to find out what 'TP' should be that will make 'Tdiff' equal 'Ydiff'.

2. ## Re: Trying to 'reverse' a formula....

For simplicity I'm going to call YEMEA1 = Y_1, YEMEA2=Y_2, Ydif = Yd, TEMA1 = T_1, TEMA2 = T_2, Tdiff = Td

The formula for T1 that you have can be simplified to $\displaystyle T_1 = \frac {T_p} 2 +\frac {Y_1} 2$, and $\displaystyle T_2 = \frac {T_p} 3 + \frac {2Y_2} 3$.

If $\displaystyle Y_d = T_d$, then $\displaystyle Y_d = \frac {T_1}{T_2} = \frac {\frac {T_p} 2 +\frac {Y_1} 2}{\frac {T_p} 3+\frac {2Y_2}{3}}$

Multiply numerator and denominator of the the left hand side by 6, and rearrange:

$\displaystyle Y_d(2T_p+ 4 Y_2) = 3T_p + 3 Y_1$

$\displaystyle T_p(2Y_d-3) = 3Y_1 - 4 Y_dY_2$

Note that Yd times Y_2 = Y_1, so:

$\displaystyle T_p = \frac {3Y_1 - 4 Y_1}{2Y_d-3}$

$\displaystyle T_p = \frac {-Y_1} {2Y_d -3 }$

$\displaystyle T_p = \frac {Y_1}{3-2 Y_d}$

Using your numbers above, where Y_1 = 4.28 and Y_d = 1.01905, you get Tp = 4.4495, T1 = 4.364752, T2 = 4.283168, and Td = 1.019048 (same as Yd).

3. ## Re: Trying to 'reverse' a formula....

Excellent! Thank you very much.. you've made my day.. I'd already spent quite some time trying to figure this out!

4. ## Re: Trying to 'reverse' a formula....

I've just been trying to test myself to make sure I understand how you derived at the formula... and so I have decided to use a different example using a 5 day EMA and an 8 day EMA.... (and applying a multiplier of 40 ).. but where I am really stuck is the process you went through to rearrange the formula after multiplying the numerator and denominator... could you break it down into smaller steps.. or point me in the direction of somewhere to go where I can learn how to do this? Thanks again.

5. ## Re: Trying to 'reverse' a formula....

OK. Staruing from:

$\displaystyle Y_d = \frac {\frac {T_p}2 +\frac {Y_1} 2}{\frac {T_p} 3 + \frac 2 Y_2} 3}$

Multiply through by $\displaystyle \frac 6 6$:

$\displaystyle Y_d = \frac {6 (\frac {T_p}2 +\frac {Y_1} 2)}{6(\frac {T_p} 3 + \frac 2 Y_2} 3)} = \frac {3T_p +3Y_1)}{2T_p + 4 Y_2}$

Now multiply through by the denominator on the right hand side:

$\displaystyle Y_d (2T_p + 4 Y_2) = 3T_p+3Y_1$

Regroup to bring the T_p terms to the left hand side and everything else on the right:

$\displaystyle Y_d(2 T_p) - 3T_p = 3Y_1 -4 Y_dY_2$

$\displaystyle T_p(2Y_d-3) = 3Y_1 - 4Y_dY_p$

Sub $\displaystyle Y_1= Y_dY_p$:

$\displaystyle T_p(2Y_d-3) = 3Y_1 - 4Y_1 = -Y_1$

Divide both sides by p$\displaystyle 2Y_d-3$:

$\displaystyle T_p = \frac {-Y_1}{2Y_d -3}$

Multiply right hand side by $\displaystyle \frac {-1}{-1}$:

$\displaystyle T_p = ( \frac {-1}{-1}) \frac {-Y_1}{2Y_d -3} = \frac {Y_1}{3 - 2 Y_d}$

Hope this helps.

6. ## Re: Trying to 'reverse' a formula....

There is an error in my previous post but i am unable to edit it.

Originally Posted by ebaines
OK. Staruing from:

$\displaystyle Y_d = \frac {\frac {T_p}2 +\frac {Y_1} 2}{\frac {T_p} 3 + \frac 2 Y_2} 3}$

Multiply through by $\displaystyle \frac 6 6$:

$\displaystyle Y_d = \frac {6 (\frac {T_p}2 +\frac {Y_1} 2)}{6(\frac {T_p} 3 + \frac 2 Y_2} 3)} = \frac {3T_p +3Y_1)}{2T_p + 4 Y_2}$
Should be:

Starting from:

$\displaystyle Y_d = \frac {\frac {T_p}2 +\frac {Y_1} 2}{\frac {T_p} 3 + \frac {2 Y_2} 3}}$

Multiply through by $\displaystyle \frac 6 6$:

$\displaystyle Y_d = \frac {6 (\frac {T_p}2 +\frac {Y_1} 2)}{6(\frac {T_p} 3 + \frac {2 Y_2} 3)}} = \frac {3T_p +3Y_1}{2T_p + 4 Y_2}$

The remainder of the post is OK as is.

7. ## Re: Trying to 'reverse' a formula....

Ah that's great - just what I needed - thank you!