-3

How can I automatically buy or sell a currency pair (on a demo account), depending on whether a financial event is above or below it's forecast figure?

Obviously I know that many other factors affect the prices of currencies, but purely for the sake of learning, I would like to achieve this. I wanted to create a relatively simple algorithm but struggled to find any support.

Other relevant details / attempts to solve this:

  • Previously attempted setting up buy or sell market orders before a high economic impact, so that as soon as the price moved significantly in a certain direction the position would automatically be opened. Downside of this is the position may be opened slightly too late.
  • I will be closing the positions manually, once opened.
  • The buy and sell tickets will already be set up on the platform screen, with the position sizes already pre-determined and entered in.
  • Previously attempted waiting until the very second of a financial data release and clicking Buy / Sell (after planning for a few hours and finding potential relationships). This method is subject to human error, and is too slow.
p.luck
  • 646
  • 2
  • 9
  • 34
  • AHK can be used inside some platform, ie MetaTrader4 or Metatrader5(answer yes for both) and other platforrms, so it's better to mention your platform. for some platforms (ie MetaTrader for Android, other web platforms) it is quite difficult or unreliable – Daniel Kniaz Feb 17 '17 at 20:21

1 Answers1

3

Original text of this question was a bit different, about a year ago & this answer was accepted on:

Can Auto Hot Keys be used to buy and/ sell FOREX currency pairs?

Yes, but production-grade solution will use other means for this

While AHK and other UI-layer scripting tools allow to auto-click/auto-fill things, such approach goes against the running river.

For decades the common FOREX trading terminals had it's own programming tools, that allow platform-integrated means for implementing this and similar ideas.

Yes, right - "snobby"-motivated nice-to-look-at "also"-Terminals, that rely just on web-GUI-layer ( not the webAPI, just the browser-based GUI-layer ), need not provide such a fully-fledged toolset, but frankly speaking, who would risk any AUM ( be it private or fund-operated ) on any such web-kit if it were not market-wide accepted for several years already, just for the sake of some nice, "contemporary"-looking UI? Sure, MARCOM & PR people strive to convince users to do this, but this is about risk & money, right?

Let's take an EasyLanguage, MQL4, C# languages as an example.

FOREX trading can use those tools, that are provided by your Broker, be it a:

  • NinjaTrader's NinjaTrader with C# programming language
  • TradeStation's TradeStation with EasyLanguage programming language
  • MetaQuotes' MetaTrader Terminal 4 with MQL4 programming language
  • MetaQuotes' MetaTrader Terminal 5 with MQL5 programming language

Having mentioned these few, the key concept is to realise that your idea has been on table for several decades and professional trading-desk automation has tried many ways to handle this.

Result?

The best what one can do in this dilemma is to spend some time with Broker-supported software IDE toolchains to get acquainted with relevant programming model(s) -- some concepts might be rather surprising on one's first look, but have rather long tradition in time-sensitive / resources-efficient code-execution systems design, so be courage-full to master the principles, as your professional knowledge will gain a lot from this expertise -- as an example, MetaTrader4 Terminal is one such software platform, that allows you to launch:

  • 1x soloist Expert Advisor - as an event-driven code-execution algorithm per each MT4.Graph window
  • Nx concurrent Custom Indicator-s event-driven restricted code-base per each MT4.Graph window
  • 1x soloist Script asynchronous code-execution unit per each MT4.Graph* window

This inventory is quite important, as you have no other means how to automate complex Trading Algorithmisation but this ( sure, except the UI-layer automation, but which is blind with respect to all the trading-relevant contexts ( so quite pretty dangerous to take it seriously )).

Technical Indicators are executed under one common thread, which poses limitations for real-time robustness plus some restrictions apply for the permitted / forbidden operations that might be coded / compiled / executed in Indicator ( all aim at avoiding any and all possible blocking situations ( ref. solo-thread for all ... ) )

This said, you might have noticed, that both Expert Advisor and Technical Indicator-s are externally synchronised ( forget for the moment about a silicon-level details about non-parallel, shared thread execution with principal nanosecond scale of asynchronicity due to resource / code-execution scheduling ) and bound to externally issued anFxMarketEVENT in a form of an arriving signal ( once a price moves, MT4.Server sends QUOTE downstream message to the MT4.Terminal, a.k.a. a Tick ), which once ( if ) received, triggers MQL4 code-execution facilities on localhost:

  • OnTick(){ ...} # in case of Expert Advisor
  • OnCalculate(){...} # in case of Custom Technical Indicator

Why all this?

A good point -- well, FOREX is not an idyllic Eden, but rather a huge , fast & cruel Battlefield HELL. While the graphs paint on screen in silence, the Market roars as a never ending war between two immense-power forces evolves, nanosecond by nanosecond exchanging funds of more than about 5.300.000.000.000 USD value each day,
which is more than 615.000.000 USD / sec in average
and
your practical experience has already seen, what triple-hell chaos evolves, once Fundamental News appear to surprise the Titans who govern these mass-forces on the FOREX Markets.

This said, your code efforts shall rather use trading-platform integrated tools, than to rely on any externally emulated-fill&click proxies.

Nanoseconds do matter.

enter image description here

Do not hesitate to read more about algorithmic-trading and ask for more details.

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92