• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem Getting data from struct

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

    Problem Getting data from struct

    Hi

    I'm trying to build an indicator that use planet longitude (Astro trading).
    I have the formula for getting the longitude (tested and compared to other sources).
    I've used struct to represent each planet (for example , Earth, Mars) because each they have some common features.

    I succeeded in getting the right longitude but when I try to insert them in an array (by date) I get 0 instead of the actual longitude.

    If you see in the code - when I try to print the longitude in SetLongitude I get 0, but when I try to print the longitude in SetPlanetElemetns I get the real longitude.

    Why is that , what am I missing ?
    Attached Files

    #2
    Managed to fix it
    Changed the struct:
    public struct OrbitalElements
    {
    public double L {get; set;} // Mean longitude of the planet
    public double w {get; set;}// Mean angular speed
    public double T {get; set;}// Period of revolution of the planets, taken from Unfolding our Universe - Iain Nicolson
    public double ML {get; set;} // Mean longitude
    public double MAT {get; set;} //Mean angle traversed
    public double A {get; set;} //Longitudinal distance of the planet from the perihelion along the elliptical orbit is known as its Anomaly
    public double MA {get; set;}//Mean Anomaly
    public double e {get; set;}//Eccentricity of the ellipse
    public double PL {get; set;} //Perihelion Longitude
    public double correction {get; set;} //Perihelion Longitude
    public double CL {get; set;} //Current longitude
    public double a {get; set;} //Semi major axis of the orbit (this element is a constant for each planet)
    public double r {get; set;} //Radii r of orbit around the sun
    public double Xh {get; set;} //Heliocentric rectangular co-ordinates
    public double Yh {get; set;} //Heliocentric rectangular co-ordinates
    public double Xg {get; set;} //Geocentric rectangular co-ordinates
    public double Yg {get; set;} //Geocentric rectangular co-ordinates
    public double rg {get; set;} //Geocentric
    public double CLg {get; set;} //Geocentric

    };

    Now it is working

    Comment


      #3
      Hello zivvv,

      Thank-you for your post. Glad you have been able to solve the problem!

      If you need assistance in the future, please feel free to post again.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Paul,
        Could you please help with similar struct issue as follows:
        1. struct is constructed in an indicator Ind_A as follows:
        private struct stSignal
        {
        public int iBar;
        public int iSignal;
        public bool bTrendDown;
        public int iStrength;
        public int iNbrSignal;
        };
        private stSignal[] stSignal_all = new stSignal[2001];

        2. From indicator Ind_A, this struct is passed by reference to Ind_B to get the data, noting that the same struct is also declared exactly in Ind_B.

        3. In Indicator Ind_B, the method is written as follows:
        public bool bGetMACDsignal(ref stSignal[] stData)
        {
        // fill stData[] data.
        ...
        return(true);
        }
        The compiler error code is CS0051: inconsistent accessibility: parameter type ...

        What is the correct method for Ind_B to accept the struct array as input (by reference)? It accepts standard variable types by reference without errors.

        Comment


          #5
          Hello,

          Thank you for the post.

          Based on the error, it seems that you are trying to pass a reference of a private object from one class to another.

          Even though the second class (indicator) has the same struct defined, the reference is to only one of the structs making the second class see it as private.

          I would suggest using a public class instead of a struct in this case if you need to make an object in which you would pass to the indicator.

          I will provide a simple example of two indicators below and the class they share:


          First in a new indicator, clear out all the code and only place the following in the file:
          MyCustomClass.cs
          Code:
          namespace NinjaTrader.Indicator
          {
             	public class MyCustomObject
          	{
          		public double MyValue {get;set;}	
          	}
          }
          Now in another indicator, you can make a public property of this type:

          Test.cs
          Code:
          public class Test : Indicator
          {
          	private NinjaTrader.Indicator.MyCustomObject myCustomObject;
          	
                  protected override void Initialize()
                  {
          		MyPublicCustomObject = new NinjaTrader.Indicator.MyCustomObject();
                  }
          	
          	protected override void OnBarUpdate()
          	{		}
          	
          	[Description("")]
          	[GridCategory("Parameters")]
          	public NinjaTrader.Indicator.MyCustomObject MyPublicCustomObject
          	{
          		get {return myCustomObject;} 
          		set { myCustomObject = value;}
          	}
          }
          Finally, you could then Call this indicator and pass a reference:

          Test2.cs
          Code:
          public class Test2 : Indicator
          {
                 private NinjaTrader.Indicator.MyCustomObject myCustomObject;
          		
                  protected override void Initialize()
                  {
          			myCustomObject = new NinjaTrader.Indicator.MyCustomObject();
          			myCustomObject.MyValue = 100;
                  }
          		
          	protected override void OnBarUpdate()
          	{		
          		Print(Test(myCustomObject));
          	}
              }
          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Jesse, thank you for your suggestion. After further consideration, to avoid unnecessary complexity, I have decided to stay with individual standard variable types for parameter passing. The sacrifice is calling the same get function numerous times instead of a single transfer.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Duval, Today, 08:38 AM
            0 responses
            8 views
            0 likes
            Last Post Duval
            by Duval
             
            Started by i2w8am9ii2, 02-13-2019, 04:28 PM
            7 responses
            61 views
            0 likes
            Last Post sledge
            by sledge
             
            Started by woodyfox, Yesterday, 08:33 PM
            0 responses
            7 views
            0 likes
            Last Post woodyfox  
            Started by rblunsom, Yesterday, 11:19 AM
            2 responses
            30 views
            0 likes
            Last Post guidoisot  
            Started by drewski1980, Yesterday, 02:38 PM
            1 response
            22 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X