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

Calling Draw Arrow

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

    Calling Draw Arrow

    If I store the CurrentBar in the string for DrawArrowDown (or Up), could I then convert that back to an int and subtract the stored CurrentBar from the current CurrentBar and get an index?

    #2
    Hello smclrr,

    Thank you for your post.

    You could, but you could also just save that current bar to an int variable and not have to cast the string back to an int. I'd probably go that route for clarity, as it might not be clear why you're using the tag for a drawing object to get a bar index later.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      If I started saving them to a variable, I would have to create a variable to store it in, yes? Or can a script create a variable? I do not really know what I am doing.

      I just saved the currentbar to each arrow that is draw byt the script and saw an opportunity to maybe use that. Does that require a lot to convert the string to an int?

      Comment


        #4
        Hello smcllr,

        To store a drawing object would require creating a variable. If you have a lot of objects you could make a List to collect drawing objects.

        You could use the arrows existing Anchor property to find the bars ago or time it was placed on so you don't need to worry about converting the Tag to an index.

        A simple example of finding the objects Time or BarsAgo looks like the following:

        Code:
        ArrowDown myArrow = Draw.ArrowDown(this, "tag1", true, 0, High[0] + TickSize, Brushes.Red);
        Print(myArrow.Anchor.Time);
        Print(myArrow.Anchor.BarsAgo);
        If you had a lot of objects you could use a C# list to hold all of the items and later loop over them. There is information on using lists in the following link:

        Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.


        A very simple example of a list in NinjaScript would be the following:

        Code:
        List<ArrowDown> myArrows = new List<ArrowDown>();
        
        protected override void OnBarUpdate()
        {
            ArrowDown myArrow = Draw.ArrowDown(this, "tag1", true, 0, High[0] + TickSize, Brushes.Red);
            myArrows.Add(myArrow);
        }
        The myArrows list could be used later to loop over and find certain objects or do an action for each object like checking its bars ago.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Today, 06:40 PM
        0 responses
        1 view
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        6 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        167 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        8 views
        0 likes
        Last Post cre8able  
        Working...
        X