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!
See more
See less

Partner 728x90

Collapse

Automatically detect and draw a divergence

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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!!

    #2
    Hi, try the 'DivergenceSpotter' from our sharing section - http://www.ninjatrader-support2.com/...ergence&desc=1
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks!! I will take a look.

      Comment


        #4
        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


          #5
          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.

          Comment


            #6
            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.

            Comment


              #7
              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!
              BertrandNinjaTrader Customer Service

              Comment


                #8
                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


                  #9
                  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


                    #10
                    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

                    Comment


                      #11
                      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


                        #12
                        In Initialize() add the line DrawOnPricePanel = false.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          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.

                          Comment


                            #14
                            This may be the issue clfield, can you reinstall the .NET framework and test this indicator again?
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              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?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Stanfillirenfro, Today, 07:23 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by olisav57, Yesterday, 07:39 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by cocoescala, 10-12-2018, 11:02 PM
                              7 responses
                              944 views
                              0 likes
                              Last Post Jquiroz1975  
                              Started by oviejo, Today, 12:28 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X