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

OnBarUpdate() did not trig

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

    OnBarUpdate() did not trig

    Hi

    I have Indicator named "KobiPAInd".
    I created Indicator named "KobiPAStartegyInd" .
    This Indicator call other indicator named "KobiPAInd" as follow:

    protected override void OnBarUpdate()
    {
    m_PAInd = KobiPAInd(0.2,m_Strength,m_SwingTime);

    if (!m_PAInd.Ready())
    return;
    }

    The problem is that the OBU of KobiPAInd wasn't called.
    I put a print in the OBU of KobiPAInd and also put a break point using a debugger but the OBU of KobiPAInd wasn't called.

    but when I called m_PAInd.Update(); every thing was OK!

    protected override void OnBarUpdate()
    {
    m_PAInd = KobiPAInd(0.2,m_Strength,m_SwingTime);
    m_PAInd.Update();

    if (!m_PAInd.Ready())
    return;
    }

    it doesn't matter if COBC set to false or true.
    calling Update() solve the problem . Why??

    thanks

    #2
    Hello levikNT,

    Thank you for your post.

    The indicator needs to have a barsAgoIndex reference to call it's value. For example:
    Code:
    m_PAInd = KobiPAInd(0.2,m_Strength,m_SwingTime)[B][0][/B];
    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you,

      It wouldn't work because m_PAInd is an indicator type and not a double type.
      the m_PAInd should be reference to KobiPAInd indicator.

      I did as your answer by reference the indicator to a barsAgoIndex :

      KobiPAInd m_PAInd = KobiPAInd(BarsArray[0],0.2,m_Strength,m_SwingTime)[0];

      but I get compiler error:
      "cannot implicitly convrer type 'double' to 'NinjaTrader.Indicator.KobiInd'

      Thanks,Kobi
      Last edited by levikNT; 11-21-2013, 11:52 AM.

      Comment


        #4
        Hello levikNT,

        Thank you for your response.

        Can you attach the indicators and/or strategies you are using to your response so I may investigate this matter further?

        You can find your files in the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom > select Indicator or Strategy respectively.

        I look forward to your response.

        Comment


          #5
          OnBarUpdate() did not trig

          Hi PatrickH,

          See attach of the two indicators.

          1. the primary indicator named "KobiPAStrtegyInd"
          2. the secondary indicator named "KobiPAInd "

          The KobiPAStrtegyInd indicator call KobiPAInd .

          I removed unnecessary code .

          I also Added two outcome files :

          1. WithoutUpdate.txt outcome file which show that the OBU of KobiPAInd not called.
          2. WithoutUpdate.txt outcome file which show that the OBU of KobiPAInd is called if I call the Update() mehods

          Thanks,Kobi
          Attached Files

          Comment


            #6
            Hello levikNT,

            Thank you for your response.

            Can you provide simplified versions of your indicators that reproduce this item?

            I look forward to your response.

            Comment


              #7
              OnBarUpdate() did not trig - continue

              Hello PatrickH,
              As your request I wrote a new two indicators that reproduce this item.
              see attach for this files.
              To clarify myself better here is the scenario :
              The main indicator named "KobiMainUtInd" contains an internal variable of KobiTest1 indicator type. The KobiTest1 is the second indicator.
              In the OBU function of KobiMainUtInd indicator I get a reference to KobiTest1.
              KobiTest1 m_Test1 = KobiTest1(1);
              This statement should trig the OBU of KobiTest1 indicator. but it does not make the job.
              but if I call m_Test1.Update() it works.
              I investigating this item more and it seemed that it is sufficient to call m_Test1.Update() only one time .
              there is no need to call the Update() every time the OBU of KobiMainUtInd indicator is trigged.
              using a the bellow statement as your proposal will rise an error since KobiTest1(1)[0]; will return a double an not a reference to KobiTest1 indicator.
              KobiTest1 m_Test1 = KobiTest1(1)[0];

              public class KobiMainUtInd : Indicator
              {
              bool m_First = true;
              KobiTest1 m_Test1;

              protected override void OnBarUpdate()
              {
              Print("KobiMainUtInd: BarsInProgress = " + BarsInProgress + " CurrentBar = " + CurrentBar + " Open = " + Open[0] + " Close = " + Close[0] + " High = " + High[0] + " Low = " + Low[0] + " " + Time[0].ToString());


              KobiTest1 m_Test1 = KobiTest1(1);

              // This statement will cause
              KobiTest1 m_Test1 = KobiTest1(1)[0];

              //Only if I call the Update of KobiTest1
              if(m_First)
              {
              m_Test1.Update();
              m_First = false;
              }

              Plot0.Set(Close[0]);

              }
              }
              Attached Files

              Comment


                #8
                Hello levikNT,

                Thank you for your response.

                When assigning indicators in this manner the indicator will not be updated until you call it in your code. So the Print() for the KobiTest1 is only called when Update() is called for the variable. Generally, this method of assigning the indicator to variable is used to avoid loading the indicator on every OnBarUpdate(), but if you want to do that you could simply cut out the variable and just call the indicator's method: KobiText(1)[0];

                For information on Indicator Methods please visit the following link: http://www.ninjatrader.com/support/h...indicators.htm

                Please let me know if I may be of further assistance.

                Comment


                  #9
                  Originally posted by NinjaTrader_PatrickH View Post
                  Hello levikNT,

                  Thank you for your response.

                  When assigning indicators in this manner the indicator will not be updated until you call it in your code. So the Print() for the KobiTest1 is only called when Update() is called for the variable. Generally, this method of assigning the indicator to variable is used to avoid loading the indicator on every OnBarUpdate(), but if you want to do that you could simply cut out the variable and just call the indicator's method: KobiText(1)[0];

                  For information on Indicator Methods please visit the following link: http://www.ninjatrader.com/support/h...indicators.htm

                  Please let me know if I may be of further assistance.
                  Thanks,

                  Sorry but I didn't understand the answer.

                  1. What do you mean by "this method of assigning the indicator to variable is used to avoid loading the indicator on every OnBarUpdate()" ? according to my understanding from the NT generated code the indicator is created as static (only 1 instance for a chart) and not loaded every time it is only updates data every new bar. when calling an indicator in that manner I assumed that I get a Pointer( reference) to this indicator.

                  2. As I mention in the previous reply it is necessary to call the Update ( ) only in the first time when the OBU called so, why a calling for one time is enough ?

                  3. cutting out the variable and just call the indicator's method: KobiTest1(1)[0]; rise a compiler error , did you try it in the files that I sent you?
                  Kobi

                  Comment


                    #10
                    Hello levikNT,

                    Thank you for your response.

                    1. NinjaTrader does not load a static value for the indicator. If I place the following line in OnBarUpdate() it will call the indicator on each bar: Print("SMA: " + SMA(20)[0]);. Can you expand on what you are attempting to achieve here with the indicator method as a variable?

                    2. Update() is a call to begin updating the indicator. Are you attempting to only have the indicator update once?

                    3. Calling the indicator by the barsAgo index worked on my end. Can you provide the full line of code that you used to call the indicator?

                    I look forward to your response.

                    Comment


                      #11
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello levikNT,

                      Thank you for your response.

                      1. NinjaTrader does not load a static value for the indicator. If I place the following line in OnBarUpdate() it will call the indicator on each bar: Print("SMA: " + SMA(20)[0]);. Can you expand on what you are attempting to achieve here with the indicator method as a variable?

                      2. Update() is a call to begin updating the indicator. Are you attempting to only have the indicator update once?

                      3. Calling the indicator by the barsAgo index worked on my end. Can you provide the full line of code that you used to call the indicator?

                      I look forward to your response.
                      Hello PatrickH,

                      Thank you for your response.

                      1.In your answer you used the statement Print("SMA: " + SMA(20)[0]);
                      This will work, but if you write
                      SMA(20)[0]; Without assigned the result of SMA(20)[0] to a variable it will cause a compiler error.
                      If I don't pass the SMA(20)[0] as input to a function and only update the called indicator it should be use like this:

                      double temp = SMA(20)[0];

                      2. The reasons that I want to assign an indicator to a variable are :
                      • avoid loading the indicator on every OnBarUpdate()
                      • I want to call the indicator methods to do something even without return a value
                      • Call a method to get a structure of data and not only one double.
                      • Programming convenient

                      My questionts are:

                      1. Does assign an indicator to a variable will achieve my purpose?
                      2. what is batter calling the Update() method or call an indicator with reference bar like SMA(20)[0]?
                      3. What's the difference?
                      4. Does calling an indicator like SMA(20)[0] will cause to reload the indicator again.? I want to avoid loading the indicator on every OnBarUpdate() !!

                      Thanks, Kobi

                      Comment


                        #12
                        Hello levikNT,

                        Thank you for your response.

                        Only when the variable you need to access does not have an IDateSeries type would you need to use the Update() method. Indicators are not loaded on each OnBarUpdate() when called via their method and barsAgo index. For example:
                        Code:
                        if(FirstTickOfBar)
                        Print("SMA: " + SMA(20)[0]); //This will not return an error and will only print on the first tick of the bar and only be accessed on the first tick of the bar.
                        In the event that an IDataSeries type class does not exist for the object type you wish to expose, you will need to use the Update() method within the property “getter” to ensure that OnBarUpdate() is processed and your calculated value is up-to-date.

                        Using any DataSeries will store calculated values associated to each bar in a chart and will allow any referencing objects to access the historical calculated values. This means that the OnBarUpdate() method of the indicator is processed prior to accessing the current bar’s value.

                        Please let me know if I may be of further assistance.

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello levikNT,

                          Thank you for your response.

                          Only when the variable you need to access does not have an IDateSeries type would you need to use the Update() method. Indicators are not loaded on each OnBarUpdate() when called via their method and barsAgo index. For example:
                          Code:
                          if(FirstTickOfBar)
                          Print("SMA: " + SMA(20)[0]); //This will not return an error and will only print on the first tick of the bar and only be accessed on the first tick of the bar.
                          In the event that an IDataSeries type class does not exist for the object type you wish to expose, you will need to use the Update() method within the property “getter” to ensure that OnBarUpdate() is processed and your calculated value is up-to-date.

                          Using any DataSeries will store calculated values associated to each bar in a chart and will allow any referencing objects to access the historical calculated values. This means that the OnBarUpdate() method of the indicator is processed prior to accessing the current bar’s value.

                          Please let me know if I may be of further assistance.
                          Hello PatrickH,

                          Thank you for your response.

                          Sorry, but I have some questions regarding this item

                          1. The NT "Swing" indicator has a property of DataSeries type "public DataSeries SwingLow" ,
                          within the property there is a call to the Update() method despite that the properties is from IDataSeries type, Why?

                          2. When CalculateOnBarClose = false and I need to access many properties of data that are not from IDataSeries, Can I assign the indicator to a variable and call the Update( ) method only once from outside, instead of calling the Update within each property?

                          3. If I interest only in the last indicator value that is not from IDataSeries type ,
                          and I access the indicator via BarsAgoIndex set to "0" for example MyIndicator()[0],
                          Would it trig the OnBarUpdate() ?

                          4. If the answer is Yes, What is better , using the Update( ) method or access the Indicator via BarsAgo Index?


                          Thanks, Kobi

                          Comment


                            #14
                            Hello Kobi,

                            Thank you for your response.

                            1. Update() can be used for any variable to force it to update via it's OnBarUpdate(). As you see in the Swing indicator the Update() is only called when the variable is called. This is used to pull the barsAgo int for the High or Low Bar: http://www.ninjatrader.com/support/h.../nt7/swing.htm

                            2. When setting the Update() in the property it only calls the Update() when the variable is called from another indicator or strategy.

                            3. Using the barsAgo index would in fact call the OnBarUpdate() for that indicator.

                            4. To call an indicator use it's barsAgo index for DataSeries values and the variable if the variable is set to use Update() within the code for the indicator you are calling.

                            Please let me know if I may be of further assistance.

                            Comment


                              #15
                              Originally posted by NinjaTrader_PatrickH View Post
                              Hello Kobi,

                              Thank you for your response.

                              1. Update() can be used for any variable to force it to update via it's OnBarUpdate(). As you see in the Swing indicator the Update() is only called when the variable is called. This is used to pull the barsAgo int for the High or Low Bar: http://www.ninjatrader.com/support/h.../nt7/swing.htm

                              2. When setting the Update() in the property it only calls the Update() when the variable is called from another indicator or strategy.

                              3. Using the barsAgo index would in fact call the OnBarUpdate() for that indicator.

                              4. To call an indicator use it's barsAgo index for DataSeries values and the variable if the variable is set to use Update() within the code for the indicator you are calling.

                              Please let me know if I may be of further assistance.
                              Hello PatrickH,

                              Thank you for your response.

                              Sorry but I need clarifications

                              1. From your previous answer you said that "Only when the variable you need to access does not have an IDateSeries type would you need to use the Update() method.", so the "Swing" indicator has a property of DataSeries type "public DataSeries SwingLow" and there is a call to Update() in order to force the OBU ,so according to your answer there is no need to call Update() .
                              So there is a conflict between your answer to the Swing Code?

                              2. You said that "Using the barsAgo index would in fact call the OnBarUpdate() for that indicator" ,so my question is If the Update( ) is forcing the call to the OnBarUpdate() and using the barsAgo index also would call the OnBarUpdate() , so which statement is preferred for barsAgo = 0 (the last bar)

                              Thanks , Kobi

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X