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 do you determine an "Up" or "Down" bar?

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

    How do you determine an "Up" or "Down" bar?

    I would like to know if a given bar was a black or white candlestick (Red or Green). Was the bar an "Up" or a "Down"? (if(Open[0] > Close[0])) I was hoping for something really simple (custom code) or NTD out of the box.

    Your ideas are very much appreciated!

    Thank You,
    Robert
    Last edited by RobVig; 06-02-2016, 04:41 PM.

    #2
    That looks good to me.

    Comment


      #3
      Originally posted by RobVig View Post
      I would like to know if a given bar was a black or white candlestick (Red or Green). Was the bar an "Up" or a "Down"? (if(Open[0] > Close[0])) I was hoping for something really simple (custom code) or NTD out of the box.
      As mentioned by Sledge, you're already there.

      However, I've devised many one liners that help me in these cases.

      Eg, instead of your example, I'd use,

      Code:
      if (IsBarDown)
      {
        // same as your Open[0] > Close[0]
      }
      Using the Compare method, documented here,


      I have this code in my toolbox,

      Code:
      protected int ComparePrice(double PriceValue1, double PriceValue2)
      {
          return Instrument.MasterInstrument.Compare(PriceValue1, PriceValue2);
      }
      
      /* --------------------------------------------------------------------------------------------------- */
      
      protected bool IsBarUp { get { return ComparePrice(Close[0], Open[0]) > 0; } }
      protected bool IsBarDown { get { return ComparePrice(Close[0], Open[0]) < 0; } }
      protected bool IsBarUpDoji { get { return ComparePrice(Close[0], Open[0]) >= 0; } }
      protected bool IsBarDownDoji { get { return ComparePrice(Close[0], Open[0]) <= 0; } }
      protected bool IsBarDoji { get { return ComparePrice(Close[0], Open[0]) == 0; } }
      protected bool IsBarSuperDoji { get { return ComparePrice(High[0], Low[0]) == 0; } }

      Comment


        #4
        Thanks Guys!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        8 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        98 views
        1 like
        Last Post caryc123  
        Working...
        X