Quality Data, Quality Decisions: Why Web Scraping is Essential for Advanced Analytics
Gediminas Rickevičius·9 min
Once you click Start Now, you will instantly be given your account login details.
Here are your login details, you should also receive them in your email.
Go to your MT4, under File, click ”Login to Trade Account” and key in your account details.
Initial settings[/caption]
[caption id="attachment_14439" align="aligncenter" width="490"]
Your edit[/caption]
After you are done, click Ok. Open the Options again. The max bars should show a different number.
Click on the D1 button. This will select the daily chart.
Each data point on the chart represents one day when the daily chart format is selected.
Uncheck “Scroll the chart to the end on tick coming”. This will prevent the chart from auto-scrolling to the most current data.
In order to collect as much Amazon price data as we can, click on your Amazon chart and scroll back to earlier dates.
You can do this by scrolling with your mouse wheel. Alternatively, continuously click the Home button on your keyboard (this is faster).
Keep scrolling until the chart stops moving. That is the limit.
In your MetaEditor, the navigator should already be open. If it is not, open it here:
The navigator contains a list of MQL4 code in your computer that you can access.
Right-click on the “Experts” folder and click “Open Folder”. Put both mq4 files that you downloaded into this folder.
Refresh the list and you will see them there.
This portion will run every time a price change happens.
A trade is fired using the code from line 51 to 65. It uses the OrderSend() function to fire a trade.
Think of a function as an entity that takes in some input and does something or spits out some output.
In our case, OrderSend() takes in 11 pieces of information on the trade to be fired, and it fires the trade.
This is an explanation of the OrderSend() function:
Optional reading: you can read more about this function here via its documentation.
Line 49 will only happen if the If statements on lines 48 and 49 are True.
Line 48 checks if we have an existing trade. If we don’t, we move on to line 49.
We have left line 49 blank as this is where you need to code your entry rule.
The exit rule is coded for you as the 6th and 7th parameters in our OrderSend() function.
Ask price of Amazon is lower than the lowest price in the last 10 trading days (Original Statement)
Ask price of Amazon < the lowest price in the last 10 trading days // replace “less than” with the symbol “<”)
Ask < the lowest price in the last 10 trading days // replace “Ask price of Amazon” with “Ask”
Ask < Low price of the data point that contains the lowest price in the last 10 trading days
Ask < iLow(Symbol(), 0, (data point that contains the lowest price in the last 10 trading days)) // iLow() is a function that gives us the low price of a certain data point. More info here. The first input is the product we are trading. The second is the timeframe, 0 stands for default timeframe that we will set later. The third is the data point ID that we are getting the low price of.
Ask < iLow(Symbol(), 0, (iLowest(Symbol(), 0, MODE_LOW, 10, 1))) // iLowest() gives us the data point that contains the lowest price. More info here.
That is quite a handful. How would you have known to code iLow() and iLowest()?
The answer is, you wouldn’t.
When learning a new (non-programming) language, you won’t know what the words are for “yes” and “no”. You need to learn that from books, websites or friends.
Similarly, we do the same for programming languages. Thanks to Google, searching for programming help is easy.
Search for the term “MQL4 lowest price” and the solution should appear in the top 3 results.
Don’t worry if you don’t understand every part of the code for now. We are just building up your intuition at this point.
Insert that last line of code into your If statement in line 49.
You can take a look at BTFD_StockBot_Complete.mq4 now to compare the correct code to what you’ve coded.
Once done, click on the compile button.
The compile button checks for errors. If there are no errors, it creates a version of your code that the computer can read.
Key in the information as shown below. For the dates, make sure you choose a starting date where you have data for. To check this, scroll on your Amazon chart to the earliest point as shown in the earlier step.
This earliest point is the earliest date you can set your start date as.
Click “Start” when you are ready!
Okay, you’ve just done your first backtest of a trading algorithm! Congratulations!
Click on the Report tab to see the performance.
We’ve made $40K in the last 7 years with a starting capital of $50K.
Well, that sucks considering if you had just bought and held Amazon through it all, you would have made about $400K.
Just base on this backtest, I won’t say that algorithmic trading doesn’t work. Most algorithms are more complicated and intelligent than this.
However, this backtest does show that buying the dip aimlessly loses to holding. No surprise here, especially since the stock we’re trading is a rocket ship like Amazon.
To run live strategies, click the “Enable Automated Trading” button
Open Amazon’s price chart.
Open your navigator in MT4 (not the MetaEditor) if it isn’t already open.
When Amazon’s price chart is open, right-click on your algorithm and click “Attach to a chart”.
That’s it! It is live!
The moment you shut down your MT4, the algorithm will go offline. Thus, to run strategies 24/5, we set up our algorithms in the cloud.
If you want to remove the algorithm, right-click on the chart. Go to Expert Advisors/Remove.
Note that this strategy is just for educational purposes and we don’t recommend you run this strategy live on real money.
Moreover, this algorithm is stripped down to its bare bones so that its code is easy to understand. It doesn’t contain any risk management or notification systems.
Go make a cup of coffee and appreciate your work
0.5 minutes (Time elapsed: 25 minutes)
I hope you are feeling pretty good about yourself now.
Even if you do not plan to trade with algorithms, you can use them to test and improve your ideas. The trades can then be entered manually.
Hope you’ve enjoyed this guide!
Disclaimer: Being successful at algorithmic trading (or manual trading) is tough. It is not a get-rich-quick method and requires hard work.
If you want to code strategies that are 10X cooler, check out my online course with over 30K students! - AlgoTrading101.Real-time institutional flow data and trading signals for serious investors.
Explore DataDrivenAlpha →Instantly repurpose any DDI article into a professionally produced short-form video.
Try DDI Media →