Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder - way to know if previous bar(s) are red or green?

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

    Strategy Builder - way to know if previous bar(s) are red or green?

    I'm testing strategy to go long but wondering if there's a way to check whether previous closing bar was green or red, or closed bullish or bearish? I know it's not always reliable but I'm still interested if there's a way to do that so I can evolve strategy builder from there.

    #2
    Hi MatthewLesko,

    For the current bar, find the relevant part of the candle with these arrays: Open[0], Close[0], High[0], and Low[0]. Once the bar is open, then Open[0] will remain the same during the current bar lifecycle. High[0] and Low[0] are updated appropriately. Close[0] is constantly updated with the latest Last transaction price.

    Likewise, to find the previous bar and the bar before that, use Open[1], Close[1], High[1], and Low[1] for previous and Open[2], Close[2], High[2], and Low[2] the bar before the previous. Hopefully, you get the idea.

    So, to your question, now that we have the required information identified, try the following:

    bool IsPrevBarGreen = Close[1] > Open [1]; // sets IsPrevBarGreen to true is it the close is higher than the open for the previous bar.
    bool IsPrevBarBullish = Close[1] > Close[2]; // set IsPrevBarBullish to true if the previous bar close is higher than its previous bar close.

    Of course, depending on how your define bullish, you might have different logic for IsPrevBarBullish. Perhaps, you define it as the close is higher than the previous bar and the high is higher than the previous bar. If so:
    bool IsPrevBarBullish = Close[1] > Close[2] && High[1] > High{2];

    As you can see, with the Open, Close, High and Low arrays, you can perform significant amount of candle comparison logic to identify any candle pattern you're interested in.

    Hope that helps!
    Stealth

    Comment


      #3
      Hello MatthewLesko,

      What StealthM93 explained is correct, you can find more details about how to do price comparisons while using the strategy builder in the following link: https://ninjatrader.com/support/help...ataComparisons

      To check if the previous bar was red or green would require making a price condition, there is not a way to check if it was a specific color.

      Please let me know if I may be of additional assistance.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Realsmooth3, Yesterday, 09:10 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by wooofad, 06-15-2020, 01:08 PM
      8 responses
      93 views
      0 likes
      Last Post echoxray  
      Started by bubblegum, Today, 12:00 AM
      0 responses
      2 views
      0 likes
      Last Post bubblegum  
      Started by eseorvuda, Yesterday, 10:28 PM
      0 responses
      2 views
      0 likes
      Last Post eseorvuda  
      Started by ctrent, Yesterday, 09:58 PM
      0 responses
      5 views
      0 likes
      Last Post ctrent
      by ctrent
       
      Working...
      X