2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-28 21:48:06 -05:00 | | | //| Charts.mqh |
|
2026-04-27 22:49:28 -05:00 | | | //| 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_CHARTS_CHARTS_MQH
|
| | | #define FULLMT5MCPBYLEO_SRC_CHARTS_CHARTS_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Include |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "..\\Def\\Def.mqh"
|
| | |
|
2026-06-29 17:48:51 -05:00 | | | namespace TSN
|
2026-06-03 20:39:25 -05:00 | | | {
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| chart_list |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncChartList : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncChartList() : CMcpFunction(0, false, "chart_list") {}
|
| | | ~CMcpFuncChartList(void) {}
|
| | |
|
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-07-13 21:11:54 -05:00 | | | void CMcpFuncChartList::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 | | | long currChart, prevChart = ChartFirst();
|
2026-04-28 21:48:06 -05:00 | | | int i = 0, limit = CHARTS_MAX;
|
2026-06-30 22:34:24 -05:00 | | |
|
2026-04-28 21:48:06 -05:00 | | | //---
|
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-06-30 22:34:24 -05:00 | | |
|
2026-04-28 21:48:06 -05:00 | | | //---
|
2026-04-27 22:49:28 -05:00 | | | if(prevChart >= 0)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.Val(prevChart);
|
2026-04-27 22:49:28 -05:00 | | | while(i < limit)
|
| | | {
|
| | | currChart = ChartNext(prevChart);
|
2026-04-28 21:48:06 -05:00 | | | if(currChart < 0)
|
| | | break;
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.Val(currChart);
|
2026-04-27 22:49:28 -05:00 | | | prevChart = currChart;
|
| | | i++;
|
| | | }
|
| | | }
|
| | |
|
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 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| chart_open |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncChartOpen : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncChartOpen() : CMcpFunction(0, false, "chart_open") {}
|
| | | ~CMcpFuncChartOpen(void) {}
|
| | |
|
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-07-13 21:11:54 -05:00 | | | void CMcpFuncChartOpen::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-06-28 22:09:10 -05:00 | | | const long chart_id = ::ChartOpen(param["symbol"].ToString(_Symbol), CEnumRegBasis::GetValNoRef<ENUM_TIMEFRAMES>(param["timeframe"].ToString(), _Period));
|
2026-04-27 22:49:28 -05:00 | | |
|
| | | //---
|
| | | if(chart_id == 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("chart_open 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").Val(chart_id);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| chart_close |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncChartClose : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncChartClose() : CMcpFunction(0, false, "chart_close") {}
|
| | | ~CMcpFuncChartClose(void) {}
|
| | |
|
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-07-13 21:11:54 -05:00 | | | void CMcpFuncChartClose::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 | | | const bool result = ChartClose((long)param["chart_id"].ToInt(-1));
|
2026-04-27 22:49:28 -05:00 | | |
|
| | | //---
|
| | | 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("chart_close 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").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-06-29 17:48:51 -05:00 | | | //| chart_get_set |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-29 17:48:51 -05:00 | | | class CMcpFuncChartSetGet : public CMcpFunction
|
2026-04-27 22:49:28 -05:00 | | | {
|
| | | public:
|
2026-06-29 17:48:51 -05:00 | | | CMcpFuncChartSetGet(void) : CMcpFunction(0, false, "chart_get_set") {}
|
| | | ~CMcpFuncChartSetGet(void) {}
|
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-07-13 21:11:54 -05:00 | | | void CMcpFuncChartSetGet::Run(CJsonNode ¶m, CJsonBuilderStr* &out)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-06-29 17:48:51 -05:00 | | | const int mode = (int)param["mode"].ToInt(-1);
|
| | | const long chart_id = param["chart_id"].ToInt(0);
|
| | | switch(mode)
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_SETGET_DOUBLE:
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | if(param.HasKey("value"))
|
| | | {
|
| | | if(ChartSetDouble(chart_id, CEnumRegBasis::GetValNoRef<ENUM_CHART_PROPERTY_DOUBLE>(param["property"].ToString(""), WRONG_VALUE), param["value"].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(true);
|
| | | m_shared_builder.KeyWV("result").Val(true);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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("Error set chart double, last mt5 err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | double v;
|
| | | if(ChartGetDouble(chart_id, CEnumRegBasis::GetValNoRef<ENUM_CHART_PROPERTY_DOUBLE>(param["property"].ToString(""), WRONG_VALUE), (int)param["sub_window"].ToInt(0), v))
|
| | | {
|
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(v);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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("Error chart get double, last err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | }
|
| | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_SETGET_INTEGER:
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | if(param.HasKey("value"))
|
| | | {
|
| | | if(ChartSetInteger(chart_id, CEnumRegBasis::GetValNoRef<ENUM_CHART_PROPERTY_INTEGER>(param["property"].ToString(""), WRONG_VALUE), param["value"].ToInt(0)))
|
| | | {
|
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-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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("Error set chart double, last mt5 err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | long v = 0;
|
| | | if(ChartGetInteger(chart_id, CEnumRegBasis::GetValNoRef<ENUM_CHART_PROPERTY_INTEGER>(param["property"].ToString(""), WRONG_VALUE), (int)param["sub_window"].ToInt(0), v))
|
| | | {
|
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(v);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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("Error chart get integer, last err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | }
|
| | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_SETGET_STRING:
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | if(param.HasKey("value"))
|
| | | {
|
| | | if(ChartSetString(chart_id, CEnumRegBasis::GetValNoRef<ENUM_CHART_PROPERTY_STRING>(param["property"].ToString(""), WRONG_VALUE), param["value"].ToString()))
|
| | | {
|
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-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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("Error set chart string, last mt5 err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | string v;
|
| | | if(ChartGetString(chart_id, CEnumRegBasis::GetValNoRef<ENUM_CHART_PROPERTY_STRING>(param["property"].ToString(""), WRONG_VALUE), v))
|
| | | {
|
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(v);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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("Error chart get string, last err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | }
|
| | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -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("Error, invalid mode");
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-06-29 17:48:51 -05:00 | | | //| chart_navigate |
|
2026-04-28 21:48:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-29 17:48:51 -05:00 | | | class CMcpFuncChartNavigate : public CMcpFunction
|
2026-04-28 21:48:06 -05:00 | | | {
|
| | | public:
|
2026-06-29 17:48:51 -05:00 | | | CMcpFuncChartNavigate(void) : CMcpFunction(0, false, "chart_navigate") {}
|
| | | ~CMcpFuncChartNavigate(void) {}
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 21:48:06 -05:00 | | | };
|
| | |
|
2026-06-29 17:48:51 -05:00 | | |
|
2026-04-28 21:48:06 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncChartNavigate::Run(CJsonNode ¶m, CJsonBuilderStr* &out)
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-04-28 21:48:06 -05:00 | | | ::ResetLastError();
|
2026-06-29 17:48:51 -05:00 | | | if(ChartNavigate(param["chart_id"].ToInt(0),
|
| | | CEnumRegBasis::GetValNoRef<ENUM_CHART_POSITION>(param["loacation"].ToString(), WRONG_VALUE), int(param["bars_to_navigate"].ToInt(0))))
|
2026-04-28 21:48:06 -05:00 | | | {
|
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 21:48:06 -05:00 | | | }
|
| | | else
|
| | | {
|
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(StringFormat("Eror navigate chart, last MQL5 Error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-06-29 17:48:51 -05:00 | | | //| chart_indicator |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-29 17:48:51 -05:00 | | | class CMcpFuncChartInd : public CMcpFunction
|
2026-04-27 22:49:28 -05:00 | | | {
|
| | | public:
|
2026-06-29 17:48:51 -05:00 | | | CMcpFuncChartInd(void) : CMcpFunction(0, false, "chart_indicator") {}
|
| | | ~CMcpFuncChartInd(void) {}
|
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-07-13 21:11:54 -05:00 | | | void CMcpFuncChartInd::Run(CJsonNode ¶m, CJsonBuilderStr* &out)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | //---
|
2026-07-13 21:11:54 -05:00 | | | out = m_shared_builder;
|
2026-06-29 17:48:51 -05:00 | | | const ENUM_MCPFUNC_CHARTIND_DEF mode = CEnumRegFullMt5Mcp::GetValNoRef<ENUM_MCPFUNC_CHARTIND_DEF>(param["mode"].ToString(""), WRONG_VALUE);
|
| | | const long chart_id = param["chart_id"].ToInt(0);
|
| | | const int subwin = (int)param["sub_window"].ToInt(0);
|
2026-06-29 20:43:05 -05:00 | | | //Print(param.ComplexToString());
|
2026-04-27 22:49:28 -05:00 | | |
|
| | | //---
|
2026-06-29 17:48:51 -05:00 | | | switch(mode)
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_CHARTIND_TOTAL:
|
2026-04-28 21:48:06 -05:00 | | | {
|
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(ChartIndicatorsTotal(chart_id, subwin));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_CHARTIND_SHORT_NAME:
|
2026-04-28 21:48:06 -05:00 | | | {
|
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(ChartIndicatorName(chart_id, subwin, (int)param["index"].ToInt(0)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_CHARTIND_ADD:
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | ::ResetLastError();
|
2026-06-29 20:43:05 -05:00 | | | const int handle = (int)param["indicator_handle"].ToInt(-1);
|
| | | if(ChartIndicatorAdd(chart_id, subwin, handle))
|
2026-06-29 17:48:51 -05:00 | | | {
|
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").ValSWV("okey");
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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(StringFormat("Last MQL5 Error = %d, Handle = %d", ::GetLastError(), handle));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -05:00 | | | case MCPFUNC_CHARTIND_DELETE:
|
2026-04-28 21:48:06 -05:00 | | | {
|
2026-06-29 17:48:51 -05:00 | | | ::ResetLastError();
|
| | | if(ChartIndicatorDelete(chart_id, subwin, param["indicator_shortname"].ToString("")))
|
| | | {
|
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").ValSWV("okey");
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | else
|
| | | {
|
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(StringFormat("Last MQL5 Error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | }
|
| | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-06-29 17:48:51 -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("Error, invalid mode mode.. ");
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 17:48:51 -05:00 | | | break;
|
2026-04-28 21:48:06 -05:00 | | | }
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| chart_redraw |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncChartRedraw : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncChartRedraw() : CMcpFunction(0, false, "chart_redraw") {}
|
| | | ~CMcpFuncChartRedraw(void) {}
|
| | |
|
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-07-13 21:11:54 -05:00 | | | void CMcpFuncChartRedraw::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 08:52:21 -05:00 | | | ChartRedraw(param["chart_id"].ToInt(0));
|
2026-04-27 22:49:28 -05:00 | | | //---
|
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").ValSWV("okey");
|
| | | 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 CMcpFuncChartGetSymbolOrPeriod : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncChartGetSymbolOrPeriod(void) : CMcpFunction(0, false, "chart_get_symbol_or_period") {}
|
| | | ~CMcpFuncChartGetSymbolOrPeriod(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 CMcpFuncChartGetSymbolOrPeriod::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;
|
2026-06-03 20:39:25 -05:00 | | | const int8_t mode = (int8_t)param["mode"].ToInt(-1);
|
2026-06-29 20:43:05 -05:00 | | | const long chart_id = param["chart_id"].ToInt(0);
|
2026-06-30 22:34:24 -05:00 | | |
|
2026-04-29 21:15:35 -05:00 | | | switch(mode)
|
| | | {
|
| | | case 0:
|
2026-06-30 22:34:24 -05:00 | | | {
|
2026-06-29 20:43:05 -05:00 | | | ::ResetLastError();
|
| | | const ENUM_TIMEFRAMES tf = ChartPeriod(chart_id);
|
2026-06-30 22:43:53 -05:00 | | | //Print(EnumToString(tf));
|
2026-06-29 20:43:05 -05:00 | | | if(tf == 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("result").ValSWV(StringFormat("Error in ChartPeriod, last mql5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 20:43:05 -05:00 | | | }
|
| | | else
|
| | | {
|
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").ValSWV(EnumToString(tf));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 20:43:05 -05:00 | | | }
|
2026-04-29 21:15:35 -05:00 | | | break;
|
| | | }
|
| | | case 1:
|
| | | {
|
2026-06-29 20:43:05 -05:00 | | | ::ResetLastError();
|
| | | const string simbolo = ChartSymbol(chart_id);
|
| | | if(simbolo == "")
|
| | | {
|
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(StringFormat("Error in ChartPeriod, last mql5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 20:43:05 -05:00 | | | }
|
| | | else
|
| | | {
|
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(simbolo);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 20:43:05 -05:00 | | | }
|
2026-04-29 21:15:35 -05:00 | | | 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("error").ValSWV(StringFormat("Invalid mode = %d, use 0=get timeframe, 1=get symbol", mode));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 21:15:35 -05:00 | | | break;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncChartSrenshot : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncChartSrenshot(void) : CMcpFunction(0, false, "chart_screenshot") {}
|
| | | ~CMcpFuncChartSrenshot(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 CMcpFuncChartSrenshot::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;
|
2026-04-29 21:15:35 -05:00 | | | const string fn = param["file_name"].ToString();
|
2026-06-03 20:39:25 -05:00 | | | const long chart_id = param["chart_id"].ToInt(0);
|
2026-04-29 21:15:35 -05:00 | | | ::ResetLastError();
|
2026-06-29 18:35:38 -05:00 | | | if(!ChartScreenShot(chart_id, fn, (int)param["width"].ToInt(ChartGetInteger(chart_id, CHART_WIDTH_IN_PIXELS)),
|
2026-04-29 21:15:35 -05:00 | | | (int)param["height"].ToInt(ChartGetInteger(chart_id, CHART_HEIGHT_IN_PIXELS)), ALIGN_CENTER))
|
| | | {
|
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("Failed call ChartScreenShot, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 21:15:35 -05:00 | | | return;
|
| | | }
|
| | |
|
| | |
|
| | | //---
|
2026-07-01 11:41:37 -05:00 | | | if(param["as_image_file"].ToBool(false))
|
2026-04-29 21:15:35 -05:00 | | | {
|
2026-06-29 18:35:38 -05:00 | | | if(param["common_flag"].ToBool(true))
|
2026-04-29 21:15:35 -05:00 | | | {
|
2026-06-29 18:35:38 -05:00 | | | if(!FileMove(fn, 0, fn, FILE_COMMON | FILE_REWRITE))
|
| | | {
|
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("Failed call FileMove, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-06-29 18:35:38 -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").Obj();
|
| | | m_shared_builder.KeyWV("full_path").ValSNoRef(TERMINAL_MT5_COMMON_PATH + "\\Files\\" + fn);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 21:15:35 -05:00 | | | }
|
| | | else
|
| | | {
|
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").Obj();
|
| | | m_shared_builder.KeyWV("full_path").ValSNoRef(TERMINAL_MT5_ROOT + "Files\\" + fn);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 21:15:35 -05:00 | | | }
|
| | | }
|
| | | else
|
| | | {
|
2026-06-29 18:35:38 -05:00 | | | uchar bytes[];
|
| | | FileLoad(fn, bytes);
|
| | | uchar key[];
|
| | | uchar b64[];
|
| | | const int t = CryptEncode(CRYPT_BASE64, bytes, key, b64);
|
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").ValSWV(CharArrayToString(b64, 0, t));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 21:15:35 -05:00 | | | }
|
| | | }
|
2026-06-29 17:48:51 -05:00 | | | }
|
2026-04-29 21:15:35 -05:00 | | |
|
| | |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
| | | #endif // FULLMT5MCPBYLEO_SRC_CHARTS_CHARTS_MQH
|