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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        88 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        134 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        69 views
        0 likes
        Last Post PaulMohn  
        Working...
        X