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

Draw lines in strategy

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

    Draw lines in strategy

    Hi,
    I have a strategy and I would like to draws some lines, i am using the below code for that:
    Draw.Line(this, CurrentBar + "Upper", true, 1, somePrice, 0, somePrice, Brushes.Orange, DashStyleHelper.Solid, 1);
    Is it the right way ?
    If I want to make it Continuous (as shown in the second image in red), should i use Draw.VerticalLine ?

    Thanks
    Attached Files

    #2
    Hello yaniv,

    To make the lines continuous you would want to use a Plot instead of the drawing tools, it will be much more efficient. A strategy can also use plots just like an indicator so you could add a plot in the same way with AddPlot.

    In place of the drawing tool you would set the plots value:

    Value[0] = somePrice;

    That would connect the datapoints based on the plot style to avoid the gaps that you pointed out.

    If you otherwise continue using a drawing object there is not necessarily a way to actually connect the lines, you could use a vertical line to simulate that but the line will be plotted inside a bar and will not likely connect to the other drawn lines in an visually pleasing way.

    https://ninjatrader.com/support/help...ghtsub=addplot


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi,
      Well, i wrote the following lines into OnStateChange under the condition: State == State.SetDefaults
      AddPlot(Brushes.Pink, "Upper");
      AddPlot(Brushes.Pink, "Lower");

      and into OnBarUpdate event i wrote:
      Values[0][0] = <some_price>;
      Values[0][1] = <some_price>;

      and still can not see any plot on chart, i am using market replay (playback) running strategy onEachTick,

      What did i do wrong ?

      Thanks

      Comment


        #4
        The purposes of drawing these lines are:
        1. Drawing a StopLoss and TakeProfit line, only if I am in a position
        2. Drawing a certain price level that I calculate in OnBarUpdate (i would like to draw it only if it higher than 0 and it should be continuous line
        What is the correct way of accomplishing each of these goals?

        Thanks

        Comment


          #5
          Hello yaniv,

          Are you using OnRender in the script? If you did use OnRender but did not call the base.OnRender(...) then the plots will be hidden. Can you confirm that you do not have OnRender being used?



          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Hi,
            I just closed the chart and reopen it and now i can see the lines !!! Thanks, i do not know what was the problem.

            What about drawing a StopLoss and TakeProfit lines, only if I am in a position, should i use AddPlot or also Draw.Line for this purpose ?

            What if I also want to write the price above the line when using AddPlot but would like the previous price to be removed on each tick (exactly as in the volume profile indicator, image attached)

            Thanks
            Attached Files

            Comment


              #7
              Hello yaniv,

              For order lines you could use the drawing objects if you wanted to display data in a custom way. You can otherwise apply the strategy to a Chart and then the execution lines and plot markers will appear. Active orders can be displayed by having the chart trader panel open, that will allow the order lines to be displayed for the selected account.

              You could use Draw.Text to display text which moves with the bars. Using the same tag name for the object will allow it to update the existing one. The price could be used to position the text. If you need to offset it you could use Y offset for the text or the price using the formula
              Code:
              Close[0] + 5 * TickSize
              Which would offset from the close price by 5 ticks. Close[0] could be replaced with the plot.


              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by giulyko00, Yesterday, 12:03 PM
              3 responses
              12 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by habeebft, Today, 07:27 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_ChristopherS  
              Started by AveryFlynn, Today, 04:57 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Max238, Today, 01:28 AM
              4 responses
              39 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by r68cervera, Today, 05:29 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X