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

Using MTF Indicator data OnBarClose = false

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

    Using MTF Indicator data OnBarClose = false

    I am developing an Indicator using Multiple Time Frame.

    The main time frame (BarsInProgress==0) is a smaller one (STF, for example: 5 Range), and the other time frame (BarsInProgress0 || ==1) is a higher one (HTF, for example: 8 Range).

    This indicator need to works IntraBar on both time frames. The indicator setup is "On Bar Close = false".

    On any change (in both time frames) I check my conditions, which is based on results of few indicators from both time frames. So I call each indicator return DataSeries, and based on the values calculate my condition.

    Everything works well, except the fact that I can't get the results of the HTF indicator values Intrabar. Since the STF is smaller then HTF, it changes more, so what I get is the last close values of the HTF, but not the current intrabar one. Calling the indicator, doesn't include the OnBarClose parameter.

    I know there is a solution, since I compare the results with BloodHound and they manage to get the HTF to reflect inrabar.

    Any ideas?

    P.S. I also sent the code to support (at) ninjatrade (dot) com title "Source code for post 426181"
    Last edited by Shai Samuel; 09-06-2015, 03:14 PM.

    #2
    Hello,

    I have received the code and will follow up with you through email.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, I have created a simple test indicator based on CCI, so I can demonstrate the issue. I actually found that there are 2 issues, not related, so I open a different ticket to the first one (426765).
      The question I have now, is more of understanding then an issue, since I found the way to make it works with multiple time frame.

      So the issue is about using
      Code:
              protected override void OnBarUpdate()
              {
      			// Checks to ensure all Bars objects contain enough bars before beginning
       			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
      				return;			// Checks if OnBarUpdate() is called from an update on the primary Bars
       			if (BarsInProgress == 0 || BarsInProgress == 1) 
       			{
       			   //... calculate my value
       			}
      to indicate changes in either the current time frame or the 2nd timeframe and calculate my value. This actually leads to wrong values displayed.

      If I only using only
      Code:
              protected override void OnBarUpdate()
              {
      			// Checks to ensure all Bars objects contain enough bars before beginning
       			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
      				return;			// Checks if OnBarUpdate() is called from an update on the primary Bars
       			if (BarsInProgress == 0) 
       			{
       			   //... calculate my value
       			}
      I get the correct results. This make no sense to me, and I would would love to understand it.

      In this example IBSimpleTest2 Indicator, the indicator check if CCI(14) is above or below a value (60) and get a signal in the direction:
      • The SignalType=CCIState just do this using the current timeframe.
      • The SignalType=CCIStateBoth uses also a higher timeframe with (BarsInProgress == 0), and gets the correct results.
      • The SignalType=CCIStateBoth uses also a higher timeframe with(BarsInProgress == 0 || BarsInProgress == 1), and gets the wrong results in some cases.


      I would appreciate to understand the logic here
      Attached Files

      Comment


        #4
        Hello Shai Samuel,

        As a test, I would suggest trying on if (BarsInProgress == 1) to see if you are getting the correct values with your secondary Bars object.

        Please note that when you have an OR between the BarsInProgress == 0 and BarsInProgress == 1 in your if statement, the code in this block will execute for both the primary Bars object and the secondary Bars object. Are you assigning values to the same variables inside of this if statement? If you are doing this, this may give you errorneous values as you will be assigning a different value to the same exact variable on each call of OnBarUpdate() by each Bars object.

        For more information about working with multiple time frames, please take a look at this link in the NinjaTrader help guide: http://ninjatrader.com/support/helpG...nstruments.htm

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Thanks Zachary for your support.

          I read all the help about Multiple Time Frame, but its clear I am still missing something. I am not sure I fully understand the function of BarsInProgress in a multiple time frame Indicator. As I read the help about BarsInProgress:
          BarsInProgress
          An index value of the current Bars object that has called the OnBarUpdate() method. In a multi-bars script, the OnBarUpdate() method is called for each Bars object of a script. This flexibility allows you to separate trading logic from different bar events. In a single Bars script this property will always return an index value of 0 representing the primary Bars and instrument the script is running on.
          what I understand, is that overtime the Chart #0 is changed OnBarUpdate() for BarsInProgress==0 is called, and overy time Chart #1 is changed OnBarUpdate() for BarsInProgress==1 is called. If this is the case, than if my indicator value is based on data from both charts should be fine with (BarsInProgress==0 || BarsInProgress==1). Clearly this is not the case, so I will appreciate further information regarding the function of BarsInProgress.

          Comment


            #6
            Hello Shai Samuel,

            Depending on whether you have CalculateOnBarClose set to true or false, OnBarUpdate() will be called on each respective Bars object on either every tick (if CalculateOnBarClose is false) or at the close of a bar (if CalculateOnBarClose is true).

            Can you please describe what your expected values are on each Bars object and what erroneous values you are getting with your code?

            Are you assigning the same variable to the values from both Bars object? Or are you assigning different variables to their respective Bars object values?

            For example, with the code below:
            Code:
            double theValue = 0;
            
            if (BarsInProgress == 0 || BarsInProgress == 1)
                 theValue = Close[0];
            theValue variable will be set to either Close[0] value from the first or secondary Bars object depending on when their respective OnBarUpdate() methods are called.
            Zachary G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Stanfillirenfro, Today, 07:23 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            2 responses
            19 views
            0 likes
            Last Post cmtjoancolmenero  
            Started by olisav57, Yesterday, 07:39 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cocoescala, 10-12-2018, 11:02 PM
            7 responses
            943 views
            0 likes
            Last Post Jquiroz1975  
            Started by oviejo, Today, 12:28 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X