Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

values and drawings + currenbar

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

    values and drawings + currenbar

    Hello,

    I found in the forum how one can plot eg different lines with adding "+currentbar" to the tagname of the drawing object (eg horizontal line).

    But what I didnt find and I want to ask please is how to store the values of each line so that the double can be used in conditions of the script and also the line can be removed (and double set to 0) when price crosses a drawingobject line.

    Thank you!
    Tony
    Last edited by tonynt; 11-06-2017, 10:30 AM. Reason: changed title

    #2
    Hello tonynt,

    Thanks for the post.

    It sounds like you might need a list of ILine objects.

    Please see this publicly available link on C#'s List class:
    Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.


    You could do something like the following to store the values of your drawing objects, ... denotes that I have left out code:

    using System.Collections.Generic;

    ...
    public class SaveLines : Indicator{
    private List<ILine> MyLineList; //Class level List object
    ...

    protected override void Initialize(){

    MyLineList = new List<ILine>();
    }

    protected override void OnBarUpdate() {

    if(CurrentBar < 10) return;

    MyLineList.Add(DrawLine("tag" + CurrentBar.ToString(), false, 10, Low[0], 0, 1001, Color.LimeGreen, DashStyle.Dot, 2));
    MyLineList.Add(DrawLine("tag" + CurrentBar.ToString(), false, 10, High[0], 0, 1001, Color.Red, DashStyle.Dot, 2));

    Print(MyLineList[0].StartTime);
    Print(MyLineList[0].EndTime);

    Print(MyLineList[1].StartTime);
    Print(MyLineList[1].EndTime);

    }

    To remove drawing objects, use RemoveDrawObject()

    https://ninjatrader.com/support/help...drawobject.htm - RemoveDrawObject()

    Please let us know if we may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 11-06-2017, 11:58 AM. Reason: syntax

    Comment


      #3
      Hello ChrisL,

      thank you for your reply. I´m thinking to work with a list as I do already for other purposes.

      But the core of my problem is what you mention in your last paragraph. How can I refer to a certain "tag+currentbar" to remove it? I´m using RemoveDrawObjects all the time and its working of course. But how to remove one of x-numbers with a condition? (if(Low[0]<=tag+currentbar && High[0]>=tag+currentbar) RemoveDrawObject("tag+currentbar");?

      Thank you!
      Tony

      Comment


        #4
        Hello tonynt,

        Thanks for the follow-up.

        You can store the tag string in a Dictionary as the key and store the IList object in the value field to create a lookup table like so :

        Code:
        private Dictionary < string, ILine > DrawingTable = new Dictionary < string, ILine > ();
        
        protected override void OnBarUpdate() {
            if (CurrentBar < 11) return;
        
            DrawingTable.Add(tag0 + CurrentBar.ToString(), DrawLine(tag0 + CurrentBar.ToString(), true, 10, Low[10], 0, Low[0], Color.LimeGreen, DashStyle.Dot, 2));
        
            DrawingTable.Add(tag1 + CurrentBar.ToString(), DrawLine(tag1 + CurrentBar.ToString(), true, 10, High[10], 0, High[0], Color.Red, DashStyle.Dot, 2));
        
            //You need to know the tag of the line object that you need information from before this next block.
        
        
            //
            if (Low[0] <= DrawingTable[tag0 + CurrentBar.ToString()].StartY && High[0] >= DrawingTable[tag0 + CurrentBar.ToString()].StartY) {
                RemoveDrawObject(tag0 + CurrentBar.ToString());
                DrawingTable[tag0 + CurrentBar.ToString()] = null;
            }
        }
        Hopefully, this example will help you do what you need to.

        Please see this publicly available link on the Dictionary class:


        Please let us know if we may be of any further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        557 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X