Hi… Been looking at this problem , can you clarify a few things. May look like stupid questions but bare with me.
Price Change…
When you talk of ‘Price Change’ and ‘Price Action Changes’, your earlier example doesn’t literally specify at what resolution you require, and from the ‘Inside Candle’ code posted by ‘JS’ gives me the impression that your concerns were focused on the array/EMA calculation, than the difference in price action values generated on a 1min for 10min chart.
Also, you gave an example of price change’s which were all integers, does this mean your minimum Price Action is ‘1’, or decimals, and to how many decimal places.
So…my guess is,
A price change is at the ‘tick’ level and, is represented by two value which are different from each other. And that 6000.00000 and 6000.00001 is a price change. Maybe not, read on…
Averages
When you calculate a, SMA, yes SMA, you take the sum of a ‘number of values’ and divide by the ‘number of values’ used, SMA = ((Vo+V1+Vn)/n). Let V0 be the current candle and V1 be the previous and,Vn other previous values and so on. Note that each SMA value calculated is going to be on a different set of ‘V’ values, based on ‘n’ value used as the bar position shifts.
But when you calculate the EMA you, don’t just do it in a slightly different but similar way. The big difference’s are that you only use one ‘V’ value, ‘ Vo’ , the previous ema, EMA[1], ‘n’ and some math magic. EMA = Vo * k+ EMA[1] * (1-k) where k=2/(n+1).
Now, just imagining what the stock EMA will do on the current candle, in real time. If price action ‘is’ constantly changing, it ‘will’ use the price change value, you want, but not an EMA of the previous change but one for the previous bar. And, that’s not even thinking what happens when, or after no change . So, is this why you wan’t the EMA to be calculated on a set of previous price changes.
It’s become evident by, how the EMA is calculated that you only need ‘1’ price change value to calculate it. This could negate the need for an array since you only need the last price change.
Compare prices…
Also, ive just remember, as i’m writing, your first post talked about comparing the ‘$lastPrice’ with the ‘latest price’ in the same candle. I’m assuming that the $lastPrice is the last Price change in the array, and the latest price is…. We’ll a bit of confusion… at tick level, the latestPrice, if different to the $lastPrice would get shoved into the array as a new $latestPrice and if no change, the difference would equate to zero.
Note to self… if a<>b = true then not( (a = b) = 0) = false
If your still following me, there needs to be some measurable values, which could/are ‘different’ to the stored Price Changes in the array, for you to compare, without themselves being shoved into the array. However logic say’s if there is a difference, store in array. Seems like one of those scenario’s where you can’t have it both ways, if you see my drift.
I’ve not thought this through yet, since you mentioned ‘in the same candle’ we must be talking about a higher timeframe, what timeframe are you talking about and what is the significance of comparing the two prices.
Summary
There has to be different values between the price action values which go in the array, to the ones for a comparison to equate a difference. This is looking like the array value must be generated from a higher timeframe and the ticks in between them are the other ones you compare. Or at least two different timeframes, one for the array and one with the compare values in between.
File below, 1st just compares a stock ema with manually calculated one. And 2nd one compares an SMA and EMA manually calculated on the price changes only, if used on 1 tick, and an EMA from the current close. I haven’t tested them just used to sus stuff out etc.
From the beginning the ‘Book’ said ‘No’, i’ve read the book and think its 99.9% right, but in trying several different things and refining the spec, were at 99.8%, there maybe a very small remote chance of coming up with a solution. Whether its going to be usable or useful, we’ll, well after wait and see.
Best regards