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:
Original text of this question was a bit different, about a year ago & this answer was accepted on:
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:
C#
programming languageEasyLanguage
programming languageMQL4
programming languageMQL5
programming languageHaving 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.
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 windowNx
concurrent Custom Indicator-s event-driven restricted code-base per each MT4.Graph window1x
soloist Script asynchronous code-execution unit per each MT4.Graph* windowThis 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
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.
Do not hesitate to read more about algorithmic-trading and ask for more details.