2026-04-28 08:53:03 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Objects.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_GRAPHICS_OBJECTS_MQH
|
| | | #define FULLMT5MCPBYLEO_SRC_GRAPHICS_OBJECTS_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Include |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "..\\Def\\Def.mqh"
|
| | |
|
2026-06-03 20:39:25 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-04-28 08:53:03 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| object_create |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncObjectCreate : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncObjectCreate(void) : CMcpFunction(0, false, "object_create") {}
|
| | | ~CMcpFuncObjectCreate(void) {}
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 08:53:03 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncObjectCreate::Run(CJsonNode ¶m, CJsonBuilderStr* &out)
|
2026-04-28 08:53:03 -05:00 | | | {
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | out = m_shared_builder;
|
2026-04-28 08:53:03 -05:00 | | | ::ResetLastError();
|
2026-06-03 20:39:25 -05:00 | | | const uint8_t mode = (uint8_t)param["mode"].ToInt(0);
|
2026-04-28 08:53:03 -05:00 | | | switch(mode)
|
| | | {
|
| | | //---
|
| | | case 0: // time1,price1,time2,price2,time3,price3 (chanel\elipse\triangle)
|
| | | {
|
| | | if(!ObjectCreate(param["chart_id"].ToInt(0), param["object_name"].ToString(""),
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_OBJECT>(param["object_type"].ToString(), WRONG_VALUE), int(param["sub_window"].ToInt(0)),
|
2026-04-28 08:53:03 -05:00 | | | StringToTime(param["time1"].ToString("0")), param["price1"].ToDouble(0.00), StringToTime(param["time2"].ToString("0")), param["price2"].ToDouble(0.00),
|
| | | StringToTime(param["time3"].ToString("0")), param["price3"].ToDouble(0.00)
|
| | | ))
|
| | | {
|
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("object_create failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -05:00 | | | return;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
| | | case 1: // time1,price1,time2,price2 (rectangle|fibbo|)
|
| | | {
|
| | | if(!ObjectCreate(param["chart_id"].ToInt(0), param["object_name"].ToString(""),
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_OBJECT>(param["object_type"].ToString(), WRONG_VALUE), int(param["sub_window"].ToInt(0)),
|
2026-04-28 08:53:03 -05:00 | | | StringToTime(param["time1"].ToString("0")), param["price1"].ToDouble(0.00), StringToTime(param["time2"].ToString("0")), param["price2"].ToDouble(0.00)))
|
| | | {
|
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("object_create failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -05:00 | | | return;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
2026-04-29 10:27:56 -05:00 | | | case 2: // time1,price1 (arrow\buttom|vline|hline)
|
2026-04-28 08:53:03 -05:00 | | | {
|
| | | if(!ObjectCreate(param["chart_id"].ToInt(0), param["object_name"].ToString(""),
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_OBJECT>(param["object_type"].ToString(), WRONG_VALUE), int(param["sub_window"].ToInt(0)),
|
2026-04-28 08:53:03 -05:00 | | | StringToTime(param["time1"].ToString("0")), param["price1"].ToDouble(0.00)))
|
| | | {
|
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("object_create failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -05:00 | | | return;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
2026-04-29 10:27:56 -05:00 | | | case 3: // RectLabel\Buttom\Edit (va sin nada se setea con ObjectSetInteger.)
|
2026-04-28 08:53:03 -05:00 | | | {
|
| | | if(!ObjectCreate(param["chart_id"].ToInt(0), param["object_name"].ToString(""),
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_OBJECT>(param["object_type"].ToString(), WRONG_VALUE), int(param["sub_window"].ToInt(0)),
|
2026-04-28 08:53:03 -05:00 | | | 0, 0.00))
|
| | | {
|
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("object_create failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -05:00 | | | return;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
| | | 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("result").ValSWV("Type of mode to create the invalid object");
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -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").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| object_delete |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncObjectDelete : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncObjectDelete() : CMcpFunction(0, false, "object_delete") {}
|
| | | ~CMcpFuncObjectDelete(void) {}
|
| | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 08:53:03 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncObjectDelete::Run(CJsonNode & param, CJsonBuilderStr* &out)
|
2026-04-28 08:53:03 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-04-28 08:53:03 -05:00 | | | ::ResetLastError();
|
| | |
|
| | | //---
|
| | | if(!ObjectDelete(param["chart_id"].ToInt(0), param["object_name"].ToString("")))
|
| | | {
|
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("object_delete failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -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").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 08:53:03 -05:00 | | | }
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-06-30 10:46:22 -05:00 | | | class CMcpFuncObjectSetGet : public CMcpFunction
|
2026-04-28 08:53:03 -05:00 | | | {
|
| | | public:
|
2026-06-30 10:46:22 -05:00 | | | CMcpFuncObjectSetGet(void) : CMcpFunction(0, false, "object_set_get") {}
|
| | | ~CMcpFuncObjectSetGet(void) {}
|
2026-04-28 08:53:03 -05:00 | | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 08:53:03 -05:00 | | | };
|
| | |
|
2026-06-30 10:46:22 -05:00 | | |
|
2026-04-28 08:53:03 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncObjectSetGet::Run(CJsonNode & param, CJsonBuilderStr* &out)
|
2026-04-28 08:53:03 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-06-30 10:46:22 -05:00 | | | const int mode = (int)param["mode"].ToInt(-1);
|
| | | switch(mode)
|
2026-04-28 08:53:03 -05:00 | | | {
|
2026-06-30 10:46:22 -05:00 | | | case MCPFUNC_SETGET_DOUBLE:
|
2026-04-28 08:53:03 -05:00 | | | {
|
2026-06-30 10:46:22 -05:00 | | | ::ResetLastError();
|
| | | const ENUM_OBJECT_PROPERTY_DOUBLE property = CEnumRegBasis::GetValNoRef<ENUM_OBJECT_PROPERTY_DOUBLE>(param["property"].ToString(""), OBJPROP_PRICE);
|
2026-04-28 08:53:03 -05:00 | | |
|
2026-06-30 10:46:22 -05:00 | | | //---
|
| | | if(param.HasKey("value"))
|
| | | {
|
| | | // SET mode
|
| | | ::ResetLastError();
|
| | | const bool result = ObjectSetDouble(param["chart_id"].ToInt(0), param["object_name"].ToString(""), property, (int)param["prop_modifier"].ToInt(0), param["value"].ToDouble(0.0));
|
| | | if(!result)
|
| | | {
|
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("object_set_double failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -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").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | }
|
| | | else
|
| | | {
|
| | | // GET mode
|
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").Val(ObjectGetDouble(param["chart_id"].ToInt(0), param["object_name"].ToString(""), property, (int)param["prop_modifier"].ToInt(0)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | }
|
| | | break;
|
| | | }
|
| | | case MCPFUNC_SETGET_INTEGER:
|
| | | {
|
| | | ::ResetLastError();
|
| | | const ENUM_OBJECT_PROPERTY_INTEGER property = CEnumRegBasis::GetValNoRef<ENUM_OBJECT_PROPERTY_INTEGER>(param["property"].ToString(""), OBJPROP_COLOR);
|
2026-04-28 08:53:03 -05:00 | | |
|
2026-06-30 10:46:22 -05:00 | | | //---
|
| | | if(param.HasKey("value"))
|
| | | {
|
| | | // SET mode
|
| | | ::ResetLastError();
|
| | | const bool result = ObjectSetInteger(param["chart_id"].ToInt(0), param["object_name"].ToString(""), property, (int)param["prop_modifier"].ToInt(0), param["value"].ToInt(0));
|
| | | if(!result)
|
| | | {
|
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("object_set_integer failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -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").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | }
|
| | | else
|
| | | {
|
| | | // GET mode
|
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").Val(ObjectGetInteger(param["chart_id"].ToInt(0), param["object_name"].ToString(""), property, (int)param["prop_modifier"].ToInt(0)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | }
|
| | | break;
|
| | | }
|
| | | case MCPFUNC_SETGET_STRING:
|
2026-04-28 08:53:03 -05:00 | | | {
|
2026-06-30 10:46:22 -05:00 | | | ::ResetLastError();
|
| | | const ENUM_OBJECT_PROPERTY_STRING property = CEnumRegBasis::GetValNoRef<ENUM_OBJECT_PROPERTY_STRING>(param["property"].ToString(""), OBJPROP_NAME);
|
| | |
|
| | | //---
|
| | | if(param.HasKey("value"))
|
| | | {
|
| | | // SET mode
|
| | | ::ResetLastError();
|
| | | const bool result = ObjectSetString(param["chart_id"].ToInt(0), param["object_name"].ToString(""), property, (int)param["prop_modifier"].ToInt(0), param["value"].ToString(""));
|
| | | if(!result)
|
| | | {
|
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("object_set_string failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -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").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | }
|
| | | else
|
| | | {
|
| | | // GET mode
|
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").ValS(ObjectGetString(param["chart_id"].ToInt(0), param["object_name"].ToString(""), property, (int)param["prop_modifier"].ToInt(0)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | }
|
| | | break;
|
2026-04-28 08:53:03 -05:00 | | | }
|
2026-06-30 10:46:22 -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("result").ValSWV("Invalid mode");
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-30 10:46:22 -05:00 | | | break;
|
2026-04-28 08:53:03 -05:00 | | | }
|
| | | }
|
| | |
|
2026-04-28 22:54:27 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| object_list |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncObjectList : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncObjectList() : CMcpFunction(0, false, "object_list") {}
|
| | | ~CMcpFuncObjectList(void) {}
|
| | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 22:54:27 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncObjectList::Run(CJsonNode & param, CJsonBuilderStr* &out)
|
2026-04-28 22:54:27 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-04-28 22:54:27 -05:00 | | | ::ResetLastError();
|
| | |
|
| | | //---
|
| | | const long chart_id = param["chart_id"].ToInt(0);
|
| | | const int sub_window = (int)param["sub_window"].ToInt(-1);
|
2026-06-28 22:09:10 -05:00 | | | const int type = int(CEnumRegBasis::GetValNoRef<ENUM_OBJECT>(param["object_type"].ToString(), -1));
|
2026-04-28 22:54:27 -05:00 | | |
|
| | | //---
|
| | | const int total = ObjectsTotal(chart_id, sub_window, type);
|
| | |
|
| | | if(total < 0)
|
| | | {
|
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("object_list failed, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 22:54:27 -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 22:54:27 -05:00 | | | for(int i = 0; i < total; i++)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.ValS(ObjectName(chart_id, i, sub_window));
|
2026-04-28 22:54:27 -05:00 | | | }
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.EndArr();
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 22:54:27 -05:00 | | | }
|
| | |
|
2026-04-28 08:53:03 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-03 20:39:25 -05:00 | | | } // namespace TSN
|
2026-04-28 08:53:03 -05:00 | | | #endif // FULLMT5MCPBYLEO_SRC_GRAPHICS_OBJECTS_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|