Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing Horizontal Line Color

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

    Changing Horizontal Line Color

    I'm drawing a horizontal line intended to vary in it's Y axis placement and color. The variable Y axis placement is working as intended. As for the variable color I've studied numerous posted examples, but the compiler tells me Sytem.Windows.Media.Brush doesn't recognize the color variable ("TargetBrush") which I seem to have already established.

    if (Position.MarketPosition == MarketPosition.Long)
    { YaxisPlacement = Position.AveragePrice + 10*TickSize;
    Brush TargetBrush = new SolidColorBrush(Colors.Green);
    TargetBrush.Freeze();}

    if (Position.MarketPosition == MarketPosition.Short)
    { YaxisPlacement = Position.AveragePrice - 10*TickSize;
    Brush TargetBrush = new SolidColorBrush(Colors.Red);
    TargetBrush.Freeze();}

    Draw.HorizontalLine(this, "TargetLine1", true, YaxisPlacement, Brush.TargetBrush, DashStyleHelper.Solid, 2);


    What am I missing here?

    #2
    Hello Doctor JR,

    The error is letting you know what you used for the variable is not valid, it is expecting the actual variable and you had provided a string. "TargetBrush" is a string where TargetBrush is the variable you made. You would have to remove the quotes where you used TargetBrush.

    The sample code you provided would look like:

    Code:
    Draw.HorizontalLine(this, "TargetLine1", true, YaxisPlacement, TargetBrush, DashStyleHelper.Solid, 2);

    Please let me know if I may be of further assistance.

    Comment


      #3
      Now it's telling me "The name 'TargetBrush' does not exist in the current context"

      Comment


        #4
        Hello Doctor JR,
        It looks like you are defining the variable inside your conditions:

        Code:
        if (Position.MarketPosition == MarketPosition.Short)
        { YaxisPlacement = Position.AveragePrice - 10*TickSize;
        [B]Brush TargetBrush [/B]= new SolidColorBrush(Colors.Red);
        TargetBrush.Freeze();}
        You would either need to move the variable definition outside of the conditions and modifiy the conditions or move the Draw. statement inside each condition.

        Code:
        [B]Brush TargetBrush [/B]= Brushes.Red;
        if (Position.MarketPosition == MarketPosition.Short)
        { YaxisPlacement = Position.AveragePrice - 10*TickSize;
        [B]TargetBrush [/B]= new SolidColorBrush(Colors.Red);
        TargetBrush.Freeze();}

        Comment


          #5
          That's it. Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          368 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X