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

Multi TF Indicator (av. daily range on 5min)

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

    Multi TF Indicator (av. daily range on 5min)

    Hi,

    I'm trying to calculate the average daily range of the last 10 days without weekend data and display it on a non daily time frame.

    This is my code. Any ideas what is wrong? I've loaded 50 days of M5 data. The indicator displays only the current day's range.

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;

    Add(PeriodType.Day,1);
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] <= 15 || CurrentBars[1] <= 15) return;

    int i, c = 0;
    double hi = 0, lo = 0, sum = 0;

    for (i=1; i>=15; i++)
    {
    hi = Highs[1][i];
    lo = Lows[1][i];
    if (Times[1][i].DayOfWeek == DayOfWeek.Saturday || Times[1][i].DayOfWeek == DayOfWeek.Sunday) continue;
    else
    {
    sum = sum + (hi - lo);
    c++;
    if (c>=10) break;
    }
    }

    hi = CurrentDayOHL().CurrentHigh[0];
    lo = CurrentDayOHL().CurrentLow[0];

    if (i>0)
    {
    string objtext = "ADR = " + (sum/c/TickSize).ToString("N1") + " (" + c + " days) Today = " + ((hi-lo)/TickSize).ToString("N1");
    DrawTextFixed("ADR", objtext, TextPosition.TopLeft);
    }
    }

    #2
    td_910, thanks for the post - so the only visualization for the indicator is the drawing object, correct?

    With using only one tag here, you only update the ADR # drawn as you progress through the OnBarUpdate() in your script, you would not create a historical progression of values with this approach.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      This is by intend. The output looks like this for 6B today. "ADR = NaN (0 days) Today = 52.0"

      There seem to be no daily data being added/loaded in the script for some reason.

      The number from today is right - but the calc for this is based on "CurrentDayOHL()".

      The problem lies in here:

      hi = Highs[1][i];
      lo = Lows[1][i];
      if (Times[1][i].DayOfWeek == DayOfWeek.Saturday || Times[1][i].DayOfWeek == DayOfWeek.Sunday) continue;



      Comment


        #4
        Hi td_910,

        Is there any reason not to use the built in session template feature to control the days of week? The session template for the added series will be the same as primary series, so this would avoid the types of calculations you're trying to do manually to exclude weekend.

        You mention that the daily bars don't seem to be loading. Have you tried a simple implementation, just to access the values?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I changed the code to this. But still no success. I now use the Forex template.

          The output is: "ADR = 0.0 (1 days) Today = 64.0"


          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          Overlay = true;
          PriceTypeSupported = false;
          MaximumBarsLookBack = MaximumBarsLookBack.Infinite;

          Add(PeriodType.Day,1);

          }

          protected override void OnBarUpdate()

          {
          if (CurrentBars[0] <= 15 || CurrentBars[1] <= 15) return;

          double hi = 0, lo = 0, sum = 0;

          int i;

          for (i=1; i==10; i++)

          {
          hi = Highs[1][i];
          lo = Lows[1][i];
          sum = sum + (hi - lo);
          }

          hi = CurrentDayOHL().CurrentHigh[0];

          lo = CurrentDayOHL().CurrentLow[0];

          if (i>0)

          {
          string objtext = "ADR = " + (sum/i/TickSize).ToString("N1") + " (" + i + " days) Today = " + ((hi-lo)/TickSize).ToString("N1");
          DrawTextFixed("ADR", objtext, TextPosition.TopLeft);
          }
          }

          I even used:

          hi = Bars.GetDayBar(i).High;
          lo = Bars.GetDayBar(i).Low;

          but without success.
          Last edited by td_910; 02-02-2012, 12:23 PM.

          Comment


            #6
            First step I would take here is to get this concept working in a single series environment. I'm not sure if you're having general multiseries difficulties or if its due to the concept you're trying to code.

            See if you can get the ATR 5day-weekend-excluded concept there, and you could easily integrate it later into multiseries without having to change much code -- Just place the same single series working example (once you get it) within a BarsInProgress ==1 filter to run it on your daily time frame.

            You are going to have to manually calculate it like you're trying, since in some cases you need to index different bars than others. Also, keep in mind for FOREX session template, the "Monday" bar would comprise of trading starting at Sunday at 5:00PM, since bars are time stamped when they end.

            This sample is the closest we have to illustrate weekend handling and may give you some ideas to work from. Best of luck creating this.
            Last edited by NinjaTrader_RyanM1; 02-02-2012, 03:41 PM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by moneyexe, Today, 11:22 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by stevec1824, Today, 11:00 AM
            2 responses
            7 views
            0 likes
            Last Post stevec1824  
            Started by sofortune, Today, 10:05 AM
            2 responses
            10 views
            0 likes
            Last Post sofortune  
            Started by sofortune, 05-10-2024, 10:28 AM
            6 responses
            47 views
            0 likes
            Last Post sofortune  
            Started by ETFVoyageur, Today, 08:54 AM
            3 responses
            33 views
            0 likes
            Last Post ETFVoyageur  
            Working...
            X