1

Q1: Is it possible to create a script/algorithm that will purely place a BUY or SELL order of a selected currency pair, depending on whether e.g. an interest rate announcement is higher ( or lower ) than the forecast figure?

I know many other technical and fundamental factors must be taken in to account before buying and selling financial instruments, but purely as an experiment I'd like to determine if this method is possible.

If this can be achieved,
Q2: how can an interest rate announcement be embedded straight in to a script, so that once the figure has been released the BUY or SELL order is immediately executed?

Note: This will only be used on a demo trading account.

Previous alternative attempts to execute positions based on a fundamental data price reaction:

  • Setting up an automatic BUY and SELL orders, just before an interest rate announcement, and allowing a significant up or down price movement in one direction to automatically open a position ( the disadvantage with this is that the position is usually opened too late ).
user3666197
  • 1
  • 6
  • 50
  • 92
p.luck
  • 646
  • 2
  • 9
  • 34
  • Of course it is possible. Draft the algorithm on paper, in pseudocode or natural language as user stories, find documentation on the APIs you are about to integrate for (1) buying/selling and (2) interest rate announcements and then choose a programming language to implement this in. The algorithm itself is suitable for a discussion on StackOverflow, though you'll have to be a bit more specific I think, right now this question is too broad IMO. – Sergiu Paraschiv May 31 '16 at 17:20
  • Thanks for getting back to me so soon. Here's some details I think are important: Positions are manually closed after algorithm execution; position sizes will be pre- determined rather than the algorithm calculating them; I've come up with the possible relationships forming the basis of the algorithm. I understand my question hasn't shown much research effort- but I'm struggling to actually find documentation as to how I can achieve this. How can you access market event API's (is there a website that lists them)? Could you recommend a language? I'm proficient with PHP and javascript. – p.luck Jun 02 '16 at 15:22
  • I'm not really sure if latency is going to be important in your algorithm or not. That's the main thing you need to decide before choosing a programming language. Then you need to know what kind of maths is involved, there are specialized languages for that too. There's this http://quant.stackexchange.com/questions/tagged/algorithmic-trading – Sergiu Paraschiv Jun 02 '16 at 15:30
  • I'm not too sure what you mean by latency- is there a common language most traders use? I'll be sure to use that link as well, thanks. – p.luck Jun 02 '16 at 15:36
  • 1
    If your algorithm relies heavily on buying/selling at a certain exact price then you also need it to be _very_ fast. Think like this: EUR/USD sells at price 1.001 and your algorithm tells you you should buy. But the market is continually changing and that price is not going to stay there for a long time, most likely it's going to be 1.002 in five seconds, minutes or hours. If it's seconds, is your algorithm fast enough to cope with this change? And then you have to take execution speed into account. I'm pretty sure low level C is going to be a lot faster than JavaScript :) – Sergiu Paraschiv Jun 02 '16 at 15:41
  • Also, five seconds is probably too much in a lot of markets. I'm pretty sure automatic trading considers tens of a second too much. – Sergiu Paraschiv Jun 02 '16 at 15:42
  • I completely agree, the only reason I'm doing this is so that I can place an order instantaneously- my trading method on certain currencies seems to be relatively good, but for one recent trade on USD/EUR I was around 1 second too late to click sell and it lost me money. I'm going to look in to C and see what I can do. – p.luck Jun 02 '16 at 15:49
  • If it's about seconds then your main problem is going to be network latency. What information do you base your decisions on? Who offers the data and over what API? Test it and see how fast it is. Then, after you know how fast you can get the data, start thinking how fast you can process it and generate transactions. Then see how fast it is to actually send those transactions to the market. After that see how much you need to improve it and decide _what_ to improve based on this. – Sergiu Paraschiv Jun 02 '16 at 15:53
  • In my initial question I used interest rates as an example to make the question simpler. In reality, I'm actually basing the decision on the release of the US monthly Non-Farm Payroll figure, alongside the Unemployment Rate (both released at exactly the same time). I've back-tracked through 3 years of monthly data for these figures, and observed the price reactions of different combinations of the two (e.g. both above forecast, one above forecast/one below etc). I trade using CMC Markets who provide a countdown and instant release of this data, but the price moves before I can click buy/sell. – p.luck Jun 02 '16 at 16:04
  • That (very fast price movement) probably means people with a lot of money to spend already invested in software to automate this task :) Meaning your code needs to be at least as fast as theirs. – Sergiu Paraschiv Jun 02 '16 at 16:24
  • That's what I thought- it only seems to be that particular set of market events that triggers such a fast price movement. For other events like CPI and interest rates I can just manage to get in at the right time. – p.luck Jun 02 '16 at 16:32
  • There are people renting server space in the same datacenter as the exchanges themselves to minimize latency. I'm afraid competing with them on the same algorithms is going to be very hard. – Sergiu Paraschiv Jun 02 '16 at 16:38
  • Okay, well thank you very much for all of your advice! – p.luck Jun 02 '16 at 19:40

1 Answers1

1

A1: IF ... Yes, it is:

The idea is doable, however several externalities make it very sensitive to factors out of the scope your code can control.

Network transport latencies are not your worst enemy. These account for some 0.1 - 200 ms, depending from which location ( over which connectivity / services ) you try to source some remote / distant information and process them locally. For colocated hosting, this would be on the shorter end of this interval, for COTS office equipment this would be on the longer end.

Application-based transaction processing latencies are the next, more dangerous ones. Every XTO transaction is not happening in zero-time. The respective delays ( latencies ) are typically regularly recorded / monitored so as to have a in-vivo latency envelope for respective Market Access Agent / Broker Office. enter image description here Figures vary,
so does their over-relaxation
in the order of several orders of magnitude during Black-Swan event periods
or under high transactional load periods / XTO-traffic-storms. enter image description here

Spurious spread explosions
are your worst
,
while still hidden
from many views,
enemy. enter image description here On Fundamental News announcement, as you have reported above, you feel the time, but the hidden danger is not the linear time ticks, but the explosion of spread, i.e. the PriceDOMAIN area, where no-one can place / execute a trade ( an XTO ) to be filled, or a an explosed Trader's Margin Attack anybody has to carry, if there is an Equity exposed to a market risk during such period of time.

enter image description here

Translated into a plain english - no-one is principally able to click a button "in-time" after a US NFP and similarly seismic News announcement.


A2: HOW ... The algorithm will communicate with the news provider

The embedding is not the right expression, your algo-trading will have to become a part of a distributed-processing system, that altogether will form the trading-infrastructure.

Market Data Feed -- which delivers quote-stream updates to your local processing
Market Access -- where you place / cancel your XTO instructions
News Feed -- where you source macro-econ news from

Technical means used for sourcing News Feed's data are typically based / dependent on the agency commercial offerings / API specifications. While one of common FOREX trading platforms, the MetaTrader Terminal does offer a News service, mediated from Broker, one shall sooner or later realise that waiting for a Broker to re-publish the news is a dual-edged sword, because if your Broker / their Risk Management Control trades "against" one's positions, they have an unfair advantage of delayed announcement without any associated risk, which is not balanced into an equally fair, decision-making position for traders, who have their equity exposed to market risk. Next, your algorithmic tools have no News-reading API/interface to handle these events fully agorithmically once delivered into your localhost realm of MetaTrader Terminal so you will in either case remain dependent on external news-stream processor, that communicates with your code, in case of MetaTrader Terminal the MQL4-code in a distributed-system manner.

Having this said, your algo-trading strategy can cooperate with News Feed and execute decisions based on the content, published automatically ( typically faster than after the same announcement got fetched / evaluated / ( delayed ) / re-processed / re-published via other tertiary processors ).

The key in this is a viable XTO & failure-remedies strategy, to escape both the time-trap and the exploded spread-trap.

The Market does not wait a single [ms] see the FIX-Protocol API details on how many millions of EUR denominated value has been removed from L2-DoM just some 47 ms right before a nominal time of a News announcement: so this is a look into a microscope, how such gigantic holes appear in the PriceDOMAIN map ( painted by a Bid-pencil, whereas the Ask-side edge of the gap is not so easily visible, unless an extraordinary case happens as illustrated above )

14:29:59,953 <121402 MarketDataIncrementalRefresh (8=FIX.4.29=31135=X34=12140249=***52=20131206-13:29:51.55156=*****************62=20131206-12:37:09.000268=4279=0269=0278=264655=EUR/USD270=1.3654115=EUR271=2000000346=1279=2269=0278=265055=EUR/USD15=EUR279=0269=1278=265555=EUR/USD270=1.365615=EUR271=2000000346=1279=2269=1278=267755=EUR/USD15=EUR10=217)
|-------------------------------------------------(
                                                   8=FIX.4.2            ________FIX.8.BeginString           .aMessageHeaderBEGIN________________________________________<<HEADER>>
                                                   9=311                        FIX.9.BodyLength            .aMessageBodyLENGTH
                                                   35=X                         FIX.35.MsgType              .aTypeOfMESSAGE
                                                   34=121402                    FIX.34.MsgSeqNum            .aMessageSeqNUMBER              121402
                                                   49=***                       FIX.49.SenderCompID         .aSenderHostID
                                                   52=20131206-13:29:51.551     FIX.52.SendingTime          .aSenderTimeSTAMP               20131206-13:29:51.551
                                                   56=*************             FIX.56.TargetCompID         .aTargetHOST
                                                                        ________________________________________________________________________________________________<<HEADER>>
                                                   262=20131206-12:37:09.000    FIX.262.MDReqID             .aMarketDataRqstUUID            20131206-12:37:09.000        asString   .aMarketDataRqstUUID
                                                                        -----------------------------------------------------------------[*]----------------------------------------------
                                                   268=4                        FIX.268.NoMDEntries         .aMarketDataEntriesNUMBER       4
                                                                        -----------------------------------------------------------------[1]----------------------------------------------
                                                   279=0                        FIX.279.MDUpdateAction      .aMarketDataUpdateACTION        0               { 0: New, 1: Change, 2: Delete }
                                                   269=0                        FIX.269.MDEntryType         .aMarketDataEntryTYPE           0               { 0: Bid, 1: Offer, 2: Trade, 3: IndexVALUE, 4: aPriceOPEN, 5: aPriceCLOSE, 6: aPriceOfSETTLEMENT, 7: aTradingSessionPriceHIGH, 8: aTradingSessionPriceLOW, 9: aTradingSessionPriceVWAP }
                                                   278=2646                     FIX.278.MDEntryID           .aMarketDataEntryUUID           2646
                                                   55=EUR/USD                   FIX.55.Symbol               .aSYMBOL                        EUR/USD
                                                   270=1.36541                  FIX.270.MDEntryPx           .aMarketDataEntryPRICE          1.36541
                                                   15=EUR                       FIX.15.Currency             .anExplicitlyStatedCURRENCY     EUR
                                                   271=2000000                  FIX.271.MDEntrySize         .aMarketDataEntrySIZE           2.000.000 UoM/pieces
                                                   346=1                        FIX.346.NumberOfOrders      .aMarketDataEntryNumberOfORDERs 1
                                                                        -----------------------------------------------------------------[2]----------------------------------------------
                                                   279=2                        FIX.279.MDUpdateAction      .aMarketDataUpdateACTION        2               {} 2: Delete
                                                   269=0                        FIX.269                     .                               0               {} 0: Bid
                                                   278=2650                     FIX.278                     .                               2650
                                                   55=EUR/USD                   FIX.55                      .                               EUR/USD 
                                                   15=EUR                       FIX.15                      .                               EUR
                                                                        -----------------------------------------------------------------[3]----------------------------------------------
                                                   279=0                        FIX.279                     .                               0               {} 0: New
                                                   269=1                        FIX.269                     .                               1               {} 1: Ask/Offer
                                                   278=2655                     FIX.278                     .                               2655
                                                   55=EUR/USD                   FIX.55                      .                               EUR/USD
                                                   270=1.3656                   FIX.270                     .                               1.36560
                                                   15=EUR                       FIX.15                      .                               EUR
                                                   271=2000000                  FIX.271                     .                               2.000.000 UoM/pieces
                                                   346=1                        FIX.346                     .                               1
                                                                        -----------------------------------------------------------------[4]----------------------------------------------
                                                   279=2                        FIX.279                     .                               2               {} 2: Delete
                                                   269=1                        FIX.269                     .                               1               {} 1: Ask/Offer
                                                   278=2677                     FIX.278                     .                               2677
                                                   55=EUR/USD                   FIX.55                      .                               EUR/USD
                                                   15=EUR                       FIX.15                      .                               EUR
                                                   10=217               ________FIX.10.CheckSum______________________________________<<TRAILER>>            aTripleBYTE, asChar, ALGO ref. below
                                                  )

This illustrative sample was still quite exceptional for having just 4 items that have changed the EUR/USD pre-NFP announcement battle-field. Having done some quantitative empirical observations on "density of changes", enclosed you have a collection of LDF() data about how many FIX-messages contain between 10..380 aMarketDataUpdateACTION units:

max. value in FIX.268 ...== FIX.268.NoMDEntries   .aMarketDataEntriesNUMBER
                                                  |
                             1:   38774 x,  i.e. ~<  10 ..  19 > FIX.268.NoMDEntries per one FIX-Message delivered
                             2:   64764 x,  i.e. ~<  20 ..  29 > 
                             3:   27805 x,  i.e. ~<  30 ..  39 > 
                             4:   41307 x,  i.e. ~<  40 ..  49 >  
                             5:   17182 x,  i.e. ~<  50 ..  59 >  
                             6:   13640 x,  i.e. ~<  60 ..  69 >  
                             7:    5914 x,  i.e. ~<  70 ..  79 >  
                             8:    6544 x,  i.e. ~<  80 ..  89 >  
                             9:    3205 x,  i.e. ~<  90 ..  99 >  
                            10:    3150 x,  i.e. ~< 100 .. 109 >  
                            11:    1767 x,  i.e. ~< 110 .. 119 >  
                            12:    1432 x,  i.e. ~< 120 .. 129 >  
                            13:    1120 x,  i.e. ~< 130 .. 139 >  
                            14:     794 x,  i.e. ~< 140 .. 149 >  
                            15:     792 x,  i.e. ~< 150 .. 159 >  
                            16:     748 x,  i.e. ~< 160 .. 169 >  
                            17:     636 x,  i.e. ~< 170 .. 179 >  
                            18:     589 x,  i.e. ~< 180 .. 189 >  
                            19:     545 x,  i.e. ~< 190 .. 199 >  
                            20:     503 x,  i.e. ~< 200 .. 209 >  
                            21:     453 x,  i.e. ~< 210 .. 219 >  
                            22:     422 x,  i.e. ~< 220 .. 229 >  
                            23:     400 x,  i.e. ~< 230 .. 239 >  
                            24:     354 x,  i.e. ~< 240 .. 249 >  
                            25:     231 x,  i.e. ~< 250 .. 259 >  
                            26:     489 x,  i.e. ~< 260 .. 269 >  
                            27:     168 x,  i.e. ~< 270 .. 279 >  
                            28:     144 x   i.e. ~< 280 .. 289 >  
                            29:      48 x,  i.e. ~< 290 .. 299 >  
                            30:      42 x,  i.e. ~< 300 .. 309 >  
                            31:      16 x,  i.e. ~< 310 .. 319 >  
                            32:       6 x,  i.e. ~< 320 .. 329 >  
                            33:       8 x,  i.e. ~< 330 .. 339 >  
                            34:       5 x,  i.e. ~< 340 .. 349 >  
                            35:       2 x,  i.e. ~< 350 .. 359 >  
                            36:       4 x,  i.e. ~< 360 .. 369 >  
                            37:       1 x   i.e. ~< 370 .. 379 >

Good luck & aim well
on this
ultimately thrilling hunt!

user3666197
  • 1
  • 6
  • 50
  • 92