Code Monkey home page Code Monkey logo

machinelearningfx's Introduction

MachineLearning on foreign exchange trading.

A MT5 trading agent (knn02.mq5) integrated with Machine Learning script in python (kmknn01.py). I used the last 80 minute foreign exchange price ticks to predict the next 20 minutes.
First, preprocess the price tick with differcing: ((high-open)*bp,(open-low)*bp,(close-open)*bp,((high-open)-(open-low))*bp )

Then, I use K-Mean clustering to find 10 clusters for each mini-batch data (10000 samples). So similar shape of the price change in the last 80 minutes, including grouping the shape similarity due to time shift.

Then, for each cluster, I averaging the price difference of each cluster sample as the next price change (up or down) of this cluster. And then take the highest price high as the price high of the next 20 minute. Similarly for the lowest price low.

Then, I stored all the centroid of each cluster from all the mini-batches, and then form a KNN model based on the centroid list.

To predict the next 20 minute price change, I feed in the last 80 minute price tick differencing into the KNN model, and get the nearest centroid point. And then use the price change (up/down) and price high/low as the prediction at present. The model is based on the belief that the future price change will repeat the historical price change pattern.

I use the MT5 platform to build the auto-trading agent. The trading agent will write the last 80 price tick to a file, and the KNN python script will periodically scan the folder to read the price tick, and then write the prediction to the response time. The trading agent will read the response file and make the trading decision. If the price change is more for up and the price high change is greate than price low change, then it regards that as the buying signal, and place a buy position with the largest price change as the take-prodit and stop-loss point. Similarly, if the price change is more for down, and the price low change is greater than the price high change, then it regards that as the selling signal, and place a sell position with the largest price change as the take-prodit and stop-loss point.

In the test simulation on the 6-month data, it approximately get a 2%-3% profit, and around 5% max drawback. The figures in the result is not accurate beacuse I did not run the test mang times, and keep track the record. I just roughly remember the testing result. Anyway, the result is not good and I'm still enahancing the algorithm.

machinelearningfx's People

Contributors

iwasnothing avatar

Stargazers

Bot Asylum avatar

Forkers

micwolf33

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.