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 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 arvidvanstaey, Today, 02:19 PM
              4 responses
              10 views
              0 likes
              Last Post arvidvanstaey  
              Started by samish18, 04-17-2024, 08:57 AM
              16 responses
              56 views
              0 likes
              Last Post samish18  
              Started by jordanq2, Today, 03:10 PM
              2 responses
              8 views
              0 likes
              Last Post jordanq2  
              Started by traderqz, Today, 12:06 AM
              10 responses
              18 views
              0 likes
              Last Post traderqz  
              Started by algospoke, 04-17-2024, 06:40 PM
              5 responses
              47 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X