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

Which Plot gets referred to

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

    Which Plot gets referred to

    Hello friends

    I am trying to understand this problem since past few hours. In the code snippet shown below, I have two classes both derived from Indicator. One of the class refers to another using C# Indexer and I am unable figure out where it links to.

    myMacd.cs contains first indicator that adds four plots in its Initialize() method

    myMacd.cs gets used in DivergenceSpotter.cs which calls automatically generated method on myMacd and then simply accesses a double value from one of the array using [0] syntax.

    My query is: Which of the four plots does the [0] is referred to by statement shown in Bold Red Colored line. It calls a method a defined in Indicator class along with parameters and returns my object. the [] indexer is defined in IndicatorBase class and I am unable to find its documentation. This construct is used in many places including the Divergence Spotter that is attached at beginning of this thread. In the sample code, there are 12 Indicators.

    Code:
    // Filename: myMACD.cs
    public class myMACD : Indicator 
    {
        protected override void Initialize()
        {
    		Add(new Plot(Color.Green, "MACD"));
    		Add(new Plot(Color.DarkViolet, "Signal"));
    		Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Histogram"));
    		Add(new Line(Color.DarkGray, 0, "Median"));
    	}
    	......
    }
    
    public partial class Indicator : IndicatorBase
    {
        private myMACD[] cachemyMACD = null;
    
        private static myMACD checkmyMACD = new myMACD();
    
        public myMACD myMACD(int fast, int slow, int smooth)
        {
            return myMACD(Input, fast, slow, smooth);
        }
    
        public myMACD myMACD(Data.IDataSeries input, int fast, int slow, int smooth)
        {
        }
    }
    =================================
    // Filename: myDivergenceSpotter.cs
    
    public class myDivergenceSpotter : Indicator
    {
    	private DataSeries TheIndicator;
    
        protected override void Initialize()
        {
    		TheIndicator = new DataSeries(this);
        } 
    
        protected override void OnBarUpdate()
        {
    		[B][COLOR="Red"]TheIndicator.Set(myMACD(12, 26, 9)[0]);[/COLOR][/B]
        } 
    }

    #2
    Originally posted by cdjindia View Post
    Hello friends

    I am trying to understand this problem since past few hours. In the code snippet shown below, I have two classes both derived from Indicator. One of the class refers to another using C# Indexer and I am unable figure out where it links to.

    myMacd.cs contains first indicator that adds four plots in its Initialize() method

    myMacd.cs gets used in DivergenceSpotter.cs which calls automatically generated method on myMacd and then simply accesses a double value from one of the array using [0] syntax.

    My query is: Which of the four plots does the [0] is referred to by statement shown in Bold Red Colored line. It calls a method a defined in Indicator class along with parameters and returns my object. the [] indexer is defined in IndicatorBase class and I am unable to find its documentation. This construct is used in many places including the Divergence Spotter that is attached at beginning of this thread. In the sample code, there are 12 Indicators.

    Code:
    // Filename: myMACD.cs
    public class myMACD : Indicator 
    {
        protected override void Initialize()
        {
    		Add(new Plot(Color.Green, "MACD"));
    		Add(new Plot(Color.DarkViolet, "Signal"));
    		Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Histogram"));
    		Add(new Line(Color.DarkGray, 0, "Median"));
    	}
    	......
    }
    
    public partial class Indicator : IndicatorBase
    {
        private myMACD[] cachemyMACD = null;
    
        private static myMACD checkmyMACD = new myMACD();
    
        public myMACD myMACD(int fast, int slow, int smooth)
        {
            return myMACD(Input, fast, slow, smooth);
        }
    
        public myMACD myMACD(Data.IDataSeries input, int fast, int slow, int smooth)
        {
        }
    }
    =================================
    // Filename: myDivergenceSpotter.cs
    
    public class myDivergenceSpotter : Indicator
    {
    	private DataSeries TheIndicator;
    
        protected override void Initialize()
        {
    		TheIndicator = new DataSeries(this);
        } 
    
        protected override void OnBarUpdate()
        {
    		[B][COLOR="Red"]TheIndicator.Set(myMACD(12, 26, 9)[0]);[/COLOR][/B]
        } 
    }
    What code "at the beginning of the thread"?

    Your post is the first post in the thread.

    Comment


      #3
      It sounds like you'll need to look down in the Properties region as I don't think I'll be able to tell from this snippet provided.

      Toward the bottom of the code you'll likely see something like this

      [Browsable(false)]
      [XmlIgnore()]
      public DataSeries TheIndicator
      {
      get { return Values[1]; }
      }

      The index of Values will let you know which plot it is referring to.
      LanceNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Lance View Post
        It sounds like you'll need to look down in the Properties region as I don't think I'll be able to tell from this snippet provided.

        Toward the bottom of the code you'll likely see something like this

        [Browsable(false)]
        [XmlIgnore()]
        public DataSeries TheIndicator
        {
        get { return Values[1]; }
        }

        The index of Values will let you know which plot it is referring to.
        Lance, Thank you very much for replying. I've already gone through all automatically generated code. I am comfortable with C#, been at it for few years now, so I've checked all such places.

        Please take a look at the zip file attached to the first post (dated 11 20 2007)


        OR
        DivergenceSpotter.zip

        I've found a very similar example here attached in a zip file here.

        In that zip, there is Indicator named DivergenceSpotter.cs that sits in-between (wraps around) 12 other indicators and accesses them using this Indexer syntax. And except for one, all of the Indicators referred are unedited standards that come with NT.

        The decision as to which Plot gets referred to does not happen in the Child class (myMacd).at all It does not happen in wrapper class either (myDivergenceSpotter). It is happening somewhere inside the NT's class hierarchy in a class named IndicatorBase.

        As you will see in the snippet that I have provided, TheIndicator is a locally defined private variable (not a property) that gets created in Initialize() and then gets set to one value in the line highlighted.

        That the double value being referred to will come from myMacd class is evident because [0] is immediately after a call to a function named myMacd. (It looks like a constructor but it isn't).

        The square bracket Indexer syntax is not defined anywhere in myMacd or in the Indicator class. That Indexer is defined in abstract base class named IndicatorBase. Somewhere inside the IndicatorBase class, there is following declaration.

        double this[int BarsAgo] {get; }
        Last edited by cdjindia; 07-29-2013, 11:20 AM.

        Comment


          #5
          Thanks for clarifying it does look like I misunderstood what you were looking for.

          While we allow users to create their own custom classes we don't provide support for this.

          This DivergenceSpotter is making calls to indicators and returning the index value for that indicator. This is what the [0] refers to. Without this it would be referring to the entire series.

          When a plot (property) is not specified, like in this example, it will refer to the primary plot. The primary plot is the first plot that was added in Initialize()
          It can also be called with Values[0]



          Let me know if this is what you were asking about.
          LanceNinjaTrader Customer Service

          Comment


            #6
            Yes Lance!!!, That is exactly what I was asking. Thank you very much!!!

            This was the most logical thing that but I still wanted to confirm this. This resolves about 40 to 50% of bugs that I am seeing here.

            Just one last thing, Lance after which you can close this query and mark it as resolved.

            In the DivergenceSpotter,zip file, Kindly confirm that in case of the @ROC Indicator,
            will the Divergence Spotter class fail to detect Divergences because
            @ROC indicator plots zero line first OR
            will it work because although @ROC code plots zero first, it uses Value.Set() method in OnBarsUpdate() method.

            DivergenceSpotter does include ROC in itself (it is numbered 11)

            Comment


              #7
              Glad to hear it.

              I won't be able to speak on behalf of the Divergence Spotter as I did not create this but in regards to the ROC indicator the added Line will not be considered the primary plot even though it comes before the plot. Plots are indexed to the Values

              Example
              Values[0] //first plot
              Values[1] //second plot
              Values[2] // third plot
              etc

              But the Added Lines are not. You can access the line property but this is not added the same way plots are.

              When setting the primary plot you can use Value.Set()
              This is the same as Values[0].Set()

              Let me know if I can further assist
              LanceNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by gravdigaz6, Today, 11:40 PM
              0 responses
              3 views
              0 likes
              Last Post gravdigaz6  
              Started by MarianApalaghiei, Today, 10:49 PM
              3 responses
              9 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by XXtrader, Today, 11:30 PM
              0 responses
              3 views
              0 likes
              Last Post XXtrader  
              Started by love2code2trade, Yesterday, 01:45 PM
              4 responses
              28 views
              0 likes
              Last Post love2code2trade  
              Started by funk10101, Today, 09:43 PM
              0 responses
              9 views
              0 likes
              Last Post funk10101  
              Working...
              X