Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am working on an algorithm that requires that at the open of each 1 minute candle I calculate what price would be required for the price to equal the value of a 5 period EMA. Basically, I need a formula that tells me the point of intersection between the price and a 5 period EMA.
If you watch a 5 period EMA move with price action on a 1 minute chart, you'll note that it moves quite a lot up and down with each tick, so simply using the position of the EMA at the previous candle's close is not an option.
Thank you so much to any math wizard who can help me with this!
Can you help answer these questions from other members on NexusFi?
You're trying to do what Excel calls a 'Circular Reference.' I said that hoping you'd be familiar with Excel and that term.
You can't know where the EMA will be in advance ... because it moves with price. So you'd have to know where price will be, in advance, to know where EMA will be, in advance.
Also, the final EMA value for each bar is based on the closing bar price. So you'd have to know the closing price of the current bar, in advance, in order to know where the EMA will be.
I think that perhaps I didn't explain it in a way you understood correctly. I am not trying to predict where the EMA of a bar will finish before the price has closed, as like you said I'd have to know where the close would be first and that is unpredictable.
What I am trying to do is figure out what the price would have to go to in order to touch the EMA. Whether it does so or not is unpredictable, but what price would be required to go to in order to touch the EMA should be calculable. For example, if we were to use a 500 day EMA, and the value of it on a given day was $100, we would know that price would have to go to basically $100 in order to touch the EMA, since the EMA would move only very, very slightly with each tick, since it is such a large period the EMA references.
Additionally, lets look at the formula for the ema: EMA = Price * (2 / (period + 1)) + EMA(of the previous period) * (1 - (2 / period + 1))
If you know the previous EMA (which I would), the period (I'm using 5), and you put in any price value, you can calculate where the EMA would be if the price got to that point. If the price also closed at that exact point, the EMA would "finalize" at that point for that period.
I hope this makes sense, and again I appreciate any help anyone can provide!
Excellent work! Thanks for the help. It makes so much sense now that you lay it out.
Since you did so well with that, can you help me with a slightly more difficult one that is similar?
I need to also find the point at which the price would intersect the upper and lower bands of a Keltner Channel. The channel uses a 5 period EMA as before as the middle band, and the distance between the middle EMA and the outer bands is equal to the ATR * KF (Keltner Factor). The ATR is a standard configuration using a Wilders MA, and borrows the length of the MA from the Keltner Channel (5 periods). It seems I can't just add the ATR * KF to the previous EMA in this case.
Of course. The formula for the middle band is the same EMA formula as before. The formula for the upper band of the Keltner Channel is : KC(upper band) = EMA + (ATR * KF) where KF is a constant that I will provide. ATR = max(high, close(previous)) - min (low, close(previous)). In word form, it is the largest of the: current high - current low, absolute value of the current high - previous close, or absolute value of the current low minus previous close.
Formula for the lower band is KC(lower band) = EMA - (ATR * KF)
I should also explain that I am not looking for the price where the price = the upper/lower bands at the previous 1 minute candle's close, but where they would meet in real time. In other words, what would price have to equal in order for it to close at the same price as the upper/lower bands?