• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sisenberg, Today, 07:29 AM
    1 response
    6 views
    0 likes
    Last Post sisenberg  
    Started by Oceans, Today, 02:22 AM
    2 responses
    22 views
    0 likes
    Last Post Oceans
    by Oceans
     
    Started by sisenberg, Yesterday, 08:06 PM
    1 response
    16 views
    0 likes
    Last Post sisenberg  
    Started by PLeary, Today, 06:25 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_SergeyS  
    Started by sergey_z, Today, 06:17 AM
    0 responses
    4 views
    0 likes
    Last Post sergey_z  
    Working...
    X