Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

10 second onbar, trading on 5 mins time interval timing problems
 Post subject: 10 second onbar, trading on 5 mins time interval timing problems Post rating: 0   New post Posted: Sat 30 Nov, 2013, 04:47 
User avatar

User rating: 1
Joined: Mon 04 Mar, 2013, 10:46
Posts: 15
Location: Australia, Leichhardt
To dukascopy support and anyone who may have had the same problem and found an answer
I have a strategy timing problem.

This strategy was developed and backtested MANY times before running live with real money. The backtests included
a full year and generally have a timing (fill of order) delay of 0 to 10 seconds, which can be expected due to market
volatility etc.
But on live trading with 2 real money accounts I have run into problem trades where "sometimes" it has traded 1 to 2 minutes
after the 5M bar that had all correct indications to trade has completed, and this IS with the strategy running on the
dukas remote server, so internet delay can not be the explanation, or my local pc time.

I have attached a trade server log showing an example where it traded 355k EUR but 1min30seconds late, also if you
notice the trade log shows message of order "sent" at 15:01:30 and then order "filled" one second later. So as
far as I knew even if there was too much volatility at the time the "sent" time should have still occurred at 15:00:00 and
at worst, the filled status can get delayed or not filled.

I can even backtest this same day now and it works as expected opening a trade at 15:00:00 !!
So it seems the strategy does different things on live than backtesting and I cant find an explanation, so theres a bug
either in my code or the dukas code or the dukas remote server somehow runs at a delay of data and or time somehow.

And in summary everything I can read from the log says that the strategy sent the order request at 15:01:30

The strategy believed it was 15:00:00 too when it sent the order because of the log message from
the strategy "Sell opened by 10 SEC routine Current count 10sec: 30 Bar counter: 78"
Which means the current 10 sec bar number is 30 ( 30x 10sec = 5mins ) of the current 5 min interval,
and the 78 refers to how many 5 min bars have elapsed since starting the strategy.

For the life of me I cant see any problem in my code, here is a summary of how the 10 sec timing works and the
vital timing parts of the code:

Basically the code runs on 10sec bars, and generates an indicator filtered version of a 5min bar from the 10sec bars.
The 10sec bars are compared to a modulus of 5mins interval to synchronise (% 300000) and repeatedly synchronised
3 times every 5 min bar (just incase the process was busy when a counter was meant to be incremented), in addition
to this safeguard for synchronising, if the 10sec bars were out of synch (different than expected) there would be a
log message saying "SYNCHRONIZATION WARNING… info" and opening of trades would also be blocked by the
boolean "synchTestOk" till at least the next 10sec interval that has confirmed the timing counter match synchronisation.

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
{      if(period == Period.TEN_SECS && subInstrument == instrument && pipSet == true)
    {    tenSecCounter++;
       IBar this10sBar1 = history.getBar(subInstrument, Period.TEN_SECS, OfferSide.BID, 1);
       long timeThisBar1 = this10sBar1.getTime();
   
    /** 10 SEC Bar Counter Synch and 2 tests and re-sync ================ **/
       tenSecCounter = synchronize10sBars( tenSecCounter, timeThisBar1); /** === **/
    /** ================================================== **/


if (synchTestOk == true)
if(tenSecCounter == 30) // IS THIS THE COMPLETED 5 minute bar time?
{     if (entrySellOk == true)
   {  openSell  }
   if (entryBuyOk == true)
   {  openBuy  }
   
}
}
}
/* 10 SEC Bar Synch and 3 tests and re-sync  if required ============================================= */       
      private int synchronize10sBars(int counter, long timeofBar) throws JFException
    {  if (timeofBar % 300000 == 0)     // Does the start time of the prev 10sec bar equal the 5M timing
        {  if (counter !=31)
             {  if ( barCounter != 0 )
                console.getOut().println( "<<< SYNCHRONIZATION WARNING - Bar 1 correction ( wasnt 31 ) >>>" + "    Current count 10sec: " + tenSecCounter + "          Bar counter: " + barCounter);           
                synchTestOk = false;
             } else synchTestOk = true;
           counter = 1;            // Make the 30 bars counter synchronized
           //fiveMOpen0T = this10sBar1.getOpen();  // Get the OPEN PRICE of the prev 10sec bar  == 5min bar under construction.
        }
      if ((timeofBar-10000) % 300000 == 0)     // Does the start time of the prev 10sec bar equal the 5M timing + 10sec?
        { if (counter != 2)
            {  counter = 2;            // Make the 30 bars counter synchronized
               if ( barCounter != 0 )
               console.getOut().println( "<<< SYNCHRONIZATION WARNING - Bar 2 correction >>>" + "    Current count 10sec: " + tenSecCounter + "          Bar counter: " + barCounter);
               synchTestOk = false;
            } else synchTestOk = true;
        }
      if ((timeofBar-290000) % 300000 == 0)    // Does the start time of the prev 10sec bar equal the 5M timing + 290sec?
        { if (counter != 30)
            {  counter = 30;            // Make the 30 bars counter synchronized
               if ( barCounter != 0 )
               console.getOut().println( "<<< SYNCHRONIZATION WARNING - Bar 30 correction >>>" + "    Current count 10sec: " + tenSecCounter + "          Bar counter: " + barCounter);
               synchTestOk = false;
            } else synchTestOk = true;
        }
      return counter;
    }
Below I highlighted first log message for the order in question

Image


Attachments:
Trade Log Screen shot 2013-11-30 at 12.08.47 PM.png [210.13 KiB]
Downloaded 330 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: 10 second onbar, trading on 5 mins time interval timing problems Post rating: 0   New post Posted: Sat 30 Nov, 2013, 11:43 
User avatar

User rating: 96
Joined: Mon 09 Sep, 2013, 07:09
Posts: 287
Location: Ukraine, SHostka
Remote servers are overloaded. This is the main issue.


 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com