Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw arrow

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

    Draw arrow

    Hi

    I'm trying to get to grips with ninjascript and at an early stage.

    I have tried to draw an arrow when close is above previous highest high and when I print it is giving me all candles where this is true when I switch the print statement with a Draw.Arrow it only draws one arrow on the candles. the important piece of the code is:

    if (Close[1]> MAX (High, MAHi)[2])
    {
    Draw.ArrowDown(this, "tag1", false, 0, High[0] + TickSize,
    Brushes.Red);
    }

    MAHi is simply the period for highest high.

    Any ideas
    thanks

    #2
    Hello fluke,
    Thanks for your post.

    I suggest changing your tag to include a not static value like "CurrentBar". Something like the following snippet would draw an arrow on every occurrence of a condition becoming true.
    Code:
    Draw.ArrowDown(this, "tag1"+CurrentBar, false, 0, High[0] + TickSize, Brushes.Red);
    Help Guide - CurrentBar
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh

      Solved. I understand how CurrentBar counts and changes each bar but just for a fuller understanding what was "tag1" actually referring to in the program - I didn't put it there myself I copied it from the language library.

      Comment


        #4
        "tag 1" is just the name of the object. You can set the tag to be whatever you like
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by fluke View Post
          Thanks Josh

          Solved. I understand how CurrentBar counts and changes each bar but just for a fuller understanding what was "tag1" actually referring to in the program - I didn't put it there myself I copied it from the language library.
          The purpose of "tag1" is to name-stamp the Arrow (or any draw object) with a string identifier so you can refer to it again later, using the same name "tag1".

          But, in your case, the real purpose is to understand that the if you call Draw.Arrow() fifty times all using the same tag name "tag1" you will only see 1 arrow printed on the chart -- Why? Because the first Draw.Arrow() draws the arrow on the chart, but the next 49 calls to Draw.Arrow() update the same draw object named by the tag name, which is "tag1" in this case.

          [You can see in your mind that Draw.Arrow() must be maintaining a C# dictionary of the arrow objects, such that the 'key' into the dictionary is that tag name string. If you keep supplying the same tag name to Draw.Arrow(), the dictionary lookup updates the same draw object each time, but if you specify a tag name not found in the dictionary, a new arrow object is created and added to the dictionary with the supplied tag name as its key.]

          If you want those 50 calls to Draw.Arrow() to draw 50 different arrows, then the tag name string must be unique.

          Thus, the entire purpose of using "tag1"+CurrentBar is to make that tag name string unique, so that each call to Draw.Arrow() draws a new arrow object.

          Make sense?
          Last edited by bltdavid; 05-28-2018, 12:18 PM.

          Comment


            #6
            Yes makes sense,

            thank you for replying in such detail

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            651 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            577 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X