Thanks!!
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Automatically detect and draw a divergence
Collapse
X
-
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!!Tags: None
-
Hi, try the 'DivergenceSpotter' from our sharing section - http://www.ninjatrader-support2.com/...ergence&desc=1BertrandNinjaTrader Customer Service
-
-
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....
Comment
-
Originally posted by clfield View PostI 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....
Comment
-
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???
Comment
-
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 P.NinjaTrader Customer Service
Comment
-
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
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
3 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
20 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment