Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optional Color Choice for drawing

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

    Optional Color Choice for drawing

    Doing something wrong... I want to provide optional color choices for a drawn rectangle. The following is failing:

    Draw.Rectangle(this, "MyBox"+g_startDateTime, g_startDateTime, highestHigh, g_endDateTime, lowestLow, MyBoxColor);



    ************************************************** ************************************************** **

    Parameters of the box perform correctly; box is not responding to color designations.

    The following are in place already:

    State.SetDefaults

    MyBoxColor = Brushes.RosyBrown;


    Properties

    [XmlIgnore]
    [Display(ResourceType = typeof(Custom.Resource), Name = "MyBox Color", GroupName = "Colors", Order = 1)]
    public Brush MyBoxColor { get; set; }

    [Browsable(false)]
    public string MyBoxColorSerialize
    {
    get { return Serialize.BrushToString(MyBoxColor); }
    set { MyBoxColor = Serialize.StringToBrush(value); }​

    I read the library on this, just not getting it ...

    #2
    Hello johnMoss,

    Thank you for your inquiry.

    Please see the attached sample script which demonstrates how to create a user defined color input.

    It looks like you are on the right track with setting up the color property for the drawn rectangle. However, there might be a small issue with how the color is being passed or serialized. Here is a step-by-step guide to ensure everything is correctly set up:

    First, ensure your color property is correctly defined and serialized:

    Code:
    //in the Properties section
    [XmlIgnore()]
    [Display(Name = "MyBoxColor", GroupName = "NinjaScriptParameters", Order = 1)]
    public Brush MyBoxColor
    { get; set; }
    
    // Serialize our Color object
    [Browsable(false)]
    public string MyBoxColorSerialize
    {
    get { return Serialize.BrushToString(MyBoxColor); }
    set { MyBoxColor = Serialize.StringToBrush(value); }
    }
    In the State.SetDefaults section, initialize the default color:​
    Code:
    MyBoxColor = Brushes.RosyBrown;
    When you draw the rectangle, ensure you are correctly using the MyBoxColor property.



    Ensure that the property changes are correctly reflected in your strategy or indicator. You can add a Print statement to verify the color property before drawing:

    Code:
    Print("MyBoxColor: " + MyBoxColor);
    If the rectangle still does not respond to the color designation, ensure that no other parts of your code are overriding the color or resetting the MyBoxColor property.​​

    If you are still having trouble creating the input after reviewing the sample, please let me know. ​
    Attached Files

    Comment


      #3
      Hi Gaby,

      Thank you for your response. Please note the original query, my properties serialization was slightly different but still valid. I plugged in yours and no effect. Looking at the code line again here:

      1) Draw.Rectangle(this, "MyBox"+startDateTime, startDateTime, highestHigh, endDateTime, lowestLow, MyBoxColor);

      ​What's happening is 'MyBoxColor' at the end here is only painting the borders. I want to paint the fill area as well. I've tried several configurations code-wise to no avail. For example:

      2) Draw.Rectangle(this, "MyBox"+startDateTime, startDateTime, highestHigh, endDateTime, lowestLow, MyBoxColor, MyBoxColor, 50);

      yields the error

      ​No overload for method 'Rectangle' takes 9 arguments.

      What am I missing?

      Just FYI, I am modifying an indicator that was using a template. So in example 1 above, I simply replaced the "MyBoxColor" template with the user definable color option. The single problem here is my Draw.Rectangle method is flawed...

      Comment


        #4
        This is from the library link you provided:

        Draw.Rectangle(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, Brush areaBrush, int areaOpacity)


        I'm curious as to why this code is invalid. I agree with you it doesn't work.

        Brush here is the outline; areabrush is the fill. Is this true, [code invalid], or do I have a referencing error in the midst?

        I read through the link you provided; forgive me, it is a bunny trail maze of obfuscation relative to SharpDX properties & functions sans any usable examples to see application. Lost ...
        Last edited by johnMoss; 05-30-2024, 12:04 PM.

        Comment


          #5
          Hello johnMoss,

          My apologies!! I deleted my previous reply because it was wrong. You definitely are able to use Draw.Rectangle to fill in the brush.

          Did you take a look at the SampleBrushInput script? This demonstrates being able to change the area color of a rectangle drawn with Draw.Rectangle.

          If you still aren't able to change the color following the example, would you mind sharing a reduced sample of your script so I can test?

          Comment


            #6
            Well G back atcha ... My mistake also, didn't read out the sample brush logic. Missing ingredient on my end was the autoscale bool. All good now thank you

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 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
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X