Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color array parameter

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

    Color array parameter

    Scenario:

    I want to pass a color array into an indicator. Can't seem to get the serialize syntax correct. Tried a couple of variations but no luck.

    private Color[] distanceRatiosColors = new Color[] {
    Color.Indigo,
    Color.Cyan,
    Color.Magenta,
    Color.DarkOrange,
    Color.Navy,
    };

    [XmlIgnore]
    [Description("Color Distance Ratios")]
    [Category("Parameters")]
    [Gui.Design.DisplayName("Color Distance Ratios")]
    public Color[] DistanceRatiosColors
    {
    get { return distanceRatiosColors; }
    set { distanceRatiosColors = value; }
    }

    // Serialize our Color object
    [Browsable(false)]
    public string[] DistanceRatiosColorsSerialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( distanceRatiosColors); }
    set { distanceRatiosColors = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }

    Any clues on what the serialize section should be? I understand what the compiler is telling me just not sure how to code it.
    Last edited by ct; 01-26-2017, 01:04 AM.

    #2
    Hello,

    Thank you for the question.

    For this item, the two methods to Serialize the Colors are only intended for a single color. Because of this, you would need to implement your own logic to get all items into a string form and then parse the string back into items and add them into the array at the correct index.

    There are likely more than a few ways to accomplish this, I am unaware of a simple way using NinjaTrader specific methods. I put together an example of using a ByteArray and encoding the array to base64, then reversing this process to rebuild the object. This sounds complicated but in reality were just saving the whole array in total, then reloading that array again.

    Please see the attached sample for a demonstration of how to serialize the array.


    I look forward to being of further assistance.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    563 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    329 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    548 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X