Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CalculateOnBarClose in strategy vs indicator

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

    #16
    Hello Chelsea,

    thank you for your reply.


    Referring b.) Do I understand right to simply set eg Variable1=1 when condition is true in onmarketdata and then to use in onbarupdate "if(Variable1==1 and FirstTickOfBar) then do"?

    Referring c.) how do you mean "plot to a secondary dataseries" please?

    Referring LiveUntilCancelled (not manually of course): this would be the same then as here with c.) means with a plot from secondary dataseries? Or would that be more easy? And "YES the secondary dataseries is using the same instrument".

    Thank you for your support
    Tony
    Last edited by tonynt; 09-16-2015, 10:25 AM. Reason: typo

    Comment


      #17
      Hi Tony,

      Basically yes, if you are using the Strategy Wizard you can use one of the user variables as a substitute for a bool. 0 for false 1 for true. This essentially becomes a trigger that is set only when a new bar arrives.

      When I mention plot to a dataseries, I really just mean that your 5 minute script is going to be making calls every 5 minutes and will only have a value from the indicator every 5 minutes when it calls it.

      Really I'm just now sure how you plan to use this information or what you are trying to do. If you want to store it, then you need a data series to store it.

      Below is a link to the help guide on the dataseries class.
      http://ninjatrader.com/support/helpG...ries_class.htm

      But to answer your question, yes, you can definitely add a secondary series to an indicator and do calculations with this, and then call the indicator from the strategy.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Chelsea,

        last try to this matter: When I have my conditions I need of primary dataseries in onmarketdata and I want to have also for secondary dataseries eg Closes[1][0]>Opens[1][0] does this work when I add this Closes[1][0]>Opens[1][0] in onmarketdata so that eg an entry is triggered when onmarketdata conditions on tickbasis are true AND the closes... of secondary dataseries? So that I dont need a variable and bring up secondary dataseries conditions closes... in onbarupdate seperately? With Closes[1][0]>Opens[1][0] I have then the COBCtrue for the secondary dataseries (even when this is coded in onmarketdata)?

        I hope I could translate correctly to describe what I mean.

        Thank you for your support!
        Tony
        Last edited by tonynt; 09-16-2015, 12:55 PM. Reason: explanation added

        Comment


          #19
          Hi Tony,

          Ok, so what I understand is you want to call the secondary series from OnMarketData. I think you want to distinguish which dataseries the tick is coming from that is updating OnMarketData, is this correct?

          The BarsInProgress is somewhat specific to OnBarUpdate. In otherwords, while the bar is building or closing, you will get OnMarketData updates for all dataseries sporadically as they come in. If both series are the same instrument, then OnMarketData will apply to both since they are both using the same prices. The bar series index doesn't matter here.

          If you using two different instruments, which have two different market update prices, then you can use the MarketDataEventArgs.MarketData.Instrument object to see what the instrument name is. This will distinguish between different instruments. When using the same instrument, it doesn't matter because the market update price is used for both data series.

          For example:
          Code:
          protected override void OnMarketData(MarketDataEventArgs e)
          {
          	Print(e.Price+" - "+e.MarketData.Instrument);
          }

          Now with that said, if you are calling your indicator from another indicator or from a strategy, how are you planning to pass that information you've gotten from OnMarketData to the caller indicator or strategy?
          Last edited by NinjaTrader_ChelseaB; 09-16-2015, 02:28 PM.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hello,

            thank you for your reply. To answer the question and to explain please:

            I refer only to ES and I have a strategy in a 1-min-chart with COBCfalse because I need IndicatorA with COBCfalse. And I have accurate conditions in onmarketdata. And I have indicatorA also in onmarketdata (as it works anyway with COBCfalse). All clear and this should work ok, yes?

            The other condition I need is closes[1][0]>opens[1][0] of my secondary dataseries which is a small range-chart. I read in the replies here that FirstTickOfBar doesnt work in onmarketdata. This I understand. But my question now is if its maybe not important for secondary dataseries if the condition is in onmarketdata or onbarupdate (as onbarupdate refers to the primary dataseries, no?). So, I think I could code the secondary dataseries closes[1][0]>opens[1][0]&&FirstTickOfBar in onmarketdata and in onbarupdate and should work same. Is this correct? NEW QUESTION that appears now when writing these lines is if its necessary to code FirstTickOfBar(dataseries2), if this code exists. I think its not necessary because as the condition is in onmarketdata it will be automatically the next tick after closes[1][0]>opens[1][0]???

            Thank you for your support
            Tony
            Last edited by tonynt; 09-16-2015, 03:27 PM. Reason: translation error

            Comment


              #21
              Hello Tony,

              I would not suggest using FirstTickOfBar in OnMarketData. See post #15 for a workaround.

              The code will not work the same as it works in OnBarUpdate.

              Please try and explain what you are trying to do without using an example.

              What I think you are asking is:

              "In OnMarketData, how do I tell what BarsInProgress is processing and if that update of OnMarketData is the first tick of a new bar for that BarsInProgress?"

              Can you simplify your question or let me know that this is what you are asking?
              Last edited by NinjaTrader_ChelseaB; 09-17-2015, 12:31 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hello Chelsea,

                thank you for your reply! Sorry for causing misunderstandings with my translations maybe.

                I understood that not to use FirstTickOfBar in OnMarketData. Lets get rid off FirstTickOfBar.

                Let me do the question again different: I work in a 1-minute-bar and I need to have the open and close of 4-Range-Bars (let say this is secondary dataseries). So I have in my conditions "if (SMA,20 primary dataseries rising && Closes[1][0]>Opens[1][0] then golong" will this work with having the strategy running COBCfalse when the Closes[1][0]>Opens[1][0] is in onbarupdate and will it work when I have it in onmarketdata?

                When the close of the 4-Range-Bar is before close of 1 Minute bar I want the entry, so the strategy has to run COBCfalse. But where in the strategy can I (or do I have) to put Closes[1][0]>Opens[1][0] so that the entry "golong" is done with the Close of 4-Range-Bar.

                I hope I could explain better this time.

                Thank you
                Tony
                Last edited by tonynt; 09-17-2015, 09:55 AM. Reason: typo

                Comment


                  #23
                  Hello Tony,

                  Yes, you can use Closes[1][bar index] and Opens[1][bar index] when Calculate on bar close is set to False.

                  You can also use these in OnMarketData and they will reference the same information.

                  What I want you to be aware of, is that OnMarketData and OnBarUpdate do not trigger at the same time.

                  Lets say you print Closes[1][0] in OnBarUpdate and also print this in OnMarketData when Calculate on bar close is False, you may get two different prices because the events were triggered at different times.

                  However, yes, that code will compile and will return the called information at the time of being called.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hello Chelsea,

                    thank you again for your reply. Yes, they will return the called information at the time of being called.

                    But when COBC==false, means it is called not with close of bar in onbarupdate but with every tick, why is then a difference to onmarketdata?

                    I thought all is clear now but I´m confused, sorry.

                    Thank you for your support.
                    Tony

                    Comment


                      #25
                      Hello Tony,

                      This means that there is no guarantee to the order that OnBarUpdate and OnMarketData are going to fire for any particular tick.

                      Specifically, I said this because FirstTickOfBar could possibly be skipped over completely in OnMarketData. I understand that you said to forget this, however, I just wanted to make you aware of the behavior.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Hello,

                        what is in this situation please:

                        I´m running a script-strategy on a 1-min-chart with COBCfalse. In onbarupdate I have condition for additional Range-Bar-Dataseries if (BarsInProgress==2 && "Closes[2][0]>Opens[2][0]" && FirstTickOfBar then enterlong".

                        Will the "enterlong" be with first tick of primary dataseries (= with next 1 minute bar) or with first tick of dataseries[2] (= open of next Rangebar, which I want to have).

                        Thank you
                        Tony

                        Comment


                          #27
                          Hello,

                          We are discussing about FirstTickOfBar and different dataseries and this doesn´t work when there are additional dataseries!

                          When I run a script-strategy in a 1-min-chart and in onbarupdate and for having an entry in a 2-RangeBar Reversal I code simply

                          protected override void Initialize()
                          {
                          Add(PeriodType.Custom2,1);//1
                          Add(PeriodType.Range,2);//2
                          }
                          if(Position.MarketPosition == MarketPosition.Flat
                          && BarsInProgress==2
                          && entryOrderkLa == null
                          && entryOrderkLb == null
                          && Closes[2][2] <= Opens[2][2] && Closes[2][2] < Highs[2][2]
                          && Closes[2][1] >= Opens[2][1] && Closes[2][1] > Lows[2][1]
                          && FirstTickOfBar
                          )

                          There is no entry!

                          It only works when I change the primary dataseries to the Range2 and remove "s[2]" from the code!

                          OR might it be that the problem occurs only with simulated datafeed? As I did the testing of different possibilites on the weekend with simulated datafeed.

                          Best
                          Tony
                          Last edited by tonynt; 09-20-2015, 03:41 PM. Reason: translation error

                          Comment


                            #28
                            Hi tonynt,

                            FirstTickOfBar will refer to the BarsInProgress that is currently processing.

                            If BarsInProgress is 2, then FirstTickOfBar will be for the Range bars when they close.

                            If the order is not making a trade, then add a print to find out why.

                            What prints from the following print?:
                            Code:
                            if (BarsInProgress == 2)
                            {
                            Print(string.Format("{0} | Position: {1} == Flat && BarsInProgress: {2} && entryOrderLa: {3} == null && entryOrderLb: {4} == null"
                            		+ " && Closes[2][2]: {5} <= Opens[2][2]: {6} && Closes[2][2]: {5} < Highs[2][2]: {7}"
                            		+ " && Closes[2][1]: {8} >= Opens[2][1]: {9} && Closes[2][1]: {8} > Lows[2][1]: {10}"
                            		+ " && FirstTickOfBar: {11}", Time[0], Position.MarketPosition, BarsInProgress,
                            		(entryOrderkLa == null ? "null" : "not null"), (entryOrderkLb == null ? "null" : "not null"),
                            		Closes[2][2], Opens[2][2], Highs[2][2], Closes[2][1], Opens[2][1], Lows[2][1], FirstTickOfBar));
                            }
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Hello Chelsea,

                              thank your for your reply. I added this with copy and paste of course to the "do-the-following-part of the script {}". But when there is a reversal-up-bar in the 2nd added dataseries (= Range2) there is no information in the output window, and no entry as well.

                              The script is running in a 1-min-chart.

                              Thank you
                              Tony
                              Last edited by tonynt; 09-21-2015, 01:54 PM. Reason: translation error

                              Comment


                                #30
                                Hi Tony,

                                I'm not quite sure what you did.

                                Have you added this as the first line of OnBarUpdate()?

                                Is this not printing anything? If so, then there is no BarsInProgress 2. If there were this should print. (Even if entryOrderkLa or entryOrderkLb are null it should just print that they are null)

                                Are you sure there are 2 added series to this script?
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by wzgy0920, 04-20-2024, 06:09 PM
                                2 responses
                                26 views
                                0 likes
                                Last Post wzgy0920  
                                Started by wzgy0920, 02-22-2024, 01:11 AM
                                5 responses
                                32 views
                                0 likes
                                Last Post wzgy0920  
                                Started by wzgy0920, Yesterday, 09:53 PM
                                2 responses
                                49 views
                                0 likes
                                Last Post wzgy0920  
                                Started by Kensonprib, 04-28-2021, 10:11 AM
                                5 responses
                                192 views
                                0 likes
                                Last Post Hasadafa  
                                Started by GussJ, 03-04-2020, 03:11 PM
                                11 responses
                                3,234 views
                                0 likes
                                Last Post xiinteractive  
                                Working...
                                X