• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 rickyblah12, Today, 01:01 PM
            0 responses
            8 views
            0 likes
            Last Post rickyblah12  
            Started by dadarara, Today, 12:18 PM
            0 responses
            8 views
            0 likes
            Last Post dadarara  
            Started by joemiller, Today, 07:33 AM
            2 responses
            12 views
            0 likes
            Last Post joemiller  
            Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
            7 responses
            38 views
            0 likes
            Last Post DaveS
            by DaveS
             
            Started by claxxical, Yesterday, 10:00 PM
            0 responses
            13 views
            0 likes
            Last Post claxxical  
            Working...
            X