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 trilliantrader, Today, 03:01 PM
          2 responses
          17 views
          0 likes
          Last Post helpwanted  
          Started by ScottWalsh, Today, 06:52 PM
          2 responses
          17 views
          0 likes
          Last Post ScottWalsh  
          Started by cre8able, Today, 07:24 PM
          0 responses
          1 view
          0 likes
          Last Post cre8able  
          Started by Haiasi, Today, 06:53 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottW, Today, 06:09 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X