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

Proper Bollinger Indicator Syntax

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

    Proper Bollinger Indicator Syntax

    Hi there,

    I'm trying to snag some values from a Bollinger indicator I have on my chart (using 2 deviations in a 12 value span), and am getting a "cannot implicitly convert type 'ninjatrader.indicator.bollinger' to 'double'" whenever I try to pass the following code:

    Code:
    double BMiddle;
    
    BMiddle = Bollinger(2,12);
    The code example in the online Version 7 guide provides the following example for syntax:

    Code:
    Syntax:
    Bollinger(double numStdDev, int period)
    What am I missing here? Please help!
    Last edited by Spiderbird; 03-23-2015, 11:42 AM. Reason: I suck at spelling/grammar when I'm rushing things...

    #2
    Okay, I'm not thinking clearly. It needs a time frame value at the end to indicate which bar/time period it's reference. So it should look like:

    BMiddle = Bollinger(2,12)[1];

    ... to reference the previous bar's value.

    Thanks anyway, and please post if that isn't right.

    Comment


      #3
      Hello Spiderbird,

      Thanks for your post.

      The issue is that you are trying to take the contents of the BollingerBand indicator into a single variable. To fix the issue you need to specify which bar of the BollingerBand to use in the variable Bmiddle. So if you change to:
      BMiddle = Bollinger(2,12)[0]; // Gets the current bar, upper bollinger line value.

      if you wish to get the middle line of the bollinger then you might want to change to this:
      BMiddle = Bollinger(2,12).Middle[0]; // Gets the current bar, Middle bollinger line value.

      Similarly for the lower:
      BMiddle = Bollinger(2,12).Lower[0]; // Gets the current bar, Lower bollinger line value.

      To be consistent and clear in your code, I recommend to use upper:
      BMiddle = Bollinger(2,12).Upper[0]; // Gets the current bar, upper bollinger line value.

      Please let me know if I can be of further assistance.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Hi Paul!

        You must have been typing that up as I as doing my previous reply, but thank you for clarifying the code... especially the .middle value (I would have missed that).

        Quick question.. by getting the value of the current bar with [0], that would mean the value would change with every tick if my strategy was configured to calculate on a bar update. Is this correct?

        Thanks in advance!

        Comment


          #5
          Hello SpiderBird,

          Indeed our posts must have crossed and that's great that you saw the indexing need.

          With CalculateOnbarClose = true, then the value of [0] will refer to the just completed bar and the currently forming bar value is not yet known.

          With CalculateOnBarClose = false, then the value of [0] will refer to the bar that is forming and will change per tick.

          Please let me know if I can be of further assistance.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            That's exactly what I needed to know. Thanks again Paul!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by daniel_weber8, Today, 01:21 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Started by jungsoohuh, Today, 12:07 PM
            1 response
            23 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by SharonSS, Today, 11:54 AM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by crystalet, Today, 11:20 AM
            3 responses
            18 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by SuperDude123, Today, 09:23 AM
            1 response
            34 views
            0 likes
            Last Post NinjaTrader_JustinD  
            Working...
            X