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

Preventing add/remove to a PriceLevels collection but keep ability to edit colors etc

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

    Preventing add/remove to a PriceLevels collection but keep ability to edit colors etc

    Hello everyone.

    If I have a PriceLevels collection, is there a straightforward way (maybe through the CollectionEditor?) to prevent the user from adding/removing price levels of his own while allowing him to edit other properties of the levels I want to lock-in?

    In other words, he can change the colors, visibility, etc but cannot remove any of my ratios or add any of his own?

    Thanks in advance.

    #2
    Hello samir.of.salem,

    Thank you for writing in.

    What type of script are you developing? You could potentially create user inputs for the properties that you will allow the user to modify, then apply those properties within the script to the price levels with the set number of levels and ratios that may not be modified.
    Please provide a snippet and/or screenshots of what you are currently working with and explain what you would like to be modifiable vs. not modifiable so I may better understand and assist you.

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily.

      Thank you for your prompt response. Below is a stripped out code snippet.
      What I'm trying to achieve is that once applied to a chart and loaded with the percentages I need, the user would be free to change their colors and styling in the Collection Editor, i.e. only tamper with the stroke's Brush, Width, Opacity etc.

      (I'll be creating my own copy of the PriceLevel class, and to prevent changing the percentages I'll probably set the Value property to ReadOnly)

      But also I want to prevent the specified levels from being deleted or added to.
      Can the add/remove buttons on the CollectionEditor's left panel be hidden or grayed out?

      Click image for larger version

Name:	image.png
Views:	21
Size:	14.0 KB
ID:	1292615

      Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class MyCustomFibs : Indicator
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "MyCustom Fibs";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = true;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = 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;
                                  
                      MyPercentages = new List<PriceLevel>();
      
                  }
                  else if (State == State.Configure)
                  {
                      if (MyPercentages.Count == 0)
                      {
                          MyPercentages.Add(new PriceLevel(55, Brushes.Red));
                          MyPercentages.Add(new PriceLevel(66, Brushes.Green));
                          MyPercentages.Add(new PriceLevel(77, Brushes.Blue));
                      }
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  //Add your custom indicator logic here.
                  if (CurrentBar != Count - 2) return;
                  
                  var fib = Draw.FibonacciRetracements(this, "fib", false, Time[10], High[10], Time[1], Low[1]);
                  fib.PriceLevels = MyPercentages;
              }
      
              #region Properties
              [PropertyEditor("NinjaTrader.Gui.Tools.CollectionEditor")]
              [Display(ResourceType = typeof(Custom.Resource), Name = "Percentages", Prompt = "NinjaScriptDrawingToolsPriceLevelsPrompt", GroupName = "Levels", Order = 206)]
              //[SkipOnCopyTo(true)]
              public List<PriceLevel> MyPercentages { get; set; }
      
              #endregion
      
          }
      }
      ​

      Comment


        #4
        Hello samir.of.salem,

        Thank you for your reply.

        You could consider making MyPercentages a private list rather than a public user input. Then, for any properties that you would like to allow the user to modify you could create separate inputs. For example, I created a sample script with the same three levels and set the colors for each level as inputs. Please see the attached file.
        The user could still potentially modify the drawing object itself from the drawing tools window, though once OnBarUpdate() is called again the draw object will be overridden to its programmatic values. You could test this script On Bar Close and see what I mean; if you add a level or change properties of the FibonacciRetracements object in the Drawing Tools window, the changes will be applied until the bar closes and they will revert to the programmed values.

        Please let us know if we may be of further assistance.
        Attached Files
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jonafare, 12-06-2012, 03:48 PM
        5 responses
        3,986 views
        0 likes
        Last Post rene69851  
        Started by Fitspressorest, Today, 01:38 PM
        0 responses
        2 views
        0 likes
        Last Post Fitspressorest  
        Started by Jonker, Today, 01:19 PM
        0 responses
        2 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Started by futtrader, Today, 01:16 PM
        0 responses
        8 views
        0 likes
        Last Post futtrader  
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,792 views
        0 likes
        Last Post aligator  
        Working...
        X