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

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 pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    149 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    5 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    5 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,283 views
    0 likes
    Last Post Leafcutter  
    Working...
    X