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

DrawLine at Profit Target and Stop Loss

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

    DrawLine at Profit Target and Stop Loss

    I'm writing a strategy and I want to draw a line at both the Profit Target and the Stop Loss. However, I can't find the correct values/terms to use for either Profit Target or Stop Loss.

    I know my syntax for the DrawLine below is basicly correct, but I get errors for "profitTarget" or "setProfitTarget". Same for "stopLoss or "setStopLoss".

    DrawLine("SetProfitTarget" + CurrentBar, false, 3, setProfitTarget, 0, setProfitTarget, Color.Lime, DashStyle.Dash, 3);

    DrawLine("ProfitTarget" + CurrentBar, false, 3, profitTarget, 0, profitTarget, Color.Lime, DashStyle.Dash, 3);

    I'd also appreciate any help extending the line foreward a few bars. As written now it only draws a line 3 bars back. How can I draw it 3 bars foreward?

    Please help.

    Thanks!!!

    #2
    Hello dewurster,

    Thank you for your note.

    You will need to use the same code for the value of the SetStopLoss() and SetProfitTarget() as the y value of your line.

    For example:
    Code:
    SetStopLoss(CalculationMode.Ticks, Low[0] - (2 * TickSize));
    DrawHorizontalLine("Stop Loss", Low[0] - (2 * TickSize), Color.Blue);
    The example above shows that I use the Low[0] - (2 * TickSize) for both the value of the Stop Loss and the Line drawn.

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

    Comment


      #3
      Thanks for you reply, but drawing a horizonal line so far was not what I had in mind. I wanted to draw it only 2 -3 bars foreward of the entry condition. Using horisonal lines will result in may multiple horizonal lines and a great deal of confusion. Any suggestions?

      Comment


        #4
        Originally posted by dewurster View Post
        Thanks for you reply, but drawing a horizonal line so far was not what I had in mind. I wanted to draw it only 2 -3 bars foreward of the entry condition. Using horisonal lines will result in may multiple horizonal lines and a great deal of confusion. Any suggestions?
        Use a negative value for your line end.
        Code:
         
        DrawLine("ProfitTarget" + CurrentBar, false, 3, profitTarget, [B][COLOR=red]-3[/COLOR][/B], profitTarget, Color.Lime, DashStyle.Dash, 3);

        Comment


          #5
          Yes, I think -3 is the answer for drawing the line going foreward. (Obvious now!!!) That's part of the answer to my problem. Thanks!

          However, the other problem is that when I plug in your line of code I get the following error:
          "The name 'profitTarget' does not exist in the current context."

          I'm using the following code syntax:

          DrawLine(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color, DashStyle dashStyle, int width)

          For example the line below is the same syntax and works:

          DrawLine("InitialStopLoss" + CurrentBar, false, 1, initialStopLoss, 0, initialStopLoss, Color.Orange, DashStyle.Solid, 2);


          I can name the string tag anything but what I need is the "stardard name" of the profit target (and stop loss) in any standard strategy. In other words "int startBarsAgo" and "int endBarsAgo", for profit target and stop loss.

          What is that?

          Do you follow???

          Comment


            #6
            Originally posted by dewurster View Post
            Yes, I think -3 is the answer for drawing the line going foreward. (Obvious now!!!) That's part of the answer to my problem. Thanks!

            However, the other problem is that when I plug in your line of code I get the following error:
            "The name 'profitTarget' does not exist in the current context."

            I'm using the following code syntax:

            DrawLine(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color, DashStyle dashStyle, int width)

            For example the line below is the same syntax and works:

            DrawLine("InitialStopLoss" + CurrentBar, false, 1, initialStopLoss, 0, initialStopLoss, Color.Orange, DashStyle.Solid, 2);


            I can name the string tag anything but what I need is the "stardard name" of the profit target (and stop loss) in any standard strategy. In other words "int startBarsAgo" and "int endBarsAgo", for profit target and stop loss.

            What is that?

            Do you follow???
            No, I do not follow. There is no standard name. You define the name that you want and use it.

            If you get an error message that says that the name is not defined in the scope, either define it within scope, or define it to have Class scope (i.e., within the Variables region, or simply outside any of the event handlers, or methods).

            Comment


              #7
              I think I understand now. I set the profit target to the variable "longProfitTarget"

              SetProfitTarget("Long 1a", CalculationMode.Ticks, longProfitTarget);

              So I need to use that veriable in the LineDraw syntax.

              Sorry for the confusion. You were a big help!

              Thanks!!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              21 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X