Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble with finding minimum bollinger band width (last n days)

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

    Trouble with finding minimum bollinger band width (last n days)

    Good day everyone, I have been stuck again.. and turning to you for help because I'm beginning to get demotivated
    Trying to describe my issue below. Thank you in advance for giving me a bit of your time.

    Aim :
    -----
    1. Find when width of bands was the lowest, in the last 50 days.

    protected override void BBwidth()
    {

    Calculate BBwidth = (Bollinger(2,20).Upper[0] - Bollinger(2,20).Lower[0])/SMA(20)[0];
    }

    protected override void OnBarUpdate()
    {

    Print (MIN(BBwidth(2,20), 50)[0]);
    }

    2. Print date on which width was lowest. (Not sure how to.. is it possible?)
    ========================================

    I am (still) struggling with the 'Strategy Analyzer' (Backtest -> Timeframe)

    My idea is that I should specify a timeframe where there is atleast 50 candles.

    For example if i specify timeframe as 01/01/2015 - 03/06/2015.. does the loop start from 01/01/2015 and look at 50
    previous candles to calculate MIN ? This is not what i want. I would like the MIN of 50 previous days from the latest trading day (03/06/2015 as of now).

    If i specify timeframe as 03/06/2015 - 03/07/2015 (with Onbarclose = false; and MinBarsRequired = 0; ) I am not able to get any results in the Output window.

    Could you help me with points 1. and 2. , please ?

    Thanks a lot,
    Vin

    #2
    Hello Vin,

    For context, is this being ran on a 1 Day bar type or is this on another bar type and interval? (Please specify)

    Comment


      #3
      Hello Patrick,

      Working with daily candlestick chart. I'm gutted I did not make it clear in my post earlier.

      Cheers,
      Vin

      Originally posted by NinjaTrader_PatrickH View Post
      Hello Vin,

      For context, is this being ran on a 1 Day bar type or is this on another bar type and interval? (Please specify)

      Comment


        #4
        Hello Vin,

        Thank you for your response.

        For the first item you could use LowestBar(): http://www.ninjatrader.com/support/h.../lowestbar.htm

        For the second item It will start calculating once 50 bars have processed since the start date and the minimum bars required have been meet. So if MinimumBarsRequired is set to 20 and your period is 50 you would need 70 bars from the start date to being calculating.

        Comment


          #5
          Hello Patrick,
          First of all thanks for the hint about the LowestBar(): I was not aware of it. Definitely going to come useful at some stage.

          However, my issue is that I have been trying to scan and locate areas where Bollinger bands are squeezed together. The approach I took is what i listed originally. I plan to write a function where I calculate Bollinger band width ( (bollingerupper - bollingerlower)/sma))

          Next step would be to use the MIN() function to find the day where bandwidth is lowest in the past 50 days, print the date and width, if possible.

          I hope you will be able to shed some light on this. Looking forward.

          Cheers,
          Vin



          Originally posted by NinjaTrader_PatrickH View Post
          Hello Vin,

          Thank you for your response.

          For the first item you could use LowestBar(): http://www.ninjatrader.com/support/h.../lowestbar.htm

          For the second item It will start calculating once 50 bars have processed since the start date and the minimum bars required have been meet. So if MinimumBarsRequired is set to 20 and your period is 50 you would need 70 bars from the start date to being calculating.

          Comment


            #6
            Hello Vin,

            Thank you for your response.

            Pass in your calculation as a Data Series to the Lowest Bar:
            Code:
            BBwidth.Set(Bollinger(2,20).Upper[0] - Bollinger(2,20).Lower[0])/SMA(20)[0]);
            Print(LowestBar(BBwidth, 50));
            For information on Data Series please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm

            Comment


              #7
              This looks great, Patrick, thanks a lot ! I will try it out later today

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bmartz, 03-12-2024, 06:12 AM
              4 responses
              31 views
              0 likes
              Last Post bmartz
              by bmartz
               
              Started by Aviram Y, Today, 05:29 AM
              4 responses
              11 views
              0 likes
              Last Post Aviram Y  
              Started by algospoke, 04-17-2024, 06:40 PM
              3 responses
              27 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cls71, Today, 04:45 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X