diff --git a/MtApi5/MqlTick.cs b/MtApi5/MqlTick.cs index ffd6c174..5e908c88 100755 --- a/MtApi5/MqlTick.cs +++ b/MtApi5/MqlTick.cs @@ -5,12 +5,18 @@ namespace MtApi5 public class MqlTick { public MqlTick(DateTime time, double bid, double ask, double last, ulong volume) + : this(time, bid, ask, last, volume, 0) + { + } + + public MqlTick(DateTime time, double bid, double ask, double last, ulong volume, ENUM_TICK_FLAGS flags) { MtTime = Mt5TimeConverter.ConvertToMtTime(time); this.bid = bid; this.ask = ask; this.last = last; this.volume = volume; + this.flags = flags; } public MqlTick() @@ -27,6 +33,7 @@ namespace MtApi5 last = tick.Last; volume = tick.Volume; volume_real = tick.VolumeReal; + flags = (ENUM_TICK_FLAGS)tick.Flags; } } @@ -37,6 +44,7 @@ namespace MtApi5 public double last { get; set; } // Price of the last deal (Last) public ulong volume { get; set; } // Volume for the current Last price public double volume_real { get; set; } // Volume for the current Last price with greater accuracy + public ENUM_TICK_FLAGS flags { get; set; } // Tick flags (used for analyzing to find out what data have been changed) public DateTime time => Mt5TimeConverter.ConvertFromMtTime(MtTime); } diff --git a/MtApi5/Mt5Enums.cs b/MtApi5/Mt5Enums.cs index c5bd3193..e8b84491 100755 --- a/MtApi5/Mt5Enums.cs +++ b/MtApi5/Mt5Enums.cs @@ -862,6 +862,18 @@ namespace MtApi5 STO_CLOSECLOSE = 1 //Calculation is based on Close/Close prices } + [Flags] + public enum ENUM_TICK_FLAGS + { + TICK_FLAG_NONE = 0, + TICK_FLAG_BID = 2, // Tick has changed a Bid price + TICK_FLAG_ASK = 4, // Tick has changed an Ask price + TICK_FLAG_LAST = 8, // Tick has changed the last deal price + TICK_FLAG_VOLUME = 16, // Tick has changed a volume + TICK_FLAG_BUY = 32, // Tick is a result of a buy deal + TICK_FLAG_SELL = 64 // Tick is a result of a sell deal + } + #endregion //Price Constants #region Smoothing Methods diff --git a/MtApi5/MtProtocol/MqlTick.cs b/MtApi5/MtProtocol/MqlTick.cs index a3b463bb..ffb936ec 100755 --- a/MtApi5/MtProtocol/MqlTick.cs +++ b/MtApi5/MtProtocol/MqlTick.cs @@ -8,5 +8,6 @@ public double Last { get; set; } // Price of the last deal (Last) public ulong Volume { get; set; } // Volume for the current Last price public double VolumeReal { get; set; } // Volume for the current Last price with greater accuracy + public uint Flags { get; set; } // Tick flags } } \ No newline at end of file diff --git a/TestClients/MtApi5TestClient/ViewModel.cs b/TestClients/MtApi5TestClient/ViewModel.cs index 470c6651..0e916d2c 100755 --- a/TestClients/MtApi5TestClient/ViewModel.cs +++ b/TestClients/MtApi5TestClient/ViewModel.cs @@ -1071,7 +1071,7 @@ namespace MtApi5TestClient { foreach (var v in result) { - var tickStr = $"time = {v.time}, bid = {v.bid}, ask = {v.ask}, last = {v.last}, volume = {v.volume}"; + var tickStr = $"time = {v.time}, bid = {v.bid}, ask = {v.ask}, last = {v.last}, volume = {v.volume}, flags = {v.flags}"; TimeSeriesResults.Add(tickStr); } }); @@ -1159,6 +1159,7 @@ namespace MtApi5TestClient AddLog($"SymbolInfoTick(EURUSD) tick.last = {result.last}"); AddLog($"SymbolInfoTick(EURUSD) tick.volume = {result.volume}"); AddLog($"SymbolInfoTick(EURUSD) tick.volume_real = {result.volume_real}"); + AddLog($"SymbolInfoTick(EURUSD) tick.flags = {result.flags}"); } private async void ExecuteSymbolInfoSessionQuote(object o) diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5 index 2d54c91d..e5cb3a8f 100755 Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index e7373c10..d4cd9ac9 100644 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -3801,6 +3801,21 @@ bool JsonToMqlTradeRequest(JSONObject *jo, MqlTradeRequest& request) JSONObject* MqlTickToJson(const MqlTick& tick) { + // MT5 can add some additional non-documented flags, so we need to filter required documented flags only + int summ=0; + if((tick.flags & TICK_FLAG_BID)==TICK_FLAG_BID) + summ+=TICK_FLAG_BID; + if((tick.flags & TICK_FLAG_ASK)==TICK_FLAG_ASK) + summ+=TICK_FLAG_ASK; + if((tick.flags & TICK_FLAG_LAST)==TICK_FLAG_LAST) + summ+=TICK_FLAG_LAST; + if((tick.flags & TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME) + summ+=TICK_FLAG_VOLUME; + if((tick.flags & TICK_FLAG_BUY)==TICK_FLAG_BUY) + summ+=TICK_FLAG_BUY; + if((tick.flags & TICK_FLAG_SELL)==TICK_FLAG_SELL) + summ+=TICK_FLAG_SELL; + JSONObject *jo = new JSONObject(); jo.put("Time", new JSONNumber((long)tick.time)); jo.put("Bid", new JSONNumber(tick.bid)); @@ -3808,6 +3823,7 @@ JSONObject* MqlTickToJson(const MqlTick& tick) jo.put("Last", new JSONNumber(tick.last)); jo.put("Volume", new JSONNumber(tick.volume)); jo.put("VolumeReal", new JSONNumber(tick.volume_real)); + jo.put("Flags", new JSONNumber(summ)); return jo; }