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

Problem saving chart template

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

    Problem saving chart template

    Hi there,

    I notice that in some cases, NT can't save templates due a failure on Indicator class reflection. I finally found a solution, but it was giving my nuts.

    I made a simple example to show the issue.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators {
    
        public class [B]MyOrder[/B] {  // Simple demo class
            public double price;
    
            public MyOrder(double price=0) {
                this.price = price;
            }
        }
    
        public class MyIndicator : Indicator {
    
            [B]public MyOrder signal_entry; [/B] // the reflection fails when this line is uncommented
    
            protected override void OnStateChange() {
    
                switch (State) {
                    case State.SetDefaults: {
                        Description = @"My Indicator base classs";
                        Name = this.GetType().Name;
                        Calculate               = Calculate.OnBarClose;
                        IsOverlay               = false;
                        DisplayInDataBox        = true;
                        DrawOnPricePanel        = false;
                        DrawHorizontalGridLines = true;
                        DrawVerticalGridLines   = true;
                        PaintPriceMarkers       = true;
                        ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                        //See Help Guide for additional information.
                        IsSuspendedWhileInactive = true;
                        break;
                    }
                    case State.Configure: {
                        AddLine(Brushes.Yellow, 0, "Zero");
                        break;
                    }
                }
            }
    
            protected override void OnBarUpdate() {
                Print("I'm alive:" + Time[0]);
            }
    
            #region Properties
            #endregion
        }
    }

    Even more surprising is the fact that if I declare protected this member, everything works fine.

    Can anyone give me a hint about that problem?, seems a design decision, not really a problem.
    --
    Asterio

    #2
    Hello,

    Thank you for the post.

    Yes, this would be expected for any complex object that you make into a public property. You would either need to make this a private property or mark this property as [XmlIgnore].

    We have a sample of the syntax to ignore a property, and also make a serialization property here: https://ninjatrader.com/support/help...definedbrushes

    The same concept applies to any complex object, not just a brush. The platform is trying to save this with the template which is not wanted, so you would need to ignore it or make it not publically visible.


    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse!

      I also get the point on using [XmlIgnore] .

      Great!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,605 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      13 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X