Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Line

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

    Draw Line

    I thought that this would be a simple task, but I am just not figuring it out.

    I am simply trying to draw a line from one place on a chart to another within NinjaScript.

    Let's just say
    if (x conditions are met)
    {
    "Draw line start at Low[5] and finishing at High[0]"
    }

    Can you point me in the right direction for this?

    Thank you

    #2
    jg123, a snippet for this case would be for example -

    if (CurrentBar < 5) return;

    DrawLine("tag", 5, Low[5], 0, High[0], Color.Blue);

    You need to keep in mind the CurrentBar check here, so if your test did not show > be sure to check the log tab first thing.

    Comment


      #3
      Yes, thank you. That definitely was the issue. I have to remember that check. It gets me often

      2 other issues that I am running into now.

      1.) I want the line to start at the top or bottom of a swing. I am, in its simplistic form, defining the top of a swing as:
      Code:
      if (High[0] > High[2]
      && High[1] > High[2]
      && High[3] > High[2]
      && High[4] > High[2])
      I want to remember the bar that is associated with High[2] and therefore I am trying to create a variable to do so. But it doesn't seem to work the way that I am going about it.

      Code:
      if (swing)
      {
      swingHigh = CurrentBar - 2;
      }
      but when I attempt to use swingHigh later in the code, it is calls the CurrentBar at the time that the swing was defined and not the actual swing bar. (hope that makes sense)

      How can I reference and hold the swing bar? Among other reasons, I want that in order to know how far back to place the line. For example in "int barsback" I would use "CurrentBar - swingHigh" which, theoretically, would then cause the original High[2] to be the starting point of my line.

      2.) The second issue that I am having is that it appears that the DrawLine, or the code that I am using, does not keep the line in place. I would like the line to stay put even when the chart progresses and new swingHigh's and swingLow's are created. (I want a line from swingHigh to swingLow and vice versa. Therefore, the finished product should look something similar to the ZigZag indicator (just using a very different calculation to accomplish it)

      Do you have any suggestions for that?

      Thank you!

      Comment


        #4
        jg123, I would expect the swingHigh variable to contain the saved value from the last time this code piece was called, correct. You offset that value to make up for the swing to be detected only after x bars, that should be fine. But still it would be saved from the last time your swing high was detected of course thus overwriting a prior saving triggered by the condition. One way to store a history of swing points would be for example a list or dictionary from more generic C#. Here you could for example use the swing price point as key and store the Currentbar -2 as value for it, so you know that pair in the future.

        For the draw objects generally, you want to make yourself familiar with this sample -

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        587 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        341 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        555 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X