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

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.
      Brandon H.NinjaTrader Customer Service

      Comment


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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RookieTrader, Today, 09:37 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by alifarahani, Today, 09:40 AM
        0 responses
        5 views
        0 likes
        Last Post alifarahani  
        Started by Gerik, Today, 09:40 AM
        0 responses
        4 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Started by KennyK, 05-29-2017, 02:02 AM
        3 responses
        1,283 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by AttiM, 02-14-2024, 05:20 PM
        11 responses
        185 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X