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 nandhumca, Yesterday, 03:41 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by The_Sec, Yesterday, 03:37 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by vecnopus, Today, 06:15 AM
    0 responses
    1 view
    0 likes
    Last Post vecnopus  
    Started by Aviram Y, Today, 05:29 AM
    0 responses
    5 views
    0 likes
    Last Post Aviram Y  
    Started by quantismo, 04-17-2024, 05:13 PM
    3 responses
    27 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X