Australian (ASX) Stock Market Forum

Joined
12 February 2014
Posts
138
Reactions
25
Thats right folks, you heard it. Exclusive only to Aussie Stock Forum Members. You will of not seen this anywhere else in the world. Here (pause) I use METATRADER'S own indicators to perform a scan on the whole EOD ASX listed securities (pause), which filters out stocks that do not pass certain conditions "as seen on tv" :)

This thread assumes that you have already created the 2100+ metatrader 4 history files (containing ASX stock quotes) by following my instructions for either the free Yahoo Finance Data thread:

https://www.aussiestockforums.com/forums/showthread.php?t=28615

or the thread for the serious trader who downloads from a paid data service such as Premium data or Data HQ:

https://www.aussiestockforums.com/forums/showthread.php?t=28692

As usual, I will attach files and explain in later posts. I have attached files DLLMTSCAN.dll and SymbolScan.mq4. After downloading, you need to put them in the metatrader 4 directories as shown below:

MTSCAN_Step1.PNG
 

Attachments

  • DLLMTSCAN.dll
    477 KB · Views: 137
  • SymbolScan.mq4
    2.5 KB · Views: 116
Re: Worlds First METATRADER 4 ASX EOD Stock Market Scanner/Screener/Filter

Next you need to open up Metatrader 4, select menu tools/options, click on Expert Advisors tab and change the settings to the following:

MTSCAN_Step2.PNG


We need to allow DLL imports. Click OK to continue.

Next open up a chart say EURUSD (we need a chart to execute a script).

Now on the Navigator Pane, scroll down to Scripts and expand it, right click on SymbolScan and select "Execute on Chart".

Here my script will execute a scan as seen below (look in bottom Terminal pane/experts tab for live scan in action):

MTSCAN_Step3.PNG

The scan I have chosen is a search for all stocks whose slow stochastic (14,3,3) has fallen below 20 or risen above 80 in the last 2 days including the current day. They must also have a 30 day average turnover of $15 million (that's outrageous). I have displayed 2 charts to show stochastic is doing what it is supposed to. In the next post I will explain the code.
 
Re: Worlds First METATRADER 4 ASX EOD Stock Market Scanner/Screener/Filter

So to view the mql code, select Tools/MetaQuotes Language Editor.

In MetaEditor, Navigator Pane, open SymbolScan.mq4.

There are basically 2 main parts here, the first is the calling of DLL functions in function start() and the second is the actual scanning of a single stock/security in function ScanSymbol().

DLL function PopulateSymbolList_DLL recusively searches for files of type _xxx1440.hst starting at the root directory where the MetaTrader Executable (terminal.exe) is located. I do this so that if Metatrader ever change their directory structure, my dll functionallity will not be effected unless they store history files separately in say My Documents. If there is a match, the symbol is added to a linked list.

Next what we do is iterate through the linked list of symbols in a loop until no more symbols are found. We do this by calling DLL functions GetFirstSymbol_DLL and GetNextSymbol_DLL. If a Symbol has bars, we call Metatrader function ScanSymbol(). Finally when we are finished scanning, we free the list with DLL function call FreeSymbolList_DLL. User does not need to modify this code unless there is a mistake :banghead:

The above describes the 1st main part. The 2nd main part is the scanning of an individual stock/security. This is where the user (that's you), can change the scanning of stocks/securities to whatever suits their needs. This happens in function ScanSymbol(). It is the template function for all future scans :)

So in function ScanSymbol(), I don't want stocks that have only 30 or less bars because I want the 30 day average turnover, so I call and test iBars() <= 30. Next I calculate the 30 day average turnover(Close*Volume) in another function. I then call iStochastic() twice to get the previous and current day values and finally I conditionally test my values and if true, display the result (Experts Tab in Terminal Pane). You could also write code to store results in a file.

Now after you make changes to suit your needs, you need to click Compile in the toolbar above. This will overwrite the previous compiled file with your changes (Namely SymbolScan.ex4).

And that's it. You can now use Metatraders own indicators to scan the whole entire ASX listed securites. You heard it first, developed by an Aussie in Australia on Aussie Stock Forums.

Ozzy Ozzy Ozzy, Oi Oi Oi,
Ozzy Ozzy Ozzy, Oi Oi Oi,
Ozzy, Oi,
Ozzy, Oi,
Ozzy Ozzy Ozzy, Oi Oi Oi.

Cheers,

Andrew.
 
Good on you to have the coding prowess to come up with this. And even better, to have the generosity to share it on a public form.

:xyxthumbs

P.S. I don't use Metatrader 4 but if I do I will sure give it a play.
P.P.S. I am not aware of any broker who let you tade ASX shares with MT4. But I guess you are just very intelligently using the MT4 capabilities to backtest other markets...
 
Thanks skc,

I've just observed something very interesting in my 2nd post on this thread. On the 1st image tools/options (MTSCAN_STEP2.PNG), I notice the number of views is 44. On the 2nd image (MTSCAN_STEP3.PNG), where I display the charts, the number of views is 4.

Now correct me if I am wrong, but if you click on an image, the number of views on that image increases by one Yes?

So based on the above information, how is it that the most informative or interesting image has had so few views and the least interesting image has had so many (11x more) ?

Here's a hint: If you were to follow my instructions in the second post to the letter, what would you do?

I had a good long think about this :). What do people think is actually going on?

Cheers,

Andrew.
 
Thanks skc,

I've just observed something very interesting in my 2nd post on this thread. On the 1st image tools/options (MTSCAN_STEP2.PNG), I notice the number of views is 44. On the 2nd image (MTSCAN_STEP3.PNG), where I display the charts, the number of views is 4.

Now correct me if I am wrong, but if you click on an image, the number of views on that image increases by one Yes?

So based on the above information, how is it that the most informative or interesting image has had so few views and the least interesting image has had so many (11x more) ?

I suspect it has nothing to do with the content of your posts. When a visitor (non-member public) comes to this thread they don't see the images, they only see the link to the image. So they click on the first link and see wht the image is. When they saw a it'boring screenshot, they didn't bother clicking on the 2nd image. You can try it for yourself by visiting the page without logging in.
 
Various definitons of a MasterBar are defined on the web, but for this example, I shall define a MasterBar as a candle that has a higher high and lower low than the next 4 candles. To implement this scan, in the file SymbolScan.mq4, replace the function ScanSymbol() with the following code (applying appropriate indenting):

bool ScanSymbol(string SymStr, int tf)
{
if (iBars(SymStr,tf) <= 30) return true; // Need a minimum number of bars
double ato = avgto(SymStr, tf, 30); // Average Turnover (Vol x Close)
double lo0 = iLow(SymStr, tf, 0);
double lo1 = iLow(SymStr, tf, 1); double lo2 = iLow(SymStr, tf, 2);
double lo3 = iLow(SymStr, tf, 3); double lo4 = iLow(SymStr, tf, 4);
double hi0 = iHigh(SymStr, tf, 0);
double hi1 = iHigh(SymStr, tf, 1); double hi2 = iHigh(SymStr, tf, 2);
double hi3 = iHigh(SymStr, tf, 3); double hi4 = iHigh(SymStr, tf, 4);

if ( ato > 200000 &&
lo4 < lo0 && lo4 < lo1 && lo4 < lo2 && lo4 < lo3 &&
hi4 > hi0 && hi4 > hi1 && hi4 > hi2 && hi4 > hi3
)
{
Print("Symbol = ",SymStr,", AvgTurnover = ",ato);
}

return true;
}

I have also added the constraint where the average turnover (volume * close) must be greater than 200000. Gotta have some liquidity :).

Based on Fridays yahoo finance data (5/Sept/2014), if you run the scan now, you should get symbols CKF and ORL satisfying the criteria. Here is a picture of the result:

MTSCAN_SB1.PNG

I have added horizonal lines to show where a MasterBar was formed in the scan. Can you see how powerful scanning the whole market can be? Instead of looking at 2000+ stocks every day to look for trades, you can come up with some basic constraints, and then make some discretionary decisons based on these results. Even though yahoo data is free, you could easily open up a chart on your broker platform and compare charts. If they agree, you could also open up hourly charts on your broker platform and make even more detailed decisions :)

I might try and get some triangles and flags happening next :)
 
I am new in Australian market
Can anybody let me know which server you using to get information about ASX stocks in metatrader?
Is it a free account of paid?

Th
Mohsen
 
I am new in Australian market
Can anybody let me know which server you using to get information about ASX stocks in metatrader?
Is it a free account of paid?

Th
Mohsen

Hi Mohsen,

As skc pointed out in about the 4th post, I am also not aware of any broker who will let you trade ASX shares with MT4 or even look at live ASX data. What I have tried to do is the next best thing, import End Of Day (EOD) data from elsewhere. In my first post I have links to 2 methods to do this, but if you consider yourself computer illiterate, then you might struggle to follow my instructions. One method involves using the free EOD Yahoo finance data and the other involves paid data downloaded in Metastock Format.

You might want to search for threads on free EOD data (namely Yahoo) and familiarize yourself with how to download it and the pitfalls of using free data.

P.S. Displaying EOD ASX stock charts in Metatrader is not for the faint hearted :(.

Cheers,

Andrew
 
Here is another sample scan I have added, I call it "Consolidation Pattern Followed by a Bullish Breakout Candle" :xyxthumbs

So what we want here are the following:

1) Average 30 day Turnover > $500,000
2) Percentage Change of Previous 15 day Consolidation Period < 10%
3) Current Bar High > 1.05 * Current Bar Low // Big Candle
4) Current Bar Close > Current Bar Open and Low // A Bullish candle
5) Current Bar Close > Highest High Value of High in the Previous 15 days

To implement this scan, in the file SymbolScan.mq4, replace the function ScanSymbol() with the following code (applying appropriate indenting):

bool ScanSymbol(string SymStr, int tf)
{
int i;
if (iBars(SymStr,tf) <= 30) return true; // Need a minimum number of bars
double ato = avgto(SymStr, tf, 30); // Average Turnover (Vol x Close)
double hhv = 0.0, llv = 2147483647.0, percentchange = 0.0;
for (i=1; i<16; i++) if (hhv < iHigh(SymStr, tf, i)) hhv = iHigh(SymStr, tf, i);
for (i=1; i<16; i++) if (llv > iLow(SymStr, tf, i)) llv = iLow(SymStr, tf, i);
if (hhv <= llv) return true;
percentchange = ((hhv - llv) / llv) * 100.0;

if ( ato > 500000 && percentchange < 10 &&
iHigh(SymStr, tf, 0) > 1.05 * iLow(SymStr, tf, 0) &&
iClose(SymStr, tf, 0) > iOpen(SymStr, tf, 0) &&
iClose(SymStr, tf, 0) > iLow(SymStr, tf, 0) &&
iClose(SymStr, tf, 0) > hhv
)
{
Print("Symbol = ",SymStr,", AvgTurnover = ",ato,", HHV = ",hhv,", LLV = ",llv,", %Chg = ",percentchange);
}

return true;
}

Based on Fridays yahoo finance data (19/Sept/2014), if you run the scan now, you should get symbol TPM satisfying the criteria. Here is a picture of the result:

MTSCAN_CP1.PNG

I have added horizonal and vertical lines to show the consolidation period and bullish breakout candle.
 
Another scan I've been working on is a TrendLine Breakout. So first I need to define a TrendLine. Lets start with an Upper Falling TrendLine.

An Upper Falling Trendline is a line between 2 swing highs where the earlier dated swing high is greater than or equal to the later dated swing high. Hence the line is continuing downwards (falling) or horizonal (if equal). Secondly, Apart from the most recent or current candle, all candles starting from the earliest dated swing high must not have a close above the TrendLine value.

From this definition you can see that there are 3 other types of lines that can be defined by 2 points, which are Lower Rising, Upper Rising and Lower Falling. For the Lower types, we use the swing low.

Now a Swing High is when the high of a candle is higher than x previous candles and also higher than x following candles, where x is the number of qualifying candles specified by the user. For a Swing Low, we use the same definition, but using the low.

Now what we want in an Upper Falling Trendline is for the close of the current candle to break above the current TrendLine value, which would indicate a possible breakout on the buy side. Attached is a scan from Yahoo Finance data (03/10/2014) of an Upper Falling TrendLine Breakout (using 3 qualifying bars for swing highs):

UFTLBO1.png

Note: A liquidity gate (turnover > $500,000) was also added.

I chose to chart the first 2 security results in the scan which are CTD and CTX. Now in the scan results, TLV stands for the current trend line value and the 2 SwingPos variables are the positions of the swing high candles where the first or current candle is position 0. So we count back from the current candle.

I have attached the MQ4 source file below as there is a bit more coding than usual involved. Please put this in the same scripts folder as where SymbolScan.mq4 is located and don't forget to compile :xyxthumbs.
 

Attachments

  • SymbolScanTL.mq4
    7.6 KB · Views: 47
Not sure if I am missing something, but for all the system traders and coders out there I would of thought there would be a bit more action in this thread
 
Not sure if I am missing something, but for all the system traders and coders out there I would of thought there would be a bit more action in this thread

Possibly the reason is that Metatrader is widely known as an amateurish piece of software.
 
Yet another scan I've been working on is a scan that returns the Pearson's Correlation Coefficient of the Closes between 2 securities (-1 < r < 1). This is a linear measure of how closely related 2 securities are. This scan takes a fair while as it traverses through all the pair combinations. I have added some constraints to help filter out rubbishy results. When the script is first executed a dialog box of the constraints is displayed like so:

MTSCAN_COR_SET1.PNG

The CorrPeriod variable is how far to look back from (and including) the current candle. So setting to 100 will only include the current 100 days in the correlation scan.

The MinRSquared variable is the minimum requirement you want for displaying correlated pairs.

The MinAvgTurnover variable is the minimum value the 30 day average turnover must be and the MinClosePrice is just what the close of the current candle has to be above, to be considered.

After the scan is run, based on yahoo finance data from Friday 17/Oct/2014, here is a scan and chart of a negative correlation (r = -0.95422) between 2 securities (CTX and AGK):

MTSCAN_COR1.png

and here is a scan and chart of a positive correlation (r = 0.95156) between 2 securities (IRE and CTX):

MTSCAN_COR2.png

Not bad charts for yahoo data and amateurish software :cool:. Would be good if someone could post the Premium Data version :) (As per thread link in first post).

I have attached the MQ4 source file below. Please put this in the same scripts folder as where SymbolScan.mq4 is located and don't forget to compile :xyxthumbs.
 

Attachments

  • SymbolScanCorrelation.mq4
    5.3 KB · Views: 48
Hi Andrew,

Thanks for the awesome scanner. I have been trying to use it but it fails to search for the written criterias.. is there other dll file that must be included in the libraries..
 
Hi Andrew,

Thanks for the awesome scanner. I have been trying to use it but it fails to search for the written criterias.. is there other dll file that must be included in the libraries..

Hi dazrul, what version of windows are you using? I just tried to install Go Markets MT4 Demo on windows 7 (64 bit) and noticed that all the default Metatrader indicators, scripts, history files, etc, get installed in their respective folders residing in the following root directory:

C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\DF5D....0C5F.

And in this root directory resides the following folders:

config
history
logs
MQL4
profiles
templates
tester

So when you follow my instructions for the other 2 threads (creating history files from MS or Yahoo), you would use the history\brokername-Demo folder to run the perl/python scripts and everything should run fine and charts will show up in metatrader. For Scanning, you would put the DLL (DLLMTSCAN.dll) in the MQL4\Libraries folder and the script (SymbolScan.mq4) in the MQL4\Scripts folder.

The problem is that the actual metatrader executable (terminal.exe) is installed (by default) in the directory:

C:\Program Files (x86)\Broker Name MT4\

and when my dll does a search for the files, it recursively searches all folders starting from this directory. So when you run the script "SymbolScan.mq4", it finds nothing. So to work around this problem, what you need to do to get this to work is after you run the perl/python scripts to create the history files, you need to copy the created history files in directory:

C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\DF5D....0C5F\history\brokername-Demo

to

C:\Program Files (x86)\Broker Name MT4\history\brokername-Demo (might need to create this directory).

This is a bit of a pain for now, but it should work. Maybe in future I could pass in the directory location where the history files are stored.

Cheers,

Andrew
 
Attached is file DLLMTSCAN20150518.zip

This file contains the new improved dll "DLLMTSCAN.dll" and the following updated mq4 scripts:

SymbolScan.mq4 - from 1st post
SymbolScanMB.mq4 - from Master Bar Scan post
SymbolScanCPBBC - from Consolidated Pattern followed by Bullish Breakout Candle Scan post
SymbolScanTL.mq4 - from Trendline Scan post
SymbolScanCorrelation.mq4 from Correlation Scan post

I have added the function "SetRootSearchDir_DLL(char *)" to DLLMTSCAN.dll and from the mq4 scripts, I now pass in the directory path where all the user files are stored thanks to being able to retrieve this string from the mq4 function call TerminalInfoString(TERMINAL_DATA_PATH).

So we can forget that last post as the problem is hopefully solved in this post.

Let me know if this works?
 

Attachments

  • DLLMTSCAN20150518.zip
    174.5 KB · Views: 67
Hello there,
I hope this thread is still alive....ajCode I found your scanner pretty interesting and trying to use it but it stops early with error code 0 "uninit reason 0". As I read your descriptions I notices your codes searches for history files which ends in xxx1440 but my files end in xxx240.hst. (forex pairs) Is there a way to make it work for my scenario.

thanks a lot for your help
Attached is file DLLMTSCAN20150518.zip



This file contains the new improved dll "DLLMTSCAN.dll" and the following updated mq4 scripts:



SymbolScan.mq4 - from 1st post

SymbolScanMB.mq4 - from Master Bar Scan post

SymbolScanCPBBC - from Consolidated Pattern followed by Bullish Breakout Candle Scan post

SymbolScanTL.mq4 - from Trendline Scan post

SymbolScanCorrelation.mq4 from Correlation Scan post



I have added the function "SetRootSearchDir_DLL(char *)" to DLLMTSCAN.dll and from the mq4 scripts, I now pass in the directory path where all the user files are stored thanks to being able to retrieve this string from the mq4 function call TerminalInfoString(TERMINAL_DATA_PATH).



So we can forget that last post as the problem is hopefully solved in this post.



Let me know if this works?
 
Hello there,
I hope this thread is still alive....ajCode I found your scanner pretty interesting and trying to use it but it stops early with error code 0 "uninit reason 0". As I read your descriptions I notices your codes searches for history files which ends in xxx1440 but my files end in xxx240.hst. (forex pairs) Is there a way to make it work for my scenario.

thanks a lot for your help

Hi aryma, I think "uninit reason 0" simply means the script was removed from the chart. So I think it ran as expected as it couldn't find any history files. I presume you are using the charts that are generated in real time from mt4 itself. If so then you don't need the dll to scan the charts. I have attached a simple mt4 script that scans common forex charts (4 hours). For example the code "ScanSymbol("USDCHF",PERIOD_H4);" scans the USDCHF 4hr chart. Note: The symbol must match (case sensitive I think) what MT4 calls it. Some MT4 brokers might call it something like USDCHFFX.
 

Attachments

  • SymbolScanMT.zip
    806 bytes · Views: 17
Hi aryma, I think "uninit reason 0" simply means the script was removed from the chart. So I think it ran as expected as it couldn't find any history files. I presume you are using the charts that are generated in real time from mt4 itself. If so then you don't need the dll to scan the charts. I have attached a simple mt4 script that scans common forex charts (4 hours). For example the code "ScanSymbol("USDCHF",PERIOD_H4);" scans the USDCHF 4hr chart. Note: The symbol must match (case sensitive I think) what MT4 calls it. Some MT4 brokers might call it something like USDCHFFX.

Hi Andrew, with a bit modification to the code in order to suit my list of stocks, I think it runs with no errors. May I suggest that we have another scanner/filter which scans a percentage change of the volume over the last n-periods. Or may be the TSV. Thank you. BR, Dazrul
 
Last edited:
Top