forked from nique_372/FastNLExamples
//+------------------------------------------------------------------+
| |
//| Test.mq5 |
| |
//| Copyright 2025, Leo. |
| |
//| https://www.mql5.com/es/users/nique_372/news |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2025, Leo."
| |
#property link "https://www.mql5.com/es/users/nique_372/news"
| |
#property version "1.00"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
//#define RELEASE_VERSION
| |
#include "..\\..\\Secrets.mqh"
| |
#include <TSN\\FastNL\\Main.mqh>
| |
#include <TSN\\FastNL\\CentralBank.mqh>
| |
#include "..\\..\\..\\AiFeatureEval\\Src\\Correlations.mqh"
| |
#include <TSN\\Std\\Basics\\Try.mqh>
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void OnStart()
| |
{
| |
CCorrelations corr;
| |
corr.CorrelationFuction(F_CORRELATION_KENDALL);
| |
const datetime d = D'2018.01.01 00:00:00';
| |
const datetime h = D'2025.06.01 00:00:00';
| |
| |
//---
| |
#ifdef TSN_FASTNL_FUNC_CTS
| |
TSN_FASTNL_FUNC_CTS(THE_BOT_PLACE_USER_ID);
| |
#else
| |
CiNewsLeo_CalendarInit(THE_BOT_PLACE_USER_ID);
| |
#endif // TSN_MCPSERVER_FUNC_CTS
| |
| |
//---
| |
TSN::ICalendarByLeo* calendar = CiNewsLeo_CreateEconomicCalendar();
| |
| |
//---
| |
string _what = NULL;
| |
TSNSTD_TRY_INI
| |
{
| |
TSNSTD_TRY_EF(calendar.AddCountryByImportances(COUNTRY_ID_USA, "High|Medium|Low"), true, CiNewsLeo_FormatTraceFirst(_what))
| |
TSNSTD_TRY_EF(calendar.SetCalendar(d, h), true, CiNewsLeo_FormatTraceFirst(_what))
| |
TSNSTD_TRY_EF(calendar.GetDataPredifinied(true), true, CiNewsLeo_FormatTraceFirst(_what))
| |
}
| |
TSNSTD_TRY_END
| |
| |
//---
| |
if(_what != NULL)
| |
{
| |
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, _what);
| |
delete calendar;
| |
return;
| |
}
| |
| |
//---
| |
TSN::CEconomicEvents container[];
| |
| |
ArrayResize(container, calendar.ContainerGetEventsSizeByCountryId(COUNTRY_ID_USA));
| |
| |
calendar.ContainerGetDataByCountryId(COUNTRY_ID_USA, container);
| |
| |
const ulong target = TSN::CBL_CountryEventToIdFinal("US", "consumer-price-index-mm");
| |
const int total = ArraySize(container);
| |
int idx_target = 0;
| |
datetime kill_time = wrong_datetime;
| |
const int data_size = 88;
| |
bool is = false;
| |
double output[];
| |
const datetime curr_time = TimeCurrent();
| |
| |
| |
//#define S_LOGS 1
| |
//---
| |
if(is)
| |
{
| |
int start_idx = TSN::GetIdxByEventTime(container, target, d, MAYOR_A_TARGET_TIME);
| |
| |
for(int i = 0; i < total; i++)
| |
{
| |
if(container[i].Porcentage_Array[0].actual_value == ERROR_VARIABLE)
| |
continue;
| |
| |
if(container[i].id == target)
| |
{
| |
double out_arr[];
| |
| |
TSN::AumentarArrayEventos(container[i].Porcentage_Array, start_idx, out_arr);
| |
ArrayPrint(out_arr);
| |
| |
double arr[];
| |
kill_time = container[i].Porcentage_Array[0].time;
| |
ObtenerLosUltimosValoresArr(data_size, 0, out_arr, output);
| |
Print("El kill time: ", kill_time);
| |
printf("tamaño del output: %I64u | data disponible = %d", output.Size(), ArraySize(container[i].Porcentage_Array));
| |
break;
| |
}
| |
}
| |
}
| |
else
| |
{
| |
for(int i = 0; i < total; i++)
| |
{
| |
if(container[i].Porcentage_Array[0].actual_value == ERROR_VARIABLE)
| |
{
| |
if(container[i].id == target)
| |
{
| |
PrintFormat("ERROR CRITICO | EL EVENTO %s tiene un valor actul invalido", target);
| |
ArrayPrint(container[i].Porcentage_Array, 4, " | ");
| |
return;
| |
}
| |
| |
continue;
| |
}
| |
| |
if(container[i].id == target)
| |
{
| |
const int t = ArraySize(container[i].Porcentage_Array);
| |
kill_time = container[i].Porcentage_Array[t - 1].time;
| |
TSN::EconomicEventData evets[];
| |
TSN::ObtenerLosUltimosValoresTester(data_size, container[i].Porcentage_Array, evets, curr_time);
| |
| |
ArrayResize(output, evets.Size());
| |
for(int i = 0; i < ArraySize(output); i++)
| |
output[i] = evets[i].actual_value;
| |
| |
Print("El kill time: ", kill_time);
| |
printf("tamaño del output: %I64u | data disponible = %d", output.Size(), t);
| |
break;
| |
}
| |
}
| |
}
| |
| |
//---
| |
Print("Ultimo id = ", target);
| |
CorrelationAr array[];
| |
| |
for(int i = 0; i < total; i++)
| |
{
| |
const int t = ArraySize(container[i].Porcentage_Array);
| |
if(t < data_size)
| |
{
| |
PrintFormat("Omitiendo el evento %s ya que el tamaño del array = %d, es menor al data size",
| |
container[i].name, ArraySize(container[i].Porcentage_Array));
| |
continue;
| |
}
| |
| |
if(container[i].Porcentage_Array[0].actual_value == ERROR_VARIABLE || container[i].Porcentage_Array[t - 1].time == kill_time)
| |
continue;
| |
| |
if(container[i].id == target || container[i].id == 840050014)
| |
continue;
| |
| |
TSN::EconomicEventData arr[];
| |
/*
| |
CPI CPI TIME
| |
CORE-PCE CORE-PCE
| |
*/
| |
/*
| |
NFP NFP TIME
| |
CPI
| |
*/
| |
#ifdef S_LOGS
| |
Print("El tiempo 0: ", container[i].Porcentage_Array[t - 1].time);
| |
#endif
| |
// Si el timepo del evento es menor al actual evento entonces este predice a->b
| |
// De lo contrario si es mayor el acutla.. entonces usamos lo normal.. solo
| |
int a_tomar = container[i].Porcentage_Array[t - 1].time < kill_time ? data_size : data_size + 1;
| |
| |
TSN::ObtenerLosUltimosValoresTester(a_tomar, container[i].Porcentage_Array, arr, curr_time);
| |
double values[];
| |
int end = a_tomar == data_size ? data_size : a_tomar - 1;
| |
//Print("A tomar: " , a_tomar, " Data size: " , data_size, " End: " , end);
| |
| |
#ifdef S_LOGS
| |
if(start == 0)
| |
Print("EMpezando por 0 todo bien");
| |
else
| |
Print("Emepzando por 1 dadoq ue el valor del tiempo es despues de: ", target);
| |
#endif
| |
| |
ArrayResize(values, end);
| |
| |
//Print("Evento: ", container[i].name, " Tiempo actual: ", container[i].Porcentage_Array[t - 1].time, " Real: ",
| |
// arr[end - 1].time);
| |
| |
for(int x = 0; x < end; x++)
| |
{
| |
values[x] = arr[x].actual_value;
| |
}
| |
| |
if((int)values.Size() < data_size)
| |
{
| |
PrintFormat("El tamaño de data de = %s no coincide | data inicial = %d >> data actual = %u", container[i].name
| |
, t, values.Size());
| |
continue;
| |
}
| |
| |
//---
| |
CorrelationAr new_cor;
| |
ArrayCopy(new_cor.values, values);
| |
new_cor.cols_name = container[i].event_code;
| |
| |
//---
| |
ArrayResize(array, array.Size() + 1);
| |
array[array.Size() - 1] = new_cor;
| |
}
| |
| |
| |
//---
| |
corr.Set(array, output);
| |
corr.Run();
| |
int indexces_cols[];
| |
corr.GetBestCorrelations(indexces_cols, 10);
| |
corr.PlotAnalisis(string(target), "DataNoticias\\", 1300, 500, clrBlack, indexces_cols, true, 0, 10);
| |
| |
//---
| |
delete calendar;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
/*
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.3122234594308072
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: ism-prices-paid
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.32168707577253436
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: import-price-index-ex-petroleum-mm
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.3321596619878823
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: producer-price-index-ex-food-energy-mm
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.33330999243707465
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: pce-price-index-mm
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: -0.33355632836142485
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: markit-services-pmi
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.3388373935641573
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: factory-orders-ex-transportation-mm
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.3477929182640344
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: export-price-index-mm
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.37653834395988955
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: ism-non-manufacturing-prices
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.3779030758088527
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: import-price-index-mm
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Correlation: 0.54645080817985
| |
2025.09.17 07:20:20.968 Test (EURUSD,M1) Col name: producer-price-index-mm
| |
*/
| |
//+------------------------------------------------------------------+
| |
| |
//+------------------------------------------------------------------+
|