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 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.
    BertrandNinjaTrader Customer Service

    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 -

        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by nandhumca, Today, 03:41 PM
        0 responses
        3 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        6 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Started by frankthearm, Today, 09:08 AM
        10 responses
        36 views
        0 likes
        Last Post frankthearm  
        Working...
        X