Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error trying to compare two numbers

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

    Error trying to compare two numbers

    Whenever I try to compile a strategy, it gives me an error because of this simple condition:

    Code:
    Low[0] < Bollinger(LSBBndStDev, LSBBndPeriod).Upper
    Where LSBBndStDev = BolingerStDev and LSBBndPeriod = BolingerPeriod

    Error message:
    Code:
    Operator '<' cannot be applied to operands of type 'double' and 'NinjaTrader.NinjaScript.Series<double>'
    A workaround would be to use:
    Code:
    CrossBelow(Low, Bollinger(LSBBndStDev, LSBBndPeriod).Upper, 1)
    But as I tested this on the chart, it does not produce a desired outcome. For example, if price is at lower band, I enter long trade and set exit CrossBelow(Low, Bollinger(LSBBndStDev, LSBBndPeriod).Middle, 1), I expect it to exit on the next bar if Low[0] < Middle band. But it doesn't. It goes up, touches Upper band, and only exits, when it drops below Middle band again. This is not acceptable.

    #2
    Hello UltraNIX,
    Modify your code as:
    Code:
    Low[0] < Bollinger(LSBBndStDev, LSBBndPeriod).Upper[0]
    This is required because Bollinger Band Upper is a double series & Low[0] is a double i.e. low of current bar so you must compare BB upper band value at current bar.
    Hope it helps!

    Comment


      #3
      Hello UltraNix,

      Thank you for your post.

      s.kinra is correct. Both Low[ ] and Bollinger( ).Upper[ ] are Series<double> objects so your code would need to be adjusted so that Bollinger( ).Upper includes a barsAgo reference for the current bar. The code would look something like this.

      Low[0] < Bollinger(LSBBndStDev, LSBBndPeriod).Upper[0]

      Please see this help guide link for more information about the Bollinger Band - https://ninjatrader.com/support/help...tsub=Bollinger

      Let us know if we may assist further.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Thank you both, s.kinra and NinjaTrader_BrandonH, it worked!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        81 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        149 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        79 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        52 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        59 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X