2026-04-28 21:48:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-27 22:49:28 -05:00 | | | //| MarketData.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza. |
|
| | | //| https://www.mql5.com/es/users/nique_372 |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com/es/users/nique_372"
|
| | | #property strict
|
| | |
|
| | | #ifndef FULLMT5MCPBYLEO_SRC_DATA_MARKETDATA_MQH
|
| | | #define FULLMT5MCPBYLEO_SRC_DATA_MARKETDATA_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Include |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "..\\Def\\Def.mqh"
|
| | |
|
2026-06-03 20:39:25 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | //| CMcpFuncCopyTicks |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | class CMcpFuncCopyTicks : public CMcpFunction
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | private:
|
| | | MqlTick m_ticks[];
|
| | |
|
2026-04-27 22:49:28 -05:00 | | | public:
|
2026-04-28 21:48:06 -05:00 | | | CMcpFuncCopyTicks(void);
|
| | | ~CMcpFuncCopyTicks(void);
|
2026-04-27 22:49:28 -05:00 | | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-27 22:49:28 -05:00 | | | };
|
| | |
|
2026-04-28 21:48:06 -05:00 | | |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | //| Constructor |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | CMcpFuncCopyTicks::CMcpFuncCopyTicks(void) : CMcpFunction(0, false, "copy_ticks")
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | ArraySetAsSeries(m_ticks, true);
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | //| Destructor |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | CMcpFuncCopyTicks::~CMcpFuncCopyTicks(void)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-04-27 22:49:28 -05:00 | | |
|
2026-04-28 21:48:06 -05:00 | | | /*
|
| | | {
|
| | | "symbol" : "XAUUSD",
|
| | | "count" : 10,
|
| | | "flags" : "COPY_TICKS_ALL",
|
| | | "from" : 0
|
| | | }
|
| | |
|
| | | COPY_TICKS_ALL = 0, // Obtener todos los ticks
|
| | | COPY_TICKS_BID = 1, // Obtener los ticks donde cambió el precio Bid
|
| | | COPY_TICKS_ASK = 2, // Obtener los ticks donde cambió el precio Ask
|
| | | COPY_TICKS_LAST = 4, // Obtener los ticks donde cambió el precio Last
|
| | | COPY_TICKS_TRADE = 8, // Obtener los ticks con volumen de transacción (Last)
|
| | | COPY_TICKS_BUY = 16, // Obtener los ticks de compra
|
| | | COPY_TICKS_SELL = 32 // Obtener los ticks de venta
|
| | | */
|
2026-04-27 22:49:28 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | //| Run - Copia ticks del símbolo especificado |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncCopyTicks::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-04-27 22:49:28 -05:00 | | | ::ResetLastError();
|
2026-04-28 21:48:06 -05:00 | | |
|
| | | //---
|
2026-04-27 22:49:28 -05:00 | | | const string symbol = param["symbol"].ToString(_Symbol);
|
2026-04-28 21:48:06 -05:00 | | | const uint count = (uint)param["count"].ToInt(10);
|
| | | const ulong from = (ulong)param["from"].ToInt((long(TimeCurrent()) * 1000) - (10 * 1000));
|
| | | const uint flags = uint(param["flags"].ToInt(COPY_TICKS_ALL));
|
2026-07-14 09:22:17 -05:00 | | | const int precistion = (int)param["digits"].ToInt(5);
|
2026-04-27 22:49:28 -05:00 | | | //---
|
2026-04-28 21:48:06 -05:00 | | | // Validar que se copiaron los ticks correctamente
|
| | | const int copied = CopyTicks(symbol, m_ticks, flags, from, count);
|
2026-04-27 22:49:28 -05:00 | | | if(copied != count)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(false);
|
| | | m_shared_builder.KeyWV("error").ValSWV(StringFormat("CopyTicks failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Arr();
|
2026-04-28 21:48:06 -05:00 | | | const int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
|
| | |
|
| | | //---
|
2026-04-27 22:49:28 -05:00 | | | for(int i = 0; i < copied; i++)
|
| | | {
|
2026-04-28 21:48:06 -05:00 | | | // Construir objeto MqlTick en JSON
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("time").ValSWV(TimeToString(m_ticks[i].time, TIME_DATE | TIME_SECONDS | TIME_MINUTES));
|
2026-07-14 09:22:17 -05:00 | | | m_shared_builder.KeyWV("bid").Val(m_ticks[i].bid, precistion);
|
| | | m_shared_builder.KeyWV("ask").Val(m_ticks[i].ask, precistion);
|
| | | m_shared_builder.KeyWV("last").Val(m_ticks[i].last, precistion);
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.KeyWV("volume").Val((long)m_ticks[i].volume);
|
| | | m_shared_builder.KeyWV("time_msc").Val(m_ticks[i].time_msc);
|
| | | m_shared_builder.KeyWV("flags").Val((long)m_ticks[i].flags);
|
2026-07-14 09:22:17 -05:00 | | | m_shared_builder.KeyWV("volume_real").Val(m_ticks[i].volume_real, precistion);
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.EndObj();
|
2026-04-27 22:49:28 -05:00 | | | }
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.EndArr();
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | |
|
| | |
|
2026-04-29 21:15:35 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncBarShift : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncBarShift(void) : CMcpFunction(0, false, "i_bar_shift") {}
|
| | | ~CMcpFuncBarShift(void) {}
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-29 21:15:35 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncBarShift::Run(CJsonNode ¶m, CJsonBuilderStr* &out)
|
2026-04-29 21:15:35 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
| | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Val(iBarShift(param["symbol"].ToString(_Symbol), CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period),
|
2026-04-29 21:15:35 -05:00 | | | StringToTime(param["time"].ToString("0")), param["exact"].ToBool(false)));
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 21:15:35 -05:00 | | | }
|
| | |
|
| | |
|
| | |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | //| copy_rates |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | class CMcpFuncCopyData : public CMcpFunction
|
2026-04-27 22:49:28 -05:00 | | | {
|
| | | protected:
|
2026-04-28 21:48:06 -05:00 | | | double m_buffer_d[];
|
| | | long m_buffer_l[];
|
| | | datetime m_buffer_dt[];
|
| | | int m_buffer_i[];
|
| | |
|
2026-04-27 22:49:28 -05:00 | | | public:
|
2026-04-28 21:48:06 -05:00 | | | CMcpFuncCopyData() : CMcpFunction(0, false, "copy_data")
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | ArraySetAsSeries(m_buffer_d, true);
|
| | | ArraySetAsSeries(m_buffer_l, true);
|
| | | ArraySetAsSeries(m_buffer_i, true);
|
| | | ArraySetAsSeries(m_buffer_dt, true);
|
2026-04-27 22:49:28 -05:00 | | | }
|
2026-04-28 21:48:06 -05:00 | | | ~CMcpFuncCopyData(void) {}
|
2026-04-27 22:49:28 -05:00 | | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-27 22:49:28 -05:00 | | | };
|
| | |
|
2026-04-28 21:48:06 -05:00 | | | /*
|
| | | {
|
| | | "symbol" : "XAUUSD",
|
| | | "count" : 10,
|
| | | "timeframe" "PERIOD_M1",
|
| | | "start" : 0,
|
| | | "mode" : "COPY_CLOSE"
|
| | | }
|
| | |
|
| | | MCPFUNC_COPY_DATA_CLOSE = 0,
|
| | | MCPFUNC_COPY_DATA_OPEN = 1,
|
| | | MCPFUNC_COPY_DATA_HIGH = 2,
|
| | | MCPFUNC_COPY_DATA_LOW = 3,
|
| | | MCPFUNC_COPY_DATA_TICK_VOLUME = 4,
|
| | | MCPFUNC_COPY_DATA_REAL_VOLUME = 5,
|
| | | MCPFUNC_COPY_DATA_TIME = 6,
|
| | | MCPFUNC_COPY_DATA_SPREAD = 7
|
| | | */
|
| | |
|
| | |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncCopyData::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | //---
|
2026-07-13 21:11:54 -05:00 | | | out = m_shared_builder;
|
2026-04-27 22:49:28 -05:00 | | | ::ResetLastError();
|
2026-04-28 21:48:06 -05:00 | | | uint8_t t = 0;
|
2026-06-03 20:39:25 -05:00 | | | const int start = (int)param["start"].ToInt(0);
|
| | | const int count = (int)param["count"].ToInt(0);
|
2026-07-14 09:22:17 -05:00 | | | const int precistion = (int)param["digits"].ToInt(5);
|
2026-06-28 22:09:10 -05:00 | | | const uint8_t mode = uint8_t(CEnumRegFullMt5Mcp::GetValNoRef<ENUM_MCPFUNC_COPY_DATA>(param["mode"].ToString(), 0));
|
2026-04-27 22:49:28 -05:00 | | | const string symbol = param["symbol"].ToString(_Symbol);
|
| | |
|
2026-04-28 21:48:06 -05:00 | | | // t = [0=double,1=long,2=datetime:string]
|
2026-04-27 22:49:28 -05:00 | | | //---
|
2026-04-28 21:48:06 -05:00 | | | int copied = -1;
|
| | | switch(mode)
|
2026-04-29 21:15:35 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | case MCPFUNC_COPY_DATA_CLOSE:
|
| | | {
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyClose(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_d);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_OPEN:
|
| | | {
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyOpen(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_d);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_HIGH:
|
| | | {
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyHigh(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_d);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_LOW:
|
| | | {
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyLow(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_d);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_TICK_VOLUME:
|
| | | {
|
| | | t = 1;
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyTickVolume(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_l);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_REAL_VOLUME:
|
| | | {
|
| | | t = 1;
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyRealVolume(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_l);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_TIME:
|
| | | {
|
| | | t = 2;
|
2026-06-28 22:09:10 -05:00 | | | copied = CopyTime(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_dt);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
| | | case MCPFUNC_COPY_DATA_SPREAD:
|
| | | {
|
| | | t = 3;
|
2026-06-28 22:09:10 -05:00 | | | copied = CopySpread(symbol, CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period), start, count, m_buffer_i);
|
2026-04-28 21:48:06 -05:00 | | | break;
|
| | | }
|
2026-04-27 22:49:28 -05:00 | | |
|
2026-04-28 21:48:06 -05:00 | | | //---
|
| | | default:
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(false);
|
| | | m_shared_builder.KeyWV("error").ValSWV(StringFormat("Invalid mode = %u", mode));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 21:48:06 -05:00 | | | return;
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //---
|
| | | if(copied != count)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(false);
|
| | | m_shared_builder.KeyWV("error").ValSWV(StringFormat("copy_data failed, last mt5 error = %d, [start = %d, count = %d]", ::GetLastError(), start, count));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Arr();
|
2026-04-28 21:48:06 -05:00 | | | switch(t)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 21:48:06 -05:00 | | | //---
|
| | | case 0: // dbl
|
| | | {
|
| | | for(int i = 0; i < copied; i++)
|
| | | {
|
2026-07-14 09:22:17 -05:00 | | | m_shared_builder.Val(m_buffer_d[i], precistion);
|
2026-04-28 21:48:06 -05:00 | | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
| | | case 1: // long
|
| | | {
|
| | | for(int i = 0; i < copied; i++)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.Val(m_buffer_l[i]);
|
2026-04-28 21:48:06 -05:00 | | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
| | | case 2: // date
|
| | | {
|
| | | for(int i = 0; i < copied; i++)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.ValSWV(TimeToString(m_buffer_dt[i]));
|
2026-04-28 21:48:06 -05:00 | | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
| | | case 3: // int
|
| | | {
|
| | | for(int i = 0; i < copied; i++)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.Val(m_buffer_i[i]);
|
2026-04-28 21:48:06 -05:00 | | | }
|
| | | break;
|
| | | }
|
2026-04-27 22:49:28 -05:00 | | | }
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.EndArr();
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 20:39:25 -05:00 | | | } // namespace TSN
|
2026-04-27 22:49:28 -05:00 | | | #endif // FULLMT5MCPBYLEO_SRC_DATA_MARKETDATA_MQH
|
2026-04-28 21:48:06 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|