I aim to make a multivariable statistical model with R. To do this we need variables and a targhet. The targhet is close price of a symbol of bar 1. the variables are as many information as possbile of bar 2 (bar datas, indicators values etc, not only from targhet symbol).
How to collect targhet and variables:
I made this to extract as many information as possible from the market.
0_1569663033618_autoextract2.mq5
Variable legend:
- bars: "from" how many bars in the past it will start collecting data.
- bar_a: "to" how many bars in the past it will stop collecting data.
- market: list of symbols to extract data
- live: if = 0 it will extract data from "bars" to "bar_a". if != 0 it will extract only the single bar you set as live value. (this was made for backtesting).
Example:
We want to extract AUDUSD, USDJPY, GBPUSD as variables. we target close price bar of EURUSD. We want to collect data from 3000 1h bars in the past to 10 1h bar in the past.
Since we target EURUSD 1h time frame, we load the ea in the 1h EURUSD chart. Variables are set like this:
- bars: 3000
- bar_a: 10
- market: AUDUSD, USDJPY, GBPUSD
- live: 0
press ok, and let the ea do its job. When the job is done you will find in /Files folder 4 files:
- AUDUSD.csv <-- data from 1h time frame extracted from this symbol (1 bar before targhet bar)
- USDJPY.csv <-- data from 1h time frame extracted from this symbol (1 bar before targhet bar)
- GBPUSD.csv <-- data from 1h time frame extracted from this symbol (1 bar before targhet bar)
- targhet.csv <-- close price of EURUSD (1 bar after AUDUSD, USDJPY, GBPUSD)
What kind of information are collected for variables (not target)?
check block n.8. You can customize it, but Candle ID needs to stay as bvar variable and tempo needs to stay as it is to have a better organization in R database.
How to change targhet?
to change the target symbol just load it in the desired symbol. to change the target information check block n. 24 and change aim. Candle ID needs to stay as bvar variable. tempo needs to stay as it is. Do not put more variables than aim and tempo, unless you know what you are doing.
How to extract all this data from only one bar?
you want to extract all the infos above from bar 5? just set variable live = 5. only the raw of bar 5 will be collected. This is made for backtesting, in fact no target.csv will be produced.
Now that we have our data, we can create an R database merging all csv extracted from this ea. We can train a machine learning model from this data, or use glm models, caret, or whatever model you would like to use. At the moment of writing, i'm studying xgbTree with caret (please refere to this page: Predictive modeling and machine learning in R with the caret package). next study model will be glm.
Once the model is done and we are happy with it, we can make prediction (wrong or right) about the target, save them in a csv file, and thanks to @trader-philipps we are able to make a ea that can read the prediction from the csv file and react to them.
tl;dr
We train a statistical model to be able to predict bar 1 price, given information from the previous bar (bar 2). once the model is trained, we give bar 0 information to the model to predict the next bar price (bar -1).


