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

How to know if an arrow exists on the previous bar?

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

    How to know if an arrow exists on the previous bar?

    My indicator occasionally draws up arrows like this:

    DrawArrowUp("MyArrowUp" + CurrentBar, false, 0, y, Color.Black);

    I would like to know if there is such an arrow on the previous bar, and if yes, do something.

    Something like:
    if (DrawArrowUp("MyArrowUp" + CurrentBar - 1) exists
    then do something

    Thanks

    #2
    Originally posted by sixteencorners View Post
    My indicator occasionally draws up arrows like this:

    DrawArrowUp("MyArrowUp" + CurrentBar, false, 0, y, Color.Black);

    I would like to know if there is such an arrow on the previous bar, and if yes, do something.

    Something like:
    if (DrawArrowUp("MyArrowUp" + CurrentBar - 1) exists
    then do something
    In what context?

    From within the same indicator?
    From within a different indicator?
    From within a strategy?

    Did you write this indicator?
    Can you attach the source of your indicator?

    Drawing an Up arrow or Down arrow does not, by definition, leave a "breadcrumb" for you to interrogate later to see if an arrow was drawn. You'll have to design your own "breadcrumb" code so that you can check if an arrow exists, and on what bar (if you need that, too).

    Such code is not hard, but the design can vary based upon the context in which you want to do the future interrogation. For example, if you want to check this from a strategy, the usual way is leave "breadcrumbs" using a DataSeries or a BoolSeries.

    If someone else wrote the indicator, chances are this "breadcrumb" code may already be in there. But if you're the sole author, then you'll need to write it yourself.

    Comment


      #3
      Hello sixteencorners,

      Thanks for your post.

      Member bltdavid has offered some valued considerations.

      One approach you could take would be to create an int variable to store the bar number of where the last arrow was drawn and then your code would test to see if the current bar minus the saved bar is equal to 1 indicating that indeed an arrow was applied on the previous bar. The value of CurrentBar is the bar number (Reference: http://ninjatrader.com/support/helpG...currentbar.htm) of the bar being processed.

      For example, assume you have created an integer variable called savedBar.

      if (Your conditions to draw arrow)
      {
      DrawArrowUp("MyArrowUp" + CurrentBar, false, 0, y, Color.Black);
      savedBar = CurrentBar; // store the bar the latest arrow is drawn on
      }

      if ((CurrentBar - savedBar) == 1)
      {
      // do something here
      }
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thank you, problem solved. So easy it is embarrassing!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by swestendorf, Today, 11:14 AM
        0 responses
        1 view
        0 likes
        Last Post swestendorf  
        Started by Sparkyboy, Today, 10:57 AM
        0 responses
        3 views
        0 likes
        Last Post Sparkyboy  
        Started by TheMarlin801, 10-13-2020, 01:40 AM
        21 responses
        3,917 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by timmbbo, 07-05-2023, 10:21 PM
        3 responses
        153 views
        0 likes
        Last Post grayfrog  
        Started by Lumbeezl, 01-11-2022, 06:50 PM
        30 responses
        812 views
        1 like
        Last Post grayfrog  
        Working...
        X