106 行
4.3 KiB
MQL5
106 行
4.3 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Test.mq5 |
|
|
//| Copyright 2026, Niquel Mendoza. |
|
|
//| https://www.mql5.com/ |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2026, Niquel Mendoza."
|
|
#property link "https://www.mql5.com/"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Include |
|
|
//+------------------------------------------------------------------+
|
|
#include <TSN\\LLM\\RegDef.mqh>
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Inputs |
|
|
//+------------------------------------------------------------------+
|
|
input string InpEaServerFoderName = "LLmRegistery\\";
|
|
input bool InpEaFilesInCommonFolder = true;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Global variables |
|
|
//+------------------------------------------------------------------+
|
|
long g_chart_id = -1;
|
|
int g_sql_handle = INVALID_HANDLE;
|
|
const long g_my = ChartID();
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//--- Parse
|
|
TSN::CJsonParser js;
|
|
const string fn_js = InpEaServerFoderName+ LLMREG_FILENAME_CONFIRM_JSON;
|
|
const int ext = js.AssingFile(fn_js, InpEaFilesInCommonFolder);
|
|
if(!js.AutoParseByFileExt(ext))
|
|
{
|
|
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "Fallo al parsear json inicial");
|
|
return INIT_FAILED;
|
|
}
|
|
|
|
//--- Lecutra
|
|
TSN::CJsonNode root = js.GetRoot();
|
|
g_chart_id = root["chart_id"].ToInt(-1);
|
|
if(g_chart_id == -1)
|
|
{
|
|
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "Campo chart id invalido en json");
|
|
return INIT_FAILED;
|
|
}
|
|
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Datos del json:\nChartID = %I64d\nLast revised time = %s"
|
|
, g_chart_id, root["last_date_revised"].ToString()));
|
|
|
|
//--- Apertura..
|
|
::GetLastError();
|
|
g_sql_handle = DatabaseOpen(InpEaServerFoderName + LLMREG_FILENAME_SQL,
|
|
DATABASE_OPEN_READWRITE | (InpEaFilesInCommonFolder ? DATABASE_OPEN_COMMON : 0));
|
|
if(g_sql_handle == INVALID_HANDLE)
|
|
{
|
|
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, StringFormat("Fallo al abrir sql, quizas no exista, ultimo err = %d", ::GetLastError()));
|
|
return INIT_FAILED;
|
|
}
|
|
if(!DatabaseExecute(g_sql_handle, StringFormat("INSERT OR IGNORE INTO charts_id (chart_id) VALUES(%I64d)", g_my)))
|
|
{
|
|
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "Fallo al instrat chart id en la tabla, o ya eixste");
|
|
return INIT_FAILED;
|
|
}
|
|
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
if(!DatabaseExecute(g_sql_handle, StringFormat("DELETE FROM charts_id WHERE chart_id = %I64d;", g_my)))
|
|
{
|
|
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "Fallo al instrat chart id en la tabla, o ya eixste");
|
|
}
|
|
DatabaseClose(g_sql_handle);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
//--- Nada
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| ChartEvent function |
|
|
//+------------------------------------------------------------------+
|
|
void OnChartEvent(const int32_t id,
|
|
const long &lparam,
|
|
const double &dparam,
|
|
const string &sparam)
|
|
{
|
|
//---
|
|
if(id == CHARTEVENT_CUSTOM + LLMREG_ON_UPDATE)
|
|
{
|
|
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Base de datos de modelos ha sido actulizada");
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|