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

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
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        19 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X