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

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

    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();}
        JesseNinjaTrader Customer Service

        Comment


          #5
          That's it. Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          601 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          16 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          229 views
          0 likes
          Last Post TradingLoss  
          Started by agclub, 04-21-2024, 08:57 PM
          3 responses
          17 views
          0 likes
          Last Post TradingLoss  
          Working...
          X