Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Button color state

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

    Button color state

    Hello,
    I have a button that changes color with a click and returns a bool, for example by default color red and true and with a click color black and false, if it stays in position black-false and I do an F5 it returns me to the position red-true.
    How can I make it stay black-false?

    #2
    Hello anmir55,

    After hitting F5 this would reset any values.
    To keep this for a new cloned instance, you would need to do this in the Clone override.

    Code:
    ​[Browsable(false)]
    public Brush MyBool
    { get; set; }​​​
    
    [XmlIgnore()]
    [Browsable(false)]
    public Brush MyBrush
    { get; set; }
    
    public override object Clone()
    {
    // clones the current instance to a new instance as a generic NinjaScriptBase
    NinjaScriptBase clonedInstance = base.Clone() as NinjaScriptBase;
    
    if (clonedInstance == null)
    return clonedInstance;
    
    // MyBrush and MyBool are specific to this NinjaScript, and we will need to set the value via reflection
    Type newInstType = clonedInstance.GetType();
    System.Reflection.PropertyInfo myBrushPropertyInfo = newInstType.GetProperty("MyBrush");
    System.Reflection.PropertyInfo myBoolPropertyInfo = newInstType.GetProperty("MyBool");
    
    if (myBrushPropertyInfo == null || myBoolPropertyInfo == null)
    return clonedInstance;
    
    myBrushPropertyInfo.SetValue(clonedInstance, MyBrush);
    myBoolPropertyInfo.SetValue(clonedInstance, MyBool);
    
    return clonedInstance;
    }​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      I don't really understand how I have to apply it if I already have it in my indicator because the brush already has its properties. I want to keep the button with the last modification, I don't want it to be reset to the initial value​

      Comment


        #4
        Hello anmir55,

        Hitting F5 or clicking Reload NinjaScript clones the instance of the script and the new instance re-runs through the different states and re-processes all data as if it was just loaded.
        If you want the button to have the same property, you'll need to set that property. If you want the script to remember a value for a variable, you'll need to assign it in the new clone.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,
          I have entered the code with the name changes of the brush and the bool but it has not worked, the button that I hit F5 loses the current properties and returns to the original properties, it does not keep the current properties.​

          Comment


            #6
            Hello anmir55,

            You are specifying the names of your variables (properties) in yourscript and not using the MyBrush, MyBool example variables names from the sample code correct?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              correct, I have made a replacement​

              Comment


                #8
                Hello anmir55,

                May I examine the script?

                To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                1. Click Tools -> Export -> NinjaScript Add-on...
                2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                3. Click the 'Export' button
                4. Enter the script name in the value for 'File name:'
                5. Choose a save location -> click Save
                6. Click OK to clear the export location message
                By default your exported file will be in the following location:
                • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                Below is a link to the help guide on Exporting NinjaScripts.


                Once exported, please attach the file as an attachment to your reply.​
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Attached file

                  Comment


                    #10
                    Hello anmir55,

                    Have you provided the wrong script?

                    This script does not implement the Clone override and is not setting any public bool property or public brush property.

                    May I have the script where you have made the suggested changes to assign the public property on the new clone from the Clone override?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I have posted your code but it has given me errors, I think it is more complicated for me, I am not a programmer,

                      Comment


                        #12
                        In the end I was able to test the code that you gave me and it doesn't work, I attached an indicator

                        Comment


                          #13
                          Hello anmir55,

                          I've tested this script and the DisplayCompletedLines bool variable is being remembered when reloading.

                          Below is a link to a video of the test.


                          The ColorFondoOff variable is never being assigned a different brush value. But it is being remembered as well. It's only ever assigned to Brushes.MediumSeaGreen and never anything else, so this is what it remembers.

                          When the button is created in AddButtonToToolbar() you never check the state of DisplayCompletedLines, so this will always be drawn with the background color MediumSeaGreen.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello, thank you for the video
                            I understand that the colored background doesn't work for you either, because with F5 I would have to keep the black background, and it changes it to red... and it doesn't, that's my question, what do I have to modify?​

                            Comment


                              #15
                              Hello anmir55,

                              When creating the button, check DisplayCompletedLines is false and set the _button.Background to black.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              596 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              343 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              556 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              554 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X