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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        55 views
        0 likes
        Last Post CarlTrading  
        Working...
        X