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 bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            16 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X