Discussing the article: "Developing a Replay System — Market simulation (Part 10): Using only real data for Replay"
Hey Daniel, good evening!
Daniel, I have the following situation: I can run and debug the service. But I can't debug the indicator, because when I run the service it already loads the indicator executable.
I don't know what I'm doing wrong, but from what I understand, you can't run the indicator code to debug it. Is this really the case? Could you give me a hint?
Hey Daniel, good evening!
Daniel, I have the following situation: I can run and debug the service. But I can't debug the indicator, because when I run the service it already loads the indicator executable.
I don't know what I'm doing wrong, but from what I understand, you can't run the indicator code to debug it. Is this really the case? Could you give me a hint?
You are absolutely NOT doing anything wrong.
In fact, the service initialises the control indicator as soon as everything is ready for the user to play the service.
I don't quite understand why you want to debug the indicator. There's practically nothing running on it. It only serves as a form of interaction between the user and the service. Without it, it would be very difficult to control when we want to play or pause the service. In any case, you're not doing anything wrong by trying to study how the system works. But as a tip, I advise you to read the articles carefully. They explain in detail how the system works, which will save you a lot of effort trying to understand how interactions happen. 😁👍
Hey Daniel, good morning!
Daniel, I've done some research into your code and development on the Metatrader 5 platform, in order to get a robot running on the replay / simulator proposed in your articles.
The robot is based on the flow of incoming data, i.e. it counts the incoming ticks and makes calculations to indicate whether to execute the trades.
I've already dealt with this same problem in other posts, and I apologise in advance for my insistence. The fact is that I've studied a little more and made the implementations I thought necessary so that the robot (EA) could receive the ticks from the Replay service.
But I'm having the following problem: The robot receives the first ticks correctly, one by one, but after the first 47 ticks received (I've put in a counter), it starts receiving the ticks very spaced out, and I can't understand why.
I'd like to show you the implementations and ask for your help in solving the problem, if possible.
Here are the changes I've made:
- In the C_Replay class (lines in yellow):
- In the Event_OnTime method:
- I created a variable of type MqlTick to receive the tick that will be sent to the graph;
- After the bar update is sent(CustomRatesUpdate), I put in a code to send the tick to the chart and wait for it to be processed via the global variable "def_GlobalVariableTick";
inline int Event_OnTime(void) { bool bNew; int mili, iPos; u_Interprocess Info; MqlTick TickToAdd[1]; static MqlRates Rate[1]; static datetime _dt = 0; if (m_ReplayCount >= m_Ticks.nTicks) return -1; if (bNew = (_dt != m_Ticks.Info[m_ReplayCount].time)) { _dt = m_Ticks.Info[m_ReplayCount].time; Rate[0].real_volume = 0; Rate[0].tick_volume = 0; } mili = (int) m_Ticks.Info[m_ReplayCount].time_msc; do { while (mili == m_Ticks.Info[m_ReplayCount].time_msc) { Rate[0].close = m_Ticks.Info[m_ReplayCount].last; Rate[0].open = (bNew ? Rate[0].close : Rate[0].open); Rate[0].high = (bNew || (Rate[0].close > Rate[0].high) ? Rate[0].close : Rate[0].high); Rate[0].low = (bNew || (Rate[0].close < Rate[0].low) ? Rate[0].close : Rate[0].low); Rate[0].real_volume += (long) m_Ticks.Info[m_ReplayCount].volume_real; bNew = false; m_ReplayCount++; } mili++; }while (mili == m_Ticks.Info[m_ReplayCount].time_msc); Rate[0].time = m_Ticks.Info[m_ReplayCount].time; CustomRatesUpdate(def_SymbolReplay, Rate, 1); iPos = (int)((m_ReplayCount * def_MaxPosSlider) / m_Ticks.nTicks); GlobalVariableGet(def_GlobalVariableReplay, Info.u_Value.df_Value); if (Info.s_Infos.iPosShift != iPos) { Info.s_Infos.iPosShift = (ushort) iPos; GlobalVariableSet(def_GlobalVariableReplay, Info.u_Value.df_Value); } // Apenas plotará o tick no grafico se o robo tiver criado a variavel "def_GlobalVariableTick" if (GlobalVariableCheck(def_GlobalVariableTick)) { TickToAdd[0]=m_Ticks.Info[m_ReplayCount]; Print("Tick enviado: Time: ", TickToAdd[0].time, " Time_msc: ", TickToAdd[0].time_msc, " Bid: ", TickToAdd[0].bid, " Ask: ", TickToAdd[0].ask, " Last: ", TickToAdd[0].last, " Volume: ", TickToAdd[0].volume_real); GlobalVariableSet(def_GlobalVariableTick, 1); // Quando o EA receber o tick (OnTick) irá alterar para ZERO CustomTicksAdd(def_SymbolReplay, TickToAdd); short ctd=0; while (GlobalVariableGet(def_GlobalVariableTick) > 0 && (!_StopFlag) && ctd <= 50) { ctd++; Sleep(50) }; } return (int)(m_Ticks.Info[m_ReplayCount].time_msc < mili ? m_Ticks.Info[m_ReplayCount].time_msc + (1000 - mili) : m_Ticks.Info[m_ReplayCount].time_msc - mili); }
- Code for the robot (EA) that receives the tick for processing:
#define def_GlobalVariableTick "ReplayTick" //+------------------------------------------------------------------+ int OnInit() { GlobalVariableTemp(def_GlobalVariableTick); Print("Variavel Criada: ", def_GlobalVariableTick); return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ void OnDeinit(const int reason) { GlobalVariableDel(def_GlobalVariableTick); } //+------------------------------------------------------------------+ void OnTick() { MqlTick mTick; static int ctd=0; SymbolInfoTick(Symbol(),mTick); ctd++; Print(Symbol(), " Tick Recebido ", ctd, ": Time: ", mTick.time, " Time_msc: ", mTick.time_msc, " Bid: ", mTick.bid, " Ask: ", mTick.ask, " Last: ", mTick.last, " Volume: ", mTick.volume); // . // . // Tick processing code // . // . // Change the value of the global variable to zero, to receive the next tick GlobalVariableSet(def_GlobalVariableTick, 0); }
continuing ....
This way, when you need to stop the robot to debug, the replay will be waiting until you pass the line that sets the global variable "def_GlobalVariableTick" to ZERO;
Got it?
continuing ....
This way, when I needed to stop the robot to debug, the replay would wait until I passed the line that sets the global variable "def_GlobalVariableTick" to ZERO;
Got it?
The detail is that this mechanism has undergone changes. Take a look at the newer articles, as they show you how the ticks will be released correctly. You can even follow them in the market observation window, the DOM. At the moment we have the article for part 28 already published in Portuguese. So this code you're trying to tweak and manipulate is already completely obsolete. You need to follow the articles to keep up with the development of the system. Don't get attached to any of the code in any of the articles until the series is completely published. Because they will undergo several changes over time, in order to be able to fulfil what is promised: DEVELOP A REPLAY / SIMULATOR and this should make it possible to use anything you already have, or are developing for use on a DEMO or REAL account. Either on the stock market or on FOREX.
DO NOT attempt to combine your Expert Advisor, indicator or script with the REPLAY / SIMULATOR, at least not yet. Because it will undergo major changes to the code ... Just create your code without worrying about the REPLAY / SIMULATOR ... There will come a time when I'll stop developing it briefly to show you how to create some support modules. When that happens, you can start integrating your code into it. And even then very slowly, because when the modules I show you how to develop are at a certain level of functionality, they will be integrated into the REPLAY / SIMULATOR ... this is when you really need to understand how the whole system will work. Otherwise, you won't be able to integrate your code into the REPLAY / SIMULATOR SERVICE.
So take it easy and study the articles, always keeping up with what's being developed... 😁👍

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Check out the new article: Developing a Replay System — Market simulation (Part 10): Using only real data for Replay.
Here we will look at how we can use more reliable data (traded ticks) in the replay system without worrying about whether it is adjusted or not.
In the video below you can see the result of the work presented in this article. While some things may not be visible yet, watching the videos will give you a clear understanding of the replay/simulation system progress in all of these articles. Just watch the video and compare the changes from the very beginning to now.
In the next article we will continue to develop the system, since there are still some truly necessary functions to implement.
Author: Daniel Jose