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 cls71, Today, 04:45 AM
      0 responses
      1 view
      0 likes
      Last Post cls71
      by cls71
       
      Started by mjairg, 07-20-2023, 11:57 PM
      3 responses
      213 views
      1 like
      Last Post PaulMohn  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      4 responses
      544 views
      0 likes
      Last Post PaulMohn  
      Started by GLFX005, Today, 03:23 AM
      0 responses
      3 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      12 views
      0 likes
      Last Post XXtrader  
      Working...
      X