![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Feb 2009
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
|
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!! |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Hi, try the 'DivergenceSpotter' from our sharing section - http://www.ninjatrader-support2.com/...ergence&desc=1
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2009
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks!! I will take a look.
|
|
|
|
|
|
#4 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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....
|
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Feb 2009
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
|
|
|
|
|
|
|
#6 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
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!
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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??? |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#11 |
|
Member
|
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
|
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
In Initialize() add the line DrawOnPricePanel = false.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
This may be the issue clfield, can you reinstall the .NET framework and test this indicator again?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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?
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |