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 mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      20 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Working...
      X