NexusFi: Find Your Edge


Home Menu

 





Divergence detection algorithm


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 6 posts (11 thanks)
    2. looks_two cunparis with 5 posts (0 thanks)
    3. looks_3 max-td with 4 posts (4 thanks)
    4. looks_4 shodson with 3 posts (2 thanks)
      Best Posters
    1. looks_one cory with 5 thanks per post
    2. looks_two Fat Tails with 1.8 thanks per post
    3. looks_3 max-td with 1 thanks per post
    4. looks_4 shodson with 0.7 thanks per post
    1. trending_up 25,024 views
    2. thumb_up 24 thanks given
    3. group 7 followers
    1. forum 24 posts
    2. attach_file 9 attachments




 
Search this Thread

Divergence detection algorithm

  #11 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

there we go ....
pic is from this morning
divers are made with MacD in this example.
the code is in MT4.
folks say MT4 code is very near to NT-script - so its no complete other world.


it show "normal + hidden" diver as solid + dashed lines.

in realtime it works great - there is no repaint + nothing "evil" in it

the arrows /signals come up with the FIRST Bar that shows a turning MacD -- not 3 Bars later or so ! so its realy useful and not just "nice in review" like so much other things.

have a look at it if you can extract the calculations - i would love to see this for NT !


BTW -- you get MT4 incl feeds for free at alpari for example .... or at any forexbrokers

max-td
Attached Thumbnails
Click image for larger version

Name:	MT4 Diver20100429-fiic-261kb.jpg
Views:	658
Size:	261.6 KB
ID:	12347  
Attached Files
Elite Membership required to download: MACD_Divergence_V1.1.zip
Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #12 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

Thanks Cunparis for the thread idea and max-td for the mt4 code. I'm wondering if anyone has compared the MT4 code with the Spotter codes posted by Fattails?

Or has anyone done some successful porting from MT4 to NT? I'd be willing to give it a try but I'm looking for resources to understand things like this one:

 
Code
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
for(int i = ObjectsTotal() - 1; i >= 0; i--)
{
string label = ObjectName(i);
if(StringSubstr(label, 0, 19) != "MACD_DivergenceLine")
continue;
ObjectDelete(label); 
}
return(0);
}
in other words, how is "de" initialization compared to NT initialization? If anyone has some online tutorials for porting, please post links.
Thanks,
kz

Reply With Quote
Thanked by:
  #13 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927


hi zeller!

have a look here - its infos about the D3-spotter - D3 didnt really look for divers/swings in the indicator at all but manages the line-plotting not too bad i think.



about the other one i know not much - but it did not give out such good+clear results/signals like the MT4-indis

max-td
Reply With Quote
Thanked by:
  #14 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

Thanks, Max,

I noticed while going through an NT support thread that sefstrat and eDanny seem to have an excellent handle on converting MT4 indicators.

If they would be so kind to teach us "junior programmers" how to port MT4, that would be greatly appreciated.

kz

Reply With Quote
  #15 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

Some time ago I started working with a couple of guys that wanted a strategy to enter a trade when we get MACD divergence off a Bollinger Band bounce. I annotated some charts to help clarify what they were looking for. See attached.

The trick is when to take the 1st peak, and when to start looking for a second but divergent peak in both data series. For example, in the MACD examples, after the first peak in the histogram, we decided to not start looking for a new but higher swing low in the MACD histogram unless the MACD unless we got at least 3 higher readings after the first peak. Some thought we should cross all the way above the zero line and then back below it before waiting for the 2nd swing lower,while others thought that a cross above the zero line should reset the search for a 2nd peak. Also, regarding price, it wasn't clear if we are comparing lower lows or lower closes.

So there is a lot of discretion in measuring divergence and how you read the 2 data series that you are comparing. These examples that I share are some of the challenges one has to consider.

Attached Thumbnails
Click image for larger version

Name:	macd-divergence.png
Views:	487
Size:	128.0 KB
ID:	12394   Click image for larger version

Name:	macd-divergence2.png
Views:	373
Size:	130.2 KB
ID:	12395  
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #16 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103

Most trading systems based on divergences have a negative expectancy. The left chart is a good example. MACD produced a divergence, not because the trend slowed down, but because of the Baskerville effect: a moving average also barks if something drops out at the beginning of the period.

By pure luck price entered a consolidation and then continued its prior trend. Every short term consolidation of a trend produces a divergence, so you would not want to trade all of them.

The right chart shows that a trade entry based on MACD divergence came way too early. What about adding a filter that you will only take divergences after a trendline break ?

Reply With Quote
Thanked by:
  #17 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


Fat Tails View Post
Most trading systems based on divergences have a negative expectancy. The left chart is a good example. MACD produced a divergence, not because the trend slowed down, but because of the Baskerville effect: a moving average also barks if something drops out at the beginning of the period.

By pure luck price entered a consolidation and then continued its prior trend. Every short term consolidation of a trend produces a divergence, so you would not want to trade all of them.

The right chart shows that a trade entry based on MACD divergence came way too early. What about adding a filter that you will only take divergences after a trendline break ?

Which is why I think the requirement that the divergence occur happen off of a Bollinger band bounce potentially increases the success of reversal.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #18 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103

If you have a strong trend, this will be typically near a Bollinger Band. I have often observed that a trend weakens - i.e. reduces its slope - several times before it reverses. See daily chart of ES below.

Attached Thumbnails
Click image for larger version

Name:	Bollinger Band.jpg
Views:	375
Size:	107.7 KB
ID:	12400  
Reply With Quote
Thanked by:
  #19 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103

Or let us have a look at price action of ES during the last hour:

Attached Thumbnails
Click image for larger version

Name:	ES 06-10 (5 Min)  29_04_2010 bis.jpg
Views:	311
Size:	102.0 KB
ID:	12404  
Reply With Quote
  #20 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709



Fat Tails View Post
If you have a strong trend, this will be typically near a Bollinger Band. I have often observed that a trend weakens - i.e. reduces its slope - several times before it reverses. See daily chart of ES below.

I attached an updated chart with notes...

Also, reversals often can have targets 2-6x larger than stops so you don't need to be right more than 50% of the time.

Attached Thumbnails
Click image for larger version

Name:	divergence-detection-algorithm-bollinger-band.jpg
Views:	338
Size:	171.2 KB
ID:	12405  
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on April 29, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts