RSI EA on a one-second timeframe

 

Hi forum,

I'm eager to build my first bot so decided to start with something simple. I'd like to create a RSI EA but have it run on a one-second timeframe. I've watched a YouTube video and I think I can manage building a standard RSI EA to get myself started but in the 'On Tick' section, it's taking the close price. So I assume if I run on the H1 timeframe, it's taking the close from an hour ago for the calculation; on the H4, it's taking the close from 4 hours ago. How do I make my EA work on a one-second time-frame please?

TIA,

CPerry.

 
CPerry: I'm eager to build my first bot so decided to start with something simple. I'd like to create a RSI EA but have it run on a one-second timeframe. I've watched a YouTube video and I think I can manage building a standard RSI EA to get myself started but in the 'On Tick' section, it's taking the close price. So I assume if I run on the H1 timeframe, it's taking the close from an hour ago for the calculation; on the H4, it's taking the close from 4 hours ago. How do I make my EA work on a one-second time-frame please?

Given that MT4 doesn't have a second time-frame built-in to the standard time-frames it supports, your selection for building your first "bot" is not ideal.

A high level of coding skill is required to build it, so I would suggest you start with standard time-frames and use the built-in iRSI() function for the RSI calculations on standard time-frames.

Also, given that there are many RSI based EAs in the codebase, I would suggest you start with those examples to begin learning your way around.

 

In fact, this subject (about 1 second data on MT4) has already been discussed with you before ...

Forum on trading, automated trading systems and testing trading strategies

Second interval forex data

Fernando Carreiro, 2022.08.22 13:20

It seems your question is about MT4 and not MT5, so in that case it is not normally possible because MT4 does not maintain any database of historical tick data.

If you need that, then you will have to captura the data yourself in real-time and generate Offline Charts in second by second format.

There may be existing tools for that in the Market or Codebase, so run a search. Another option is to code it yourself or hire someone in the Freelance section to code it for you.


 
Fernando Carreiro #:

Given that MT4 doesn't have a second time-frame built-in to the standard time-frames it supports, your selection for building your first "bot" is not ideal.

A high level of coding skill is required to build it, so I would suggest you start with standard time-frames and use the built-in iRSI() function for the RSI calculations on standard time-frames.

Also, given that there are many RSI based EAs in the codebase, I would suggest you start with those examples to begin learning your way around.

Hi @Fernando Carreiro,

I've done analysis on the one-second time-frame and from my background in statistical sports trading, it seems to be the pace I enjoy/understand the most. I'm aware it will be tricky but I'm happy to learn. Any idea where to start with coding a one-second tick rate?

CPerry.

 
Fernando Carreiro #:

In fact, this subject (about 1 second data on MT4) has already been discussed with your before ...


This was regarding the data for one-second time-frame. Following your guidance, I got my hands on this, formatted and analysed it (as well as completing BabyPips, which you suggested) the data. I now have something that has passed the analysis stage so I'd like to trial it on practise mode but of course my next lesson is learning how to create a one-second tick rate on MT4 for my strategy to run on.  

 
CPerry #: This was regarding the data for one-second time-frame. Following your guidance, I got my hands on this, formatted and analysed it (as well as completing BabyPips, which you suggested) the data. I now have something that has passed the analysis stage so I'd like to trial it on practise mode but of course my next lesson is learning how to create a one-second tick rate on MT4 for my strategy to run on.  

But the answer is still the same. MT4 does not support historical tick data, and can therefore not produce 1 second data retroactively (only MT5 can do that).

Your EA will have to collect the tick data in real time and build the 1 send data as time goes by. And given that you still don't know your way around MQL, it is not a task to be taken lightly.

I repeat ... temporarily ignore your desire or preference for "second charts" and first learn to work with standard chart (e.g. 1 minute).

Then once you are more comfortable with the coding for the platform. then slowly work your skills up to the being able to build a 1 second EA.

 

@Fernando Carreiro

I have created the RSI EA using the 'On Tick' to capture the close price for the calculation and it seems to be working on the 1 minute. With all due respect, and I sincerely mean that as you have been a huge help thus far on my journey, I'd like to take the time to learn the one-second now. I've been pretty independent in the last few weeks and have backtested something with a decent looking ROI and Sharpe Ratio over a huge sample. Using one-second data for the past 9 months, 80% of the 195 days have been positive and I feel confident to take it to the paper trading stage next.

I'm happy to put the work in, I just came back here as I don't know my next step. I could do with a little push in the right direction please.

I'm hoping there's a time variable, even if it's linked to my system's internal clock. I assume it's just a matter of capturing the close price each time a second passes. I only need one IF statement and one value captured each second for the calculation... I think.

CPerry.

 
CPerry #: I have created the RSI EA using the 'On Tick' to capture the close price for the calculation and it seems to be working on the 1 minute. With all due respect, and I sincerely mean that as you have been a huge help thus far on my journey, I'd like to take the time to learn the one-second now. I've been pretty independent in the last few weeks and have backtested something with a decent looking ROI and Sharpe Ratio over a huge sample. Using one-second data for the past 9 months, 80% of the 195 days have been positive and I feel confident to take it to the paper trading stage next. I'm happy to put the work in, I just came back here as I don't know my next step. I could do with a little push in the right direction please. I'm hoping there's a time variable, even if it's linked to my system's internal clock. I assume it's just a matter of capturing the close price each time a second passes. I only need one IF statement and one value captured each second for the calculation... I think.

How to build and use 1-second time frame on MT4:

  1. On every call to to OnTick(), read in the the tick quote price data via SymbolInfoTick.
  2. With the tick information build your own MqlRates array for every second interval. Alternatively only have a simple array to keep track of the close (or open) quote price of each second.
  3. Use iRSIOnArray on the simple close price array to calculate the RSI. Alternatively, calculate the RSI (or any other indicator) yourself incrementally on each new second as this will make the calculations be much more efficient (faster).
  4. Carry out the rest of the strategy, to detect signal and place orders and manage them.

Given that reading tick data this way will cause tick data to be missed if the on Tick() event takes too long (longer than the arrival of the next tick), your coding has to be as efficient as possible (it needs to be extremely efficient if the entire strategy is all done in a single EA).

Alternatively, one would need two EAs, one to only collect the tick data as fast as possible so not to miss ticks, producing the 1-second data, and the other EA to process the second data and carry out the strategy. This is due to the limitations of MT4 not supporting historical tick data, unlike MT5. The dual EA method however, would not allow you to run it in the strategy tester.

PS! If you only use incremental calculations, then you don't need to keep an array of the 1 second rates. You can just keep track of the start of a new second and apply calculations at that moment without need to store an array.

 

Thank you very much @Fernando Carreiro!

This is exactly what I need to go and do my own research, thank you for the guidance and for taking the time to type this out. Massively appreciated!

CPerry :)

 
CPerry #:Thank you very much @Fernando Carreiro! This is exactly what I need to go and do my own research, thank you for the guidance and for taking the time to type this out. Massively appreciated! CPerry :)
You are welcome!
 
Is using the tick data on the seconds in mt5 different to this? Essentially I’m a scalper using the 5s/15s timeframes to trade but mt5 doesn’t have seconds timeframes charts..

If you were to use this same concept on mt5, would it be a similar process?
Reason: