• 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

Multi-Time Frame

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

    Multi-Time Frame

    Hi

    I want to 2 indicators in multi time frame. I wrote an indicator PAInd that base its logic on 5 min bars but should update its data every 1Min. the indicator is expose an UpdateInd() method. the UpdateInd() call the Update() method in order to force a call to OnBarUpdate() every 1Min.

    I wrote another indicator PAStrategyInd that run on 1Min bar and call PAInd indicator.the PAStrategyInd call the UpdateInd() method of PAInd every 1 min.

    it seems that PAInd indicator data is update its data every 5Min and not every 1 min as expected.


    public class PAInd : Indicator
    {
    protected override void OnBarUpdate()
    { do something}
    public void UpdateInd()
    {
    Update();
    }
    }
    public class PAInd : Indicator
    {
    protected override void Initialize()
    { Add(PeriodType.Minute, 5);}
    protected override void OnBarUpdate()
    {
    if(BarsPeriod.Value != 1 || BarsInProgress !=0)
    return;

    PAInd m_PAInd = PAInd(BarsArray[1]);
    m_PAInd.UpdateInd();
    do something
    }
    }

    #2
    Hello,

    Do you mean that the PAInd only updates every 5 minute when called from the second indicator?

    Or are you saying that even the PAInd is updating every 5 minutes when running on itself?

    When you run these, what is your calculate on bar close set to? Do you declare CalculateOnBarClose in Initialize() in the PAInd?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Multi time fram

      Hi,

      1. sorry I typed wrong the second indicator name. The second indicator name is PAStrategyInd which run on 1 min bar and call PAInd indicator.

      2 . PAInd indicator is triggered every 1 min from the second indicator PAStrategyInd instead of every Tick, but the logic of PAInd is based on 5 min bar.

      3. PAStrategyInd call UpdateInd() PAInd method which call the Update() in order to trig OnBarUpdate() of PAInd every 1 Min

      4. CalculateOnBarClose of PAInd indicator is false
      5.. CalculateOnBarClose of PAStrategyInd indicator is true

      6. correct sample of my code:

      public class PAInd : Indicator
      {
      protected override void Initialize()
      {

      CalculateOnBarClose = false;

      }

      protected override void OnBarUpdate()
      {
      do something
      }

      public void UpdateInd()
      {
      Update();
      }
      }



      public class PAStrategyInd : Indicator
      {

      protected override void Initialize()
      {
      Add(PeriodType.Minute, 5);
      CalculateOnBarClose =true;

      }

      protected override void OnBarUpdate()
      {
      if(BarsPeriod.Value != 1 || BarsInProgress !=0)
      return;

      PAInd m_PAInd = PAInd(BarsArray[1]);
      m_PAInd.UpdateInd();
      do something
      }
      }

      Comment


        #4
        Hello,

        Originally posted by levikNT View Post

        4. CalculateOnBarClose of PAInd indicator is false
        5.. CalculateOnBarClose of PAStrategyInd indicator is true
        When running indicators that rely off of information from one another the Primary indicator (the one referencing the other indicator) both of them require to have the same COBC settings. If you set them differently in Initialize() it should run off of the primary's settings

        Depending on your end goal here you may not require the use of the Update() call however I'll need a little more info before I can determine this.

        It's my understanding PAStrategyInd is the primary indicator. Is this run on a 1 minute chart?

        You can set COBC = false and use First tick of bar to correctly get the values at the start of each bar instead of waiting for the 5 minutes close

        http://www.ninjatrader.com/support/h...ttickofbar.htm

        You will then want to setup your BarsInProgress conditional statement structure so that it evaluates accordingly. http://www.ninjatrader.com/support/h...nstruments.htm

        Let me know how I can further assist or clarify
        LanceNinjaTrader Customer Service

        Comment


          #5
          Multi-Time frame

          Hi,
          Sorry , but I didn't understood.

          My end goal is to get data in 1 Min bar accuracy from secondary indicator that run on 5 Min bar .

          1. PAStrategyInd is the primary indicator and its run on a 1 minute chart.
          The COBC of PAStrategyInd which is the primary indicator is set to true.

          2. The PAInd is the secondary indicator which run in 5 minute chart and its COBC = false.

          The primary indicator (which runs on a 1 min bar) is calling PAInd (which runs on 5 Min bar) .

          In order to update PAInd intenal data (which runs on 5 Min bar) every 1 Min, the PAStrategyInd (primary indicator) call PAInd indicator method named UpdateInd() that inside call the Update() function.

          The Problem is the PAInd indicator internal data is update every 5Min and not every 1 Min as excpected.

          The primary indicator is PAStrategyInd and run in 1 Min chart and look like this:
          public class PAStrategyInd : Indicator
          {
          protected override void Initialize()
          {
          Add(PeriodType.Minute, 5);
          CalculateOnBarClose = true;
          }

          protected override void OnBarUpdate()
          {

          if (BarsPeriod.Value != 1 || BarsInProgress != 0)
          return;

          m_PAInd = PAInd(BarsArray[1]);
          m_PAInd.UpdateInd();

          double X = m_PAInd.GetData();
          }
          }

          The Secondary indicator is PAInd and run in 5 Min chart and look like this:
          public class PAInd : Indicator
          {
          double x = 0.0;
          protected override void Initialize()
          {
          CalculateOnBarClose = false;
          }

          protected override void OnBarUpdate()
          {
          double x = Close[0];
          }

          public void UpdateInd()
          {
          Update();
          }

          public double GetData()
          {
          Update();
          }
          }

          Comment


            #6
            Originally posted by levikNT View Post
            Hi,
            Sorry , but I didn't understood.

            My end goal is to get data in 1 Min bar accuracy from secondary indicator that run on 5 Min bar .

            1. PAStrategyInd is the primary indicator and its run on a 1 minute chart.
            The COBC of PAStrategyInd which is the primary indicator is set to true.

            2. The PAInd is the secondary indicator which run in 5 minute chart and its COBC = false.

            The primary indicator (which runs on a 1 min bar) is calling PAInd (which runs on 5 Min bar) .

            The Problem is the PAInd indicator internal data is update every 5Min and not every 1 Min as excpected.
            This is because you are required to have both your indicators set to the same Calculate on bar close settings.

            You can achieve your goal by setting COBC = false on both indicators. By doing so you can have PAInd update it's value every tick, based off of the 5 minute bars it's running off of. If you wanted it to update only every 1 minute you could insert custom logic to using time checks such as DateTime.Now: http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx OR you could set everything to COBC = true and then manually calculate the 2nd indicator by combining information from a 5 and 1 minute series.

            When you set COBC = false you will have to change the PAStrategyInd to make it only run a calculation every minute. You can do this by using FirstTickOfBar: http://www.ninjatrader.com/support/h...ttickofbar.htm
            LanceNinjaTrader Customer Service

            Comment


              #7
              multi-time

              thank you for your response,

              I all ready tried these. I set both COBC of both indicators to false, so both indicators data should be updated every tick.

              I also used FirstTickOfBar (including referencing one bar back) while COBC of both indicators are set to false/

              I added Print log inside OnBarUpdate() of both indicators and it seemed that the secondary indicator (which is 5 min bars) is triggered every 5 Minutes and not every tick or 1 minute as expected.

              May be its not working because the entry condition in the primary indicator:

              if(BarsInProgress != 0) return;

              while the 5 min bar series index is 1 so, this series didn't trig the OnBarUpdate() of the 5 minute bar series.

              may I should remove this condition an do as follow:

              // BarInProgress = 1 is the 5 Min bar index
              if(BarInProgress == 1) {m_PAInd.UpdateInd();}

              // BarInProgress = 0 is the 1Min bar index - the primary bar series
              if(BarInProgress == 0) {do somthing}

              the questions are:
              1. is this the solution?
              2. what is the sequential of triggering OnBarUpdate() in Multi time fram? Is the primary bar series will be the first and after that BarInProgress 1 and so on ?

              3. If I use FirstTickOfBar can I run it on historical data and get the same results?

              thanks,Kobi

              Comment


                #8
                Originally posted by levikNT View Post

                // BarInProgress = 1 is the 5 Min bar index
                if(BarInProgress == 1) {m_PAInd.UpdateInd();}

                // BarInProgress = 0 is the 1Min bar index - the primary bar series
                if(BarInProgress == 0) {do somthing}

                the questions are:
                1. is this the solution?
                Yes I think this is the right approach. However you likely do not need to update the secondary indicator, but instead you can just reference the desired values. If you only need to access the secondary indicator values you can leave your script as is and call it like this from the BIP 0

                PAInd(BarsArray[1], your inputs);

                See the third section here on indicators for more info: http://www.ninjatrader.com/support/h...nstruments.htm

                2. what is the sequential of triggering OnBarUpdate() in Multi time fram? Is the primary bar series will be the first and after that BarInProgress 1 and so on ?
                If both series close at the same time (always the case when COBC = false) it will evaluate them in order in which they are added. So yes Primary series is first.

                3. If I use FirstTickOfBar can I run it on historical data and get the same results?

                thanks,Kobi
                This will depend on the script but most likely you'll need to add separate logic to handle historical and real time plots differently

                http://www.ninjatrader.com/support/h...historical.htm
                LanceNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by abfefmu, Today, 05:33 AM
                0 responses
                1 view
                0 likes
                Last Post abfefmu
                by abfefmu
                 
                Started by bbdjad, Today, 04:36 AM
                0 responses
                4 views
                0 likes
                Last Post bbdjad
                by bbdjad
                 
                Started by mittie3, Today, 03:33 AM
                0 responses
                7 views
                0 likes
                Last Post mittie3
                by mittie3
                 
                Started by Againmain1, Today, 03:04 AM
                0 responses
                8 views
                0 likes
                Last Post Againmain1  
                Started by tonytimpa, Today, 01:33 AM
                0 responses
                5 views
                0 likes
                Last Post tonytimpa  
                Working...
                X