NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 02-15-2009, 10:16 AM   #1
tradinginzen
Senior Member
 
Join Date: Feb 2009
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
Default Automatically detect and draw a divergence

I am curious if anyone has any samples that would detect either a divergence between price and an indicator and draw a trendline on the diverging indicator or (really what I want) divergences between two indicators. I know that if I could do price/indicator divergence then I could easily do indicator/indicator divergence. However, the detection code and drawing the subsequent trendline over the divergence on the indicator is new to me.

Thanks!!
tradinginzen is offline  
Reply With Quote
Old 02-15-2009, 01:36 PM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

Hi, try the 'DivergenceSpotter' from our sharing section - http://www.ninjatrader-support2.com/...ergence&desc=1
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 02-15-2009, 04:48 PM   #3
tradinginzen
Senior Member
 
Join Date: Feb 2009
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks!! I will take a look.
tradinginzen is offline  
Reply With Quote
Old 03-22-2009, 01:30 PM   #4
clfield
Member
 
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Default Drawing lines on Indicator panel

I have a working Divergence indicator whih I am currently using on the MACD and price. I an get it to Draw a line from the Peaks or valleys in quetion on the price bars just fine. However I can not get it to draw lines in the indicator panel. It is easy enough to do this manually so I am hoping it can be done with code too....
clfield is offline  
Reply With Quote
Old 03-22-2009, 01:34 PM   #5
tradinginzen
Senior Member
 
Join Date: Feb 2009
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by clfield View Post
I have a working Divergence indicator whih I am currently using on the MACD and price. I an get it to Draw a line from the Peaks or valleys in quetion on the price bars just fine. However I can not get it to draw lines in the indicator panel. It is easy enough to do this manually so I am hoping it can be done with code too....
I can try to help if you post the code.
tradinginzen is offline  
Reply With Quote
Old 03-23-2009, 05:38 AM   #6
clfield
Member
 
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Default

I am updating NT right now. Also I am having issues with the plotting in the Price panel today. Worked yesterday but not today????
I will post code here when I get NT running again.
clfield is offline  
Reply With Quote
Old 03-23-2009, 05:42 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

Hi clfield, could you please clarify what issues you are having and also report back if they are resolved after upgrading to 6.5.1000.9 ? Thanks!
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 03-23-2009, 06:16 AM   #8
clfield
Member
 
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Default

I sent an email support request to you just a couple of minutes ago. I am having two problems, both with Drawing lines. I wish to connect the related peaks or valleys on both the price chart and on the indicator when the divergence is detected. I thought I had the line on the chart working, but today it does not work either. Here is the related code which is embeded in a MACD type indicator.

if( CurrentBar > 20)
{
// Check indicator for Divergence with Price data
Print("----------------------------------- ");
Print(Time[0]);
Print("Diff[0] = "+ Diff[0]);


/*-------------------------------------------------------------------------------------------------------------
Determine LAST PEAK in the ZeroLag_TEMA_HATEMA_MACD.Diff Line, record values for it and previous peak
-------------------------------------------------------------------------------------------------------------*/
//Only Look for Peaks in Diif Line
if(Diff[0] < Diff[1] && Diff[1] > Diff[2])
{
//Only take peaks that are above zero line
if( Diff[1] > 0.0)
{

Print("----------------------------------- ");
Print("TestPeakDiff= "+TestPeakDiff);

ThirdPeakDiff = PrevPeakDiff;
ThirdPeakPriceDiff = PrevPeakPriceDiff;
ThirdPeakBarDiff = PrevPeakBarDiff;
ThirdPeakBarsAgo = (Bars.BarsSinceSession - ThirdPeakBarDiff);

PrevPeakDiff = LastPeakDiff;
PrevPeakPriceDiff = LastPeakPriceDiff;
PrevPeakBarDiff = LastPeakBarDiff;
PrevPeakBarsAgo = (Bars.BarsSinceSession - PrevPeakBarDiff);

LastPeakDiff = Diff[1];
LastPeakPriceDiff = High[1];
LastPeakBarDiff = Bars.BarsSinceSession-1;


// DrawVerticalLine("MACD2"+CurrentBar,1,Color.Chartr euse,DashStyle.Dash,1);

Print(" ");
Print("----------------------------------- ");
Print(Time[0]);
Print("Peak in ZLMACD.Diff ");
Print("LastPeakDiff= "+LastPeakDiff);
Print("LastPeakPrice= "+LastPeakPriceDiff);
Print("LastPeakBar= "+LastPeakBarDiff);
Print("LastPeakDiff="+ LastPeakDiff);
Print("PrevPeakDiff="+ PrevPeakDiff);
Print("LastPeakPriceDiff="+ LastPeakPriceDiff);
Print("PrevPeakPriceDiff="+ PrevPeakPriceDiff);
Print("LastPeakBarDiff="+ LastPeakBarDiff);
Print("PrevPeakBarDiff="+ PrevPeakBarDiff);

// Check for regular divergence in Peaks on ZLMACD.Diff line
if( LastPeakPriceDiff > PrevPeakPriceDiff && LastPeakDiff <= PrevPeakDiff
//&& PrevPeakPriceDiff > ThirdPeakPriceDiff && PrevPeakDiff < ThirdPeakDiff
)
{

DrawLine("ZLMACD"+CurrentBar,false,PrevPeakBarsAgo ,PrevPeakPriceDiff,1,LastPeakPriceDiff ,Color.Magenta,DashStyle.Dash,2);



}
}
}

there is a section to detect valleys following this then a close bracket for the if(CurrentBar > 20) statement.
This compiles fine but no indicator plots when loaded
if I change the PrevPeakBarsAgo to a 5 it works???
clfield is offline  
Reply With Quote
Old 03-23-2009, 07:58 AM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Please check your Control Center log for errors. From a brief glance, Bars.BarsSinceSession could easily be less than PrevPeakBarDiff which would result in the parameter being negative. This could cause problems as you try to pass it into DrawLine().

Remember if (CurrentBar > 20) does not limit anything on Bars.BarsSinceSession. CurrentBar > 20 is counting from the beginning of the chart. Bars.BarsSinceSession is counting from the session. You may have multiple sessions on a chart.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-23-2009, 08:19 AM   #10
clfield
Member
 
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your help. Yes that was exactly the problem, I was getting a negative value for the PrevPeakBarsAgo Value.
Man what alot to learn.
Got it working now
clfield is offline  
Reply With Quote
Old 04-17-2009, 01:52 PM   #11
dadof3and3
Member
 
Join Date: Jul 2007
Location: New Braunfels, Texas
Posts: 58
Thanks: 0
Thanked 0 times in 0 posts
Send a message via Yahoo to dadof3and3 Send a message via Skype™ to dadof3and3
Default

I'm not sure if one of your questions were ever answered. How do you use drawline in the indicator pane, I have no problems using it in the price pane. - David
dadof3and3 is offline  
Reply With Quote
Old 04-17-2009, 02:09 PM   #12
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

In Initialize() add the line DrawOnPricePanel = false.
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-17-2009, 04:38 PM   #13
clfield
Member
 
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Default

I tried that without results. I think the issue may be in the .Net platform. I sent the indicator to another trader to test. He said he gets a plot on the Indicator panel but not on the price panel. Just the opposite of what I see in my charts.
clfield is offline  
Reply With Quote
Old 04-17-2009, 11:25 PM   #14
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

This may be the issue clfield, can you reinstall the .NET framework and test this indicator again?
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 04-18-2009, 10:32 AM   #15
clfield
Member
 
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Default

I have removed and reinstalled the .Net Framework 3.5 SP1 twice now. I am wondering if I should only have the 2.0 loaded?
clfield is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Divergence spotter sbgtrading NinjaScript File Sharing Discussion 37 03-03-2012 07:01 AM
how to detect (eliminate) holidays? Lost Trader Strategy Development 6 06-09-2011 03:08 AM
Divergence line plotting? 5iver Indicator Development 5 09-28-2008 08:31 PM
How can you detect a close? tradefaz General Programming 1 08-24-2008 11:08 PM
Is there a way to detect what fractal is used? FireFly General Programming 3 04-29-2007 11:41 PM


All times are GMT -6. The time now is 12:27 AM.