• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to check custom calculation of previous bar

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

    How to check custom calculation of previous bar

    Hey guys,

    I have developed my own algorithm to plot a down or up arrow above/below the highs/lows of the current bar (upon close) if certain conditions are met.

    It is possible that the next bar could also meet the same conditions, however if conditions were met on the previous bar, I would not want to plot an arrow on the new bar.

    Is there a shorter way of checking if the previous bar had met the conditions or not, without having to recalculate for all conditions for the previous bar? I am looking for something along the lines of checking to see if the previous bar had an arrow associated with it or not. Is there a way of doing this?

    Asim

    #2
    Originally posted by asimbhuta View Post
    Hey guys,

    I have developed my own algorithm to plot a down or up arrow above/below the highs/lows of the current bar (upon close) if certain conditions are met.

    It is possible that the next bar could also meet the same conditions, however if conditions were met on the previous bar, I would not want to plot an arrow on the new bar.

    Is there a shorter way of checking if the previous bar had met the conditions or not, without having to recalculate for all conditions for the previous bar? I am looking for something along the lines of checking to see if the previous bar had an arrow associated with it or not. Is there a way of doing this?

    Asim
    Declare global variables:
    IDrawObject arrow;
    When you draw an arrow, please use this tagging logic to associate the arrow to a bar:
    string tag = "arrow" + CurrentBar;
    arrow = DrawArrowDown(tag, AutoScale, 0, High[0], Color.Red);

    or:

    string tag = "arrow" + CurrentBar;
    arrow = DrawArrowUp(tag, AutoScale, 0, Low[0], Color.Blue);
    Then you can check if there is an arrow for the previous bar:

    if (CurrentBar != 0) {
    string prevTag = "arrow" + (CurrentBar - 1);

    if (arrow != null && arrow.Tag == prevTag) {
    // there is an arrow for the prev bar, do your stufff here
    }
    }
    Not sure if there is a shorter solution?

    Thanks.
    Pi
    Last edited by ninZa; 01-01-2015, 07:05 PM.
    ninZa
    NinjaTrader Ecosystem Vendor - ninZa.co

    Comment


      #3
      Thanks ninZa, that's a good approach - other way I can think of would be using a bool to test if the arrow should be drawn or not and then updating the bool if the saved bar == CurrentBar + 1 so next bar.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        Thanks ninZa, that's a good approach - other way I can think of would be using a bool to test if the arrow should be drawn or not and then updating the bool if the saved bar == CurrentBar + 1 so next bar.
        You make me think of a very simple approach, perhaps the same as yours, but should it be saved bar == CurrenBar - 1, Bertand?

        Declare a global variable:
        int prevBar = -100;
        Every time you draw an arrow, update the prevBar as well:
        DrawArrow(...);
        prevBar = CurrentBar;
        So, you can check if the last bar has an arrow associated with it:
        if (prevBar == CurrentBar - 1) {
        // the last bar has an arrow, do your stuff here
        }
        Last edited by ninZa; 01-02-2015, 05:42 AM.
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment


          #5
          Thanks, you are correct - either savedBar == CurrentBar -1 or CurrentBar == savedBar + 1. Both should work fine.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            Thanks, you are correct - either savedBar == CurrentBar -1 or CurrentBar == savedBar + 1. Both should work fine.
            I see.
            Happy new year to you and all the Ninjas lol
            ninZa
            NinjaTrader Ecosystem Vendor - ninZa.co

            Comment


              #7
              Thanks, we wish you a Happy and successful 2015 as well!
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Bionian, Today, 10:10 AM
              2 responses
              17 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by D Trader, Today, 01:41 PM
              0 responses
              8 views
              0 likes
              Last Post D Trader  
              Started by rexmie888, Today, 04:00 AM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by terminatorT1000, Today, 01:23 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by Tradarr, Today, 12:25 PM
              0 responses
              10 views
              0 likes
              Last Post Tradarr
              by Tradarr
               
              Working...
              X