Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding DataSeries possible off by one bar error?

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

    Adding DataSeries possible off by one bar error?

    I have quality data for 2 instruments, $GBPUSD and $EURUSD.

    GPBUSD is the pair that I am running a backtest on.
    My strategy code loads EURUSD data into a dataseries

    Code:
    otherprice = new DataSeries(this);
    Add("$EURUSD", PeriodType.Minute, BarsPeriod.Value);
    Open[0] refers to the current open price of GBPUSD and Opens[1][0] refers to the current open price of EURUSD.

    If all of my previous assumptions are correct, then I am noticing something odd. My output console reports that the Opens[1][0] returns the open price 1 bar late.

    $EURUSD sample data
    20071001 010000;1.4268;1.427;1.4267;1.4269;12
    20071001 010500;1.4268;1.427;1.4268;1.427;7
    20071001 011000;1.4271;1.4271;1.427;1.427;2
    20071001 011500;1.4271;1.4271;1.4267;1.4268;14
    20071001 012000;1.4267;1.4268;1.4264;1.4264;8

    $GBPUSD sample data
    20071001 010000;2.0453;2.0454;2.0453;2.0453;3
    20071001 010500;2.0452;2.0453;2.0444;2.0445;26
    20071001 011000;2.0446;2.0447;2.0445;2.0445;3
    20071001 011500;2.0446;2.045;2.0444;2.0444;19
    20071001 012000;2.0443;2.0443;2.0442;2.0443;5

    Output
    AT 10/1/2007 1:00:00 AM | GBP=2.0453 EUR=1.4265Diff= 0.6188 NormDIff = -1.24264685245949
    AT 10/1/2007 1:05:00 AM | GBP=2.0452 EUR=1.4268Diff= 0.6184 NormDIff = -1.63361918954248
    AT 10/1/2007 1:10:00 AM | GBP=2.0446 EUR=1.4268Diff= 0.6178 NormDIff = -2.07749124557629
    AT 10/1/2007 1:15:00 AM | GBP=2.0446 EUR=1.4271Diff= 0.6175 NormDIff = -2.1391276847069
    AT 10/1/2007 1:20:00 AM | GBP=2.0443 EUR=1.4271Diff= 0.6172 NormDIff = -2.15446197586889


    See how EURUSD is one bar off?
    The print statement was generated with this code.
    Code:
    Print("AT " + Time[0] + " | GBP=" + Open[0] + " EUR=" + diffPairOpen + "Diff= " + priceDifference + " NormDIff = " + ZScore);
    NT Admins? Any idea if this is truly a bug? Or if my code is simply incorrect?

    Thanks so much.
    -Shuli

    #2
    Sorry I don't understand the logic of your code below but please try applying your Print() statement if BarsInProgress==1 and both series should be in sync.

    Comment


      #3
      My Mistake

      NT Dierk,

      Thank you for pointing out my mistake. I think I understand what you mean now. For the reference of other users...

      The price of GBPUSD is printed when the current Bar being processed == 0 (this is by default if you only work with one instrument)

      The price of EURUSD is can only be printed accurately if the current bar being processed == 1 (because the data series resides in index [1])

      I made the error of trying to print out EURUSD (index 1) at say.. time 5, when the current bar being processed is the GBPUSD series (index 0) at time 5. Doing so effectively prints out the previous EURUSD price, at time 4, with GBPUSD's price at time 5. So if we specifically wait for BarsInProgress to == 1, in other words, waiting for the 2nd instrument to catch up, then the instrument prices will synchronize correctly.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,606 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      9 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      19 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      6 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      15 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X