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

drawing a horizontal line on the stop level

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

    drawing a horizontal line on the stop level

    Hi
    i would like to draw an horizontal line on my stop level, i read the guide and write that script...but it doesn't work...

    SetStopLoss(CalculationMode.Price,High[0] + 3*TickSize);
    DrawHorizontalLine(
    "SetStopLoss", DashStyle.DashDot,Color.Black);

    #2
    Please see the syntax portion of the Help Guide article on DrawHorizontalLine().

    DrawHorizontalLine(string tag, double y, Color color)

    You need to provide a "double y" value for the line to be drawn at for the second parameter and not some DashStyle.

    DrawHorizontalLine("SetStopLoss", High[0] + 3 * TickSize, Color.Black);
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      oki i have a line but on all the historical graph... i can not have it just during the trade ? after the trade is closed don't see the line anymore ?

      Comment


        #4
        If you don't want the line anymore you need to remove the line.

        RemoveDrawObject("SetStopLoss");
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          sorry Josh... i wasn't clear, i want that the line remain on the chart as long as the trade is on the way... show an example below... i draw the line with a pen...

          Comment


            #6
            Thomas79,

            Just leave the line drawn and when you don't want it anymore type in RemoveDrawObject().

            DrawHorizontalLine() will draw a line all the way across the chart regardless of which bar you are at. If you only want line segments then use DrawLine().
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              thx Josh, that's work... the only thing is that works but just for the last trade on my graph, not the previous...

              also i can see it XX bar ago but how can i see for the coming bar... what i have to write on the 5th where i put 0... can i put +10 ? that not works....

              here my code :

              //set a stop 3 ticks above my shooting
              SetStopLoss(CalculationMode.Price,High[0]+ 3*TickSize);
              DrawLine(
              "SetStopLoss",false, 10, High[0] + 3 * TickSize, 0, High[0] + 3 * TickSize, Color.Red, DashStyle.Dot,2);

              Comment


                #8
                You need to give it unique string names. You are constantly using the same ID name and as such it will only draw one line. For each trade you need a new ID name.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  but it's impossible to give a new ID name for each trade... i have a lot of trade !

                  or may be there is a solution to automatically generate a new ID for each trade ?

                  here my code

                  //set a stop 3 ticks above my shooting
                  SetStopLoss(CalculationMode.Price,High[0]+ 3*TickSize);

                  Stop = High[
                  0]+ 3*TickSize;
                  DrawLine(
                  "Stop",false, 10, Stop, 0, Stop, Color.Red, DashStyle.Dot,2);

                  Comment


                    #10
                    Simply use something like this for creating unique tag ID's -
                    "Stop"
                    + CurrentBar
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      that's work, thx a lot !!

                      Comment


                        #12
                        I code to draw a horizontal line with a Tag1 and wish to use "RemoveDrawObject(Tag1)" three bars later. I cannot find a simple way to code three bars later. Can you help?
                        Last edited by Pete77; 03-23-2019, 03:29 PM.

                        Comment


                          #13
                          At the point where you draw your horizontal line, save the value of CurrentBar.

                          Code:
                          drawnAtBar = CurrentBar;
                          Now, you know that CurrentBar is always advancing, so three bars later is a very simple check,

                          Code:
                          if ((CurrentBar - drawnAtBar) == 3)
                              RemoveDrawObject("Tag1");
                          Make sure drawnAtBar is a private variable, declared at the top of your script, with the other
                          global variables.

                          Good luck!
                          Last edited by bltdavid; 03-26-2019, 06:04 PM.

                          Comment


                            #14
                            Thanks very much bitdavid. The term CurrentBar has always confused me, thinking it has to do with leftmost bars.

                            Comment


                              #15
                              Leftmost? Do you mean rightmost?

                              Bars on the leftmost end of your chart are the oldest.
                              Bars on the rightmost side of your chart are the newest, most recent bars.

                              CurrentBar is just a number, and it increments by 1 each time a bar (whether it be historical or real-time) is drawn on the chart.

                              The very first leftmost bar (scroll all the way to the left on your chart, yes, all the way) is numbered 0.

                              As such, "CurrentBar" is a concept applied equally to each bar (starting at 0) as they are drawn on the chart.

                              No one area, left or right, visible or not, scrolled off the chart or not, has providence over the CurrentBar value, except
                              to say this: as each bar is added to the chart, it receives the value of CurrentBar as a kind of unique "id" number, and
                              then CurrentBar is incremented by 1.

                              Make sense? From a 'CurrentBar' point of view, it's easy to see how real-time bars dove-tail nicely with historical bars. When
                              historical bars are first drawn on any chart, each bar gets a number, which always starts at 0, and increments by 1 for each
                              following bar. This counter is maintained by CurrentBar. Ok, so when the first real-time bar closes (called the historical to
                              real-time transition), it simply adopts the value of CurrentBar, and the counter keeps on incrementing by 1 on the close of
                              each additional real-time bar.

                              See that? CurrentBar is foremost a "counter" concept, and is used to identify each historical bar drawn on the chart. But the
                              counter value is not thrown away after all the historical bars are drawn. Nope, CurrentBar continues to increment and gets
                              used to identify each real-time bar as it closes, too.

                              Thus, CurrentBar keeps on going and going, just like the Energizer bunny, incrementing by 1 for each bar added to the chart.

                              So, if anything, CurrentBar is associated more with the right-side of your chart, not the left.

                              Because that's where the most current bar is drawn.
                              Last edited by bltdavid; 03-24-2019, 09:13 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by llanqui, Today, 03:53 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              15 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post strategist007  
                              Working...
                              X