darwinex / dwx-zeromq-connector

Wrapper library for algorithmic trading in Python 3, providing DMA/STP access to Darwinex liquidity via a ZeroMQ-enabled MetaTrader Bridge EA.
https://blog.darwinex.com/zeromq-interface-python-r-metatrader4/
BSD 3-Clause "New" or "Revised" License
346 stars 228 forks source link

GetRates sends the new bar data not the last bar data #93

Closed ianhendry closed 3 years ago

ianhendry commented 4 years ago

This is not an issue per se but I want to leave it here in case others find the same thing I did. If using the subscriber to get OHLC bar data the implementation provided sends the data of the new bar not the last completed bar. You will see this because after the first response all subsequent published bars have bar volume =1. My requirement for this type of functionality is to send the data for the last complete bar just after it has been completed. Should you wish to move to this implementation the change required is as per below:

int GetRates(MqlRates& rates[], int count) {
    // ensures that symbol is setup
    if(StringLen(_symbol) > 0) {
        return CopyRates(_symbol, _timeframe, 1, count, rates);
    }
    return 0;
}

where the 0 (zero) in the return CopyRates has been replaced with 1 (one)

This will send the data for the last formed bar on the first tick of the next bar

elvinex commented 3 years ago

Hi, Thank you for your suggestion. It is true that in many cases probably the finished bar is more interesting. We will keep it as it is for now to keep the consistency. People who need the last bar can use your solution.