Posted 2/13/2010 05:00:04
|
|
|
|
Hi Guys,
Looking for any help on how would I write the code to scan for a divergence between price and an indicator.
i.e Bullish divergence when the price makes two lower lows but the indicator make two higher highs.
See screen shot for a clear picture.
Any ideas?
Thanks.
|
|
Posted 2/13/2010 08:42:52
|
|
|
|
In principle this would seem to work(?): Under NewBar, test whether current is new low in your time frame (see BarUtils.LowestLow maybe). On each subsequent NewBar keep a count that 'ages' that previous new low. Check whether this new current is lower (within the time frame (before aging out)) to see if you have two successively in the time frame. Note that the value of 'local' variables are preserved from one NewBar to the next, so keeping a bit of history is easy.
-Pete (See also rightedge-ats Yahoo group )
|
|
Posted 2/13/2010 21:15:15
|
|
|
|
Small nitpick: Technically "local" variables are those declared inside of a method body, and those aren't preserved from one NewBar to the next. I think you are referring to class variables, which are preserved.

Daniel
|
|
Posted 2/14/2010 05:49:11
|
|
|
|
Thanks would the way PHG mentioned be the best?
I know in other packages you can specify peak and trough but couldn't see it in RE
|
|
Posted 2/14/2010 07:00:25
|
|
|
|
Thanks Daniel. Precision counts, and that keeps me on my learning curve.
-Pete (See also rightedge-ats Yahoo group )
|
|
Posted 2/14/2010 11:39:51
|
|
|
|
Yes, I would recommend doing something like PHG's method.
To code this you need to define what you are looking for more precisely. Do the new high/lows you are looking for have to be all-time high or lows, or do you only want to look back a certain number of bars? How close together do you want to require the highs/lows to be.
Also, looking at the screenshot, it looks like the indicator isn't actually making two new highs. So I'm not sure if you want something different or if the chart isn't a good example of what you're looking for.
Daniel
|
|
Posted 2/16/2010 05:07:13
|
|
|
|
| The indicator is making a higher swing low is what It should have said.
|
|
|
|