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

Historical crossover to Real time

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

    Historical crossover to Real time

    Hi,

    This isn't a code question, more of an approach question.

    I have an indicator I am working on that has a lookback period. The crossover period from Historical to real time is giving me fits.

    The calculation is complicated and has ramifications for many bars (even beyond the lookback period).

    Historical data works great but the crossover requires some of the calculations to be on the price[0] and some on [1] (I am using FirstTickOfBar).

    I have found using

    int barOffset = (Historical || CalculateOnBarClose) ? 0 : 1;

    and then using barOffset in place of [0] or [1] for real time solves everything but the crossover period.

    I have also found it helpful to color the first realtime bar when debugging a new indicator.

    I always feel with issues like this there is a simple solution that is eluding me. Does anyone have any suggestions as to how they deal with this issue?

    Best Regards,
    Scott

    #2
    Hello,

    Thanks for the forum post.

    I do not understand where the issue is however to be able to assist?

    As you should not need to do any of this.

    The crossover from historical to live is meant to be seamless. Why is it that your having to do all this code for this event?



    I look forward to assisting you further.

    Comment


      #3
      Brett,

      Possibly that is the issue, I shouldn't be doing anything; however, I tried that to no avail.

      If Historical = true, everything works fine; once I cross to real time it doesn't so I know I have some sort of error and my logic suggests it has to do with the crossover (again, possibly I am wrong in that assumption).

      If I am looping looking at opens for example and I start in real time on FirstTickOfBar = true then I have to start with an index of 1 to get the open from the last bar and an index of 2 gives me the open of the bar before that.

      However to do that same calculation in historical data, I start with an index of 0 and use an index of 1 to get the open of the prior bar.

      It seems like the starting offset should be the only variable so I must be doing something else wrong, given that I shouldn't have to worry about the crossover (where index = 1 gives me the last bar, etc.)

      That all makes logical sense, thanks.

      Best Regards,
      Scott

      Comment


        #4
        Hello,

        Heres what I suggest. We backup here. We take away the code your doing to fix the error with the crossover to historical to live.

        Then please let me know what (!) Specifically is the error from historical to live and I can assist you here.


        I look forward to assisting you further.

        Comment


          #5
          Brett, it isn't an error, it is that I am trying to move something from updating every tick (CalculateOnBarClose = false because I need every tick for another reason) to only calculating at the end of the bar (these particular calculations don't need to calculate tick by tick because the calculations only use OHLC).

          If I use a FirstTickOfBar test and I am in historical data Open[0] gives me the open of the current bar but if I am in real time Open[0] still gives me the open of the current bar but it is a 1 tick bar not the last complete bar as it would be in history.

          I was interested to know if anyone had a simple way around the issue.

          Best Regards,
          Scott

          Comment


            #6
            Hello,

            Open[0] should behave the same here: You would want to use Open[1] here for calculations when using First Tick of Bar. Open[1] would give the same behavior of this occuring on historical. You would need to adjust your code logic to run on Open[1] instead of [0].

            When an indicator or strategy runs on Historical. It always runs COBC=true. Since theres no way of looking intra bar. Therefor FirstTickOfBar does nothing for you on historical and is just like the indicator is running COBC=true.

            So when you got to live and then we have COBC = False. Now FirstTickOfBar comes into action. It is at this point that you will want to be accuratly looking at the bar behind it. Which will also work the same way in historical with Open[1].
            [
            Let me know if I can be of further assistance.

            Comment


              #7
              Brett, thanks for your help, I appreciate it.

              It is the historical to live crossover that is where I am having issues. As I said it isn't a code issue or a knowledge of how all this works, I amonly looking for a technique that will work seamlessly whether I am in historical or live.

              As you mention, once I am in live, because I am using FirstTickOfBar, I now have to look back 1 bar. This is what causes a code branch based on live vs. historical and what I am trying to avoid. It doesn't sound like there is any way around it.

              Best Regards,
              Scott

              Comment


                #8
                Hello,

                Unfortunately not.

                It will simply run different in backtest due to this. Since it always runs COBC = True on historical.

                Comment


                  #9
                  Hello Brett,

                  I have problem about my strategy(calculateonbarclose=false) and i'm search for solution and i see this post and i read it. But i don't understand that:

                  1.Suppose my onbarupdate event like this

                  if(FirstTickOfBar) { EMA(Close, 8)[1] > EMA(Close,13)[1]) EnterLong(); }

                  2.Open chart and add strategy this chart and look historical data it's not working correctly. Because historic data [0] current bar close [1] previous bar, actually i want to look last bar.

                  3.But this strategy works correctly in market replay because, market replay can process tick by tick so [1] last clossed bar [0] is the already processing bar.

                  SO, WHEN WE HAVE CALCULATEONBARCLOSE = FALSE IN STRATEGY AND WE NEED LAST PROCESSED BAR OHLC INFO, WHEN TEST THİS STRATEGY ON HISTORICAL DATA WE HAVE TO LOOK BACK "0", WHEN TEST THİS STRATEGY ON MARKET REPLAY DATA WE HAVE TO BACK "1".
                  AND
                  WHEN WE HAVE CALCULATEONBARCLOSE = TRUE IN STRATEGY AND WE NEED LAST PROCESSED BAR OHLC INFO, WHEN TEST THİS STRATEGY ON HISTORICAL DATA WE HAVE TO LOOK BACK "0" AGAIN, WHEN TEST THİS STRATEGY ON MARKET REPLAY DATA WE HAVE TO BACK "0" NOT "1".

                  IS CORRECT OR NOT PLEASE INFORM ME.

                  IF CORRECT AND IF WE WANT TO SEE HISTORICAL AND MARKET REPLAT TEST RESULT SAME TIME WE NEED WRITE THIS CODE IN ONBARUPDATE:

                  int barOffset = (Historical || CalculateOnBarClose) ? 0 : 1;
                  if (EMA(Close, 8)[barOffset] > EMA(Close, 13)[barOffset]) EnterLong();
                  if (CrossOver(Close, EMA(Close, 8)[barOffset], barOffset + 1) ExitLong();

                  (LIKE MENTIONED BELOW ScottB)

                  For ScottB : how is it going about this problem? You solve this problem like this?

                  Thanks.
                  Last edited by aytacasan; 08-24-2011, 02:24 AM.

                  Comment


                    #10
                    aytacasan, It has been awhile but I believe I had other issues in my code. I did get it to work using barOffset as you mentioned above.

                    My problem was I was calling an indicator from another indicator and had to sync the two using the same technique in the "lower" indicator. In the end, all you can do is use a lot (and I do mean a lot) of print statements and see where the issue is.

                    I do believe Brett's advice is correct. If you cannot figure it out after working with it for a while and you feel comfortable sending someone the code to check for you, if NinjaTrader support cannot, I will be glad to take a look at it.

                    Best Regards,
                    Scott

                    Comment


                      #11
                      Hi Scott,

                      Actually, I'm trying to develop profitable SYSTEM not strategy. I don't believe strategies for long term period.Ultimately strategies fail and you loss your many. Ok so why i'm trying to develop a strategy, because i'm looking for profitable system (for manual trading) but how can i know profitable or not? at this point i have to work with ninja and strategies. Actually I don't want this because i'm software developer and i'm developing programs for corporates almoust 15 years. So i bored write code Plus ninja have several bugs about testing and i don't have time for deal this rubbish. For example suppose you open 1.1.2011 - 30.1.2011 historical data and put the strategy on chart and look at output window there is no error or warning and start market replay, after a time you see strategy don't create orders then look again output window you'll see error about one day. What is interesting? this day before 30.1.2011(that time is time to start replay). I don't understand how it can be?

                      Thank you for your interest and friendly approach. I can share my indicators and strategies(actually this is the first) codes with you. For do this please send me an email address via private message.

                      Best Regards.
                      Aytaç Aşan

                      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