FastNLExamples/Src/EAs/NewsTrader/Bot.mq5
Nique_372 Nique_372 117ca6a503
2026-11-05 12:09:22 -05:00
//+------------------------------------------------------------------+
//| NewsTrader.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"
#property strict
//#define TO_INCLUDE1
//#define NEW_BAR_MANAGER_DEBUG
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
//#define RELEASE_VERSION
#include "..\\..\\..\\Secrets.mqh"
#include "Main.mqh"
#include <TSN\\MQLArticles\\PosMgmt\\Trailing Stop.mqh>
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
sinput group "----------| General |----------" //General
input ulong Magic = 777; // Magic Number of EA
sinput group ""
sinput group "-------| Strategy |-------" //Aqui parametros de la estrategia
input ENUM_VERBOSE_LOG_LEVEL log_level_strategy = VERBOSE_LOG_LEVEL_CAUTION; //Strategy log level:
sinput group "-----| TP/SL by Fixed |-----" //TP SL
input ENUM_TYPE_TP_SL_FIXED inp_type_tp_sl_fixed = TP_SL_ATR; //Tipo de tp sl fjo:
sinput group "--| TP SL by Point "
input long sl_point = 250; //Stop Loss In Points
input long tp_point = 500; //Take Profit In Points
sinput group "--| TP SL by Atr "
input int inp_index_atr = 0; //Index del atr
input double inp_atr_multiplier_tp = 2.0; //Multiplicador del atr para el tp
input double inp_atr_multiplier_sl = 2.0; //Multiplicador del atr para el sl
sinput group "--| Ordenes "
input ulong max_deviation_ord = 100; //Maxima desviacion/slípagge de las ordenes en puntos
sinput group ""
sinput group "-------| Account Status |-------" //Account status unico parametros logs
input ENUM_VERBOSE_LOG_LEVEL log_level_account_status = VERBOSE_LOG_LEVEL_ALL; //(Account Status|Ticket Mangement) log level:
sinput group ""
sinput group "-------| Risk Management |-------" //Gestion de riesgo
input TSN::ENUM_LOTE_TYPE Lote_Type = TSN::Dinamico; //Lote Type:
input double lote = 0.1; //Lot size (only for fixed lot)
input TSN::ENUM_MODE_RISK_MANAGEMENT risk_mode = TSN::risk_mode_personal_account; //type of risk management mode
input TSN::ENUM_GET_LOT get_mode = TSN::GET_LOT_BY_STOPLOSS_AND_RISK_PER_OPERATION; //How to get the lot
input double prop_firm_balance = 0; //If risk mode is Prop Firm FTMO, then put your ftmo account balance
input ENUM_VERBOSE_LOG_LEVEL log_level_risk_management = VERBOSE_LOG_LEVEL_WARNINGS; //Risk Management log level:
sinput group "--| ML/Maxium loss/Maxima perdida "
input double percentage_or_money_ml_input = 0; //percentage or money (0 => not used ML)
input TSN::ENUM_RISK_CALCULATION_MODE mode_calculation_ml = TSN::percentage; //Mode calculation Max Loss
input TSN::ENUM_APPLIED_PERCENTAGES applied_percentages_ml = TSN::Balance; //ML percentage applies to:
sinput group "--| MWL/Maximum weekly loss/Perdida maxima semanal "
input double percentage_or_money_mwl_input = 0; //percentage or money (0 => not used MWL)
input TSN::ENUM_RISK_CALCULATION_MODE mode_calculation_mwl = TSN::percentage; //Mode calculation Max weekly Loss
input TSN::ENUM_APPLIED_PERCENTAGES applied_percentages_mwl = TSN::Balance;//MWL percentage applies to:
sinput group "--| MDL/Maximum daily loss/Perdida maxima diaria "
input double percentage_or_money_mdl_input = 0; //percentage or money (0 => not used MDL)
input TSN::ENUM_RISK_CALCULATION_MODE mode_calculation_mdl = TSN::percentage; //Mode calculation Max daily loss
input TSN::ENUM_APPLIED_PERCENTAGES applied_percentages_mdl = TSN::Balance;//MDL percentage applies to:
sinput group "--| GMLPO/Gross maximum loss per operation/Porcentaje a arriesgar por operacion "
input TSN::ENUM_OF_DYNAMIC_MODES_OF_GMLPO mode_gmlpo = TSN::DYNAMIC_GMLPO_FULL_CUSTOM; //Select GMLPO mode:
input double percentage_or_money_gmlpo_input = 10.0; //percentage or money (0 => not used GMLPO)
input TSN::ENUM_RISK_CALCULATION_MODE mode_calculation_gmlpo = TSN::percentage; //Mode calculation Max Loss per operation
input TSN::ENUM_APPLIED_PERCENTAGES applied_percentages_gmlpo = TSN::Balance;//GMPLO percentage applies to:
sinput group "-----| Optional GMLPO settings, Dynamic GMLPO |-----"
sinput group "--| Full customizable dynamic GMLPO "
input string note1 = "subtracted from your total balance to establish a threshold."; //This parameter determines a specific percentage that will be
input string str_percentages_to_be_reviewed = "15,30,50"; //percentages separated by commas.
input string note2 = "a new risk level will be triggered on your future trades: "; //When the current balance (equity) falls below this threshold
input string str_percentages_to_apply = "10,20,25"; //percentages separated by commas.
input string note3 = "0 in both parameters => do not use dynamic risk in gmlpo"; //Note:
sinput group "--| Fixed dynamic GMLPO with parameters "
sinput group "- 1 -"
input string note1_1 = "subtracted from your total balance to establish a threshold."; //This parameter determines a specific percentage that will be
input double inp_balance_percentage_to_activate_the_risk_1 = 2.0; //percentage 1 that will be exceeded to modify the risk separated by commas
input string note2_1 = "a new risk level will be triggered on your future trades: "; //When the current balance (equity) falls below this threshold
input double inp_percentage_to_be_modified_1 = 1.0;//new percentage 1 to which the gmlpo is modified
sinput group "- 2 -"
input double inp_balance_percentage_to_activate_the_risk_2 = 5.0;//percentage 2 that will be exceeded to modify the risk separated by commas
input double inp_percentage_to_be_modified_2 = 0.7;//new percentage 2 to which the gmlpo is modified
sinput group "- 3 -"
input double inp_balance_percentage_to_activate_the_risk_3 = 7.0;//percentage 3 that will be exceeded to modify the risk separated by commas
input double inp_percentage_to_be_modified_3 = 0.5;//new percentage 3 to which the gmlpo is modified
sinput group "- 4 -"
input double inp_balance_percentage_to_activate_the_risk_4 = 9.0;//percentage 4 that will be exceeded to modify the risk separated by commas
input double inp_percentage_to_be_modified_4 = 0.33;//new percentage 4 1 to which the gmlpo is modified
sinput group "--| MDP/Maximum daily profit/Maxima ganancia diaria "
input bool mdp_is_strict = true; //MDP is strict?
input double percentage_or_money_mdp_input = 0; //percentage or money (0 => not used MDP)
input TSN::ENUM_RISK_CALCULATION_MODE mode_calculation_mdp = TSN::percentage; //Mode calculation Max Daily Profit
input TSN::ENUM_APPLIED_PERCENTAGES applied_percentages_mdp = TSN::Balance;//MDP percentage applies to:
sinput group "-------| News |-------"
sinput group "--| General"
input datetime fecha_desde_incio_noticias = D'2005.01.01'; //Start date for TSN::calendar data collection (equal to generated csv files)
input uint8_t seg_antes_despues = 5; //Segundos antes y depues para operar noticias
sinput group "--| Cadenas "
input string cadena_EUR = "ecb-interest-rate-decision,unemployment-rate,gross-domestic-product-qq,consumer-price-index-mm,employment-change-qq,producer-price-index-mm"; //Important EUR Events (MQL5 Calendary event code) separated by ,
input string cadena_CAD = "boc-interest-rate-decision,cpi-mm,unemployment-rate,employment-change,gdp-qq,ippi-mm"; //Important CAD Events (MQL5 Calendary event code) separated by ,
input string cadenas_CHF = "snb-interest-rate-decision,gdp-qq,unemployment-rate,cpi-mm,employment-level,ppi-mm"; //Important CHF Events (MQL5 Calendary event code) separated by ,
input string cadena_GBP = "cpi-mm,boe-interest-rate-decision,unemployment-rate,gdp-qq,employment-change-3-months,ppi-output-mm"; //Important GBP Events (MQL5 Calendary event code) separated by ,
input string cadena_AUD = "gdp-qq,unemployment-rate,employment-change,rba-interest-rate-decision,cpi-qq,ppi-qq"; //Important AUD Events (MQL5 Calendary event code) separated by ,
input string cadena_NZD = "rbnz-interest-rate-decision,unemployment-rate,gdp-qq,cpi-qq,employment-change-qq,ppi-output-qq"; //Important NZD Events (MQL5 Calendary event code) separated by ,
input string cadena_JPY = "gross-domestic-product-qq,unemployment-rate,boj-interest-rate-decision"; //Important JPY Events (MQL5 Calendary event code) separated by ,
sinput group "--| Objetos graficos"
input string type_draw_events = "Line|Event"; //Tipo de dibujado de los eventos
input color color_eventos_high = clrRed; //Color de los eventos de alta impotancia
input color color_eventos_low = clrSilver; //Color de los eventos de baja impotancia
input color color_eventos_mid = C'0xF8,0xDA,0x07'; //Color de los eventos de media impotancia
input color color_eventos_none = C'0x8A,0x84,0x8A'; //Color de los eventos de ninguna impotancia
input int16_t width_events = 1; //Ancho de los eventos
sinput group ""
sinput group "-------| Trailing Stop |-------"
input bool use_trailing_stop = false; // Enable trailing stop
input TSN::ENUM_TSN_TRAILING_STOP_MODE_BASIC mode_trailing_stop = TSN::TRAILING_STOP_MODE_BASIC_ATR; // Select the indicator used for trailing stop
input ENUM_VERBOSE_LOG_LEVEL log_level_trailing_stop = VERBOSE_LOG_LEVEL_ALL; // Trailing stop log level:
sinput group "-- Trailing by Atr"
input ENUM_TIMEFRAMES tsl_timeframe_atr = PERIOD_CURRENT; // Timeframe used for ATR calculation
input int tsl_index_atr = 0; // Buffer index for ATR, typically 0
input double tsl_atr_multiplier = 1.5; // ATR multiplier to set trailing distance from current price
input int tsl_atr_period = 14; // ATR period used for calculation
sinput group "-- Trailing by Prev Low/High"
input ENUM_TIMEFRAMES tsl_timeframe_prev_low_high = PERIOD_CURRENT; // Timeframe used to find previous lows/highs
input int tsl_index_prev_low_high = 1; // Index for calculating previous lows/highs
sinput group "-- Trailing by Sar"
input ENUM_TIMEFRAMES tsl_timeframe_sar = PERIOD_CURRENT; // Timeframe used for SAR calculation
input int tsl_index_sar = 1; // Buffer index for SAR, typically 1
input double tsl_sar_step = 0.02; // SAR step value
input double tsl_sar_maximum = 0.20; // SAR maximum value
sinput group "-- Trailing by MA"
input ENUM_TIMEFRAMES tsl_timeframe_ma = PERIOD_CURRENT; // Timeframe used for Moving Average calculation
input ENUM_MA_METHOD tsl_ma_method = MODE_EMA; // Moving Average method: EMA, SMA, etc.
input int tsl_index_ma = 1; // Buffer index for Moving Average, typically 1
input int tsl_ma_period = 14; // Period used for Moving Average calculation
sinput group "-- Trailing by AMA"
input ENUM_TIMEFRAMES tsl_timeframe_ama = PERIOD_CURRENT; // Timeframe used for AMA calculation
input int tsl_index_ama = 1; // Buffer index for AMA, typically 1
input int tsl_ama_period = 6; // AMA base period
input int tsl_ama_fast_period = 6; // Fast moving average period
input int tsl_ama_low_period = 50; // Slow moving average period
sinput group "-- Trailing Fixed"
input int tsl_fixed_start = 50; // Distance to start the fixed trailing stop
input int tsl_fixed_step = 10; // Step size for adjusting the fixed trailing stop
sinput group "-- Trailing by Swings"
input ENUM_TIMEFRAMES tsl_swings_timeframe = PERIOD_CURRENT; // Timeframe used for swing detection
input int tsl_swings_length = 4; // Length for detecting swing points
input int tsl_swings_index = 1; // Buffer index for swing detection, typically 1
input color tsl_color_bull_swing = clrGreen; // Color for bullish swing points
input color tsl_color_bear_swing = clrRed; // Color for bearish swing points
//+------------------------------------------------------------------+
//| Global |
//+------------------------------------------------------------------+
int8_t idx_controler_w1 = INVALID_INDEX;
int8_t idx_bar_controlerd1 = INVALID_INDEX;
int8_t idx_bar_mn1 = INVALID_INDEX;
//---
TSN::CNewsTrader strategy(Magic, _Symbol, _Period, 0, 0, max_deviation_ord);
TSN::CTrailingStopManager g_trailing_creator;
TSN::TrailingStopRun g_trailing_stop;
uint g_trade_flags = 0;
TSN::CLossProfitManager g_loss_profit_manager; // LossProfitManager
TSN::CAtrOptimized* g_atr_opt = NULL; // Zero (index 0) o NonZero (index != 0), segun inp_index_atr
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Añadimos los ejecutores..
g_new_bar_manager.GetPosExecute(PERIOD_D1, idx_bar_controlerd1);
g_new_bar_manager.GetPosExecute(PERIOD_W1, idx_controler_w1);
g_new_bar_manager.GetPosExecute(PERIOD_MN1, idx_bar_mn1);
//--- Caledario
datetime desde = fecha_desde_incio_noticias;
datetime hasta = iTime(_Symbol, PERIOD_D1, 0);
// inicilzaicion del calendario
#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
// Creacion
TSN::calendar = CiNewsLeo_CreateEconomicCalendar();
CAutoCleaner::AddPtr(TSN::calendar);
// Filtrado
TSN::calendar.FilterBySymbol(_Symbol); //Siempre configurar el filtro antes de agregar paises
// Def
ulong temp[];
// Uno a uno
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_US, TSN::cadena_USD_operate, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_USA, temp);
//ArrayPrint(temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_CA, cadena_CAD, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_CANADA, temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_EU, cadena_EUR, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_EUROPEAN_UNION, temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_GB, cadena_GBP, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_UNITED_KINGDOM, temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_AU, cadena_AUD, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_AUSTRALIA, temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_CH, cadenas_CHF, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_SWITZERLAND, temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_JP, cadena_JPY, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_JAPAN, temp);
TSN::CalendarByLeo_ParseStrEvents(CALENDAR_COUNTRY_CODE_HASH_NZ, cadena_NZD, ',', temp);
TSN::calendar.AddCountryByEventList(COUNTRY_ID_NEW_ZEALAND, temp);
// Final
TSN::calendar.SetObtenerValoresActuales(true);
TSN::calendar.SetNoticiasChecker(seg_antes_despues, 10);
//--- Bloque try
string _what = NULL;
TSNSTD_TRY_INI
{
//--- calendar final
// Seteamos el calendario
TSNSTD_TRY_EF(TSN::calendar.SetCalendar(desde, hasta), true,
CiNewsLeo_FormatTraceFirst(_what));
// First corrida
TSNSTD_TRY_EF(TSN::calendar.First(TimeCurrent()), true,
CiNewsLeo_FormatTraceFirst(_what))
//--- Estrategia
if(inp_index_atr == 0)
g_atr_opt = new TSN::CAtrOptimizedZero(PERIOD_CURRENT, _Symbol, 14);
else
g_atr_opt = new TSN::CAtrOptimizedNonZero(PERIOD_CURRENT, _Symbol, inp_index_atr, 14);
//---
CAutoCleaner::AddPtr(g_atr_opt);
//---
strategy.Set(TSN::calendar.CountryIdSymbolACambiar());
strategy.SetAtrTP_SL(g_atr_opt, inp_atr_multiplier_tp, inp_atr_multiplier_sl);
strategy.SetOperateMode(TR_BUY_SELL, inp_type_tp_sl_fixed);
strategy.SetTP_SL(tp_point, sl_point);
strategy.AddLogFlags(log_level_strategy);
if(Lote_Type == TSN::Fijo)
strategy.FixedLotSize(lote);
TSN::calendar.AddHook(&strategy); // Lo agregamos para que reciba eventos...
//--- Trailing stop y gestion de riesgo
//--- Trailing stop
if(use_trailing_stop)
{
g_trailing_creator.SetTrailingAMA(tsl_index_ama, tsl_timeframe_ama, tsl_ama_period, tsl_ama_low_period, tsl_ama_fast_period);
g_trailing_creator.SetTrailingAtr(tsl_atr_period, tsl_atr_multiplier, tsl_timeframe_atr, tsl_index_atr);
g_trailing_creator.SetTrailingFixed(tsl_fixed_start, tsl_fixed_step);
g_trailing_creator.SetTrailingMa(tsl_index_ma, tsl_timeframe_ma, tsl_ma_period, tsl_ma_method);
g_trailing_creator.SetTrailingPrev(tsl_timeframe_prev_low_high, tsl_index_prev_low_high);
g_trailing_creator.SetTrailingSar(tsl_index_sar, tsl_timeframe_sar, tsl_sar_step, tsl_sar_maximum);
g_trailing_creator.SetTrailingSwings(tsl_swings_timeframe, tsl_swings_index, 0, tsl_color_bull_swing, tsl_color_bear_swing, tsl_swings_length, 100);
g_trailing_stop = g_trailing_creator.Create(mode_trailing_stop, Magic, _Symbol);
TSNSTD_TRY_EF(g_trailing_stop.IsValid(), true,
_what = StringFormat("Fallo al crear TSL ultimo err = %s", EnumToString(g_trailing_creator.LastErr())))
g_trailing_stop.m_trailing.AddLogFlags(log_level_trailing_stop);
}
//--- Gestion de riesgo
TSN::CRiskManagementCreator manager;
manager.SetPropirm(prop_firm_balance);
//---
TSN::MQLArtRMCreatorRes result = manager.GetRiskPointer(risk_mode, Magic, get_mode);
TSNSTD_TRY_EF(result.res, TSN::TSNMQLART_RISKMANCREATOR_RES_OK,
TSN::MQLArtRMCreatorRes::FormatErr(result, _what))
//---
TSN::risk = result.ptr;
TSN::risk.AddLogFlags(log_level_risk_management);
TSN::risk.SetLossProfitManager(g_loss_profit_manager);
CAutoCleaner::AddPtr(TSN::risk);
// Seteamos los parametros
string to_apply = str_percentages_to_apply, to_modfied = str_percentages_to_be_reviewed;
if(mode_gmlpo == TSN::DYNAMIC_GMLPO_FIXED_PARAMETERS)
TSN::CRmFunctions::SetDynamicUsingFixedParameters(inp_balance_percentage_to_activate_the_risk_1, inp_balance_percentage_to_activate_the_risk_2, inp_balance_percentage_to_activate_the_risk_3
, inp_balance_percentage_to_activate_the_risk_4, inp_percentage_to_be_modified_1, inp_percentage_to_be_modified_2, inp_percentage_to_be_modified_3, inp_percentage_to_be_modified_4
, to_modfied, to_apply);
//--- Maximas perdidas y ganancias
TSNSTD_TRY_INI_S // nota: genera bool _err implicito
{
TSNSTD_TRY_SE(TSN::risk.AddLP(percentage_or_money_mdl_input, applied_percentages_mdl, mode_calculation_mdl, TSN::LP_MDL, true), true);
TSNSTD_TRY_SE(TSN::risk.AddLP(percentage_or_money_gmlpo_input, applied_percentages_gmlpo, mode_calculation_gmlpo, TSN::LP_GMLPO, true,
(mode_gmlpo != TSN::NO_DYNAMIC_GMLPO), to_modfied, to_apply), true);
TSNSTD_TRY_SE(TSN::risk.AddLP(percentage_or_money_ml_input, applied_percentages_ml, mode_calculation_ml, TSN::LP_ML, true), true);
TSNSTD_TRY_SE(TSN::risk.AddLP(percentage_or_money_mwl_input, applied_percentages_mwl, mode_calculation_mwl, TSN::LP_MWL, true), true);
TSNSTD_TRY_SE(TSN::risk.AddLP(percentage_or_money_mdp_input, applied_percentages_mdp, mode_calculation_mdp, TSN::LP_MDP, mdp_is_strict), true);
TSN::risk.EndAddProfitLoss(); //Ejecutar esto cada vez que se termina de setear las maximas peridas y gancnasias
}
TSNSTD_TRY_END;
//---
TSNSTD_TRY_N_EF(_err, true, TSN::CRiskManagemet::FormatErr(TSN::risk, _what))
}
TSNSTD_TRY_END;
//---
if(_what != NULL) // error final
{
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, _what);
return INIT_FAILED;
}
//---
if(TSN::risk.IsWarningLogEnabled() && TSN::risk.TotalWarns())
{
string str;
TSN::CRiskManagemet::FormatRiskWarns(TSN::risk, str);
FastLog(FUNCION_ACTUAL, WARNING_TEXT, str);
}
//--- Inicilizamos la cuenta
TSN::account_status.AddLogFlags(log_level_account_status);
TSN::account_status.OnInitEvent();
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
CAutoCleaner::Deinit(reason);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
const datetime time_curr = TimeCurrent();
g_new_bar_manager.Execute(time_curr);
//--- Bloque 1 | Control diario
if(CNewBarManager_IsNewBarM1(g_new_bar_manager) && CNewBarManager_IsNewBar(g_new_bar_manager, idx_bar_controlerd1))
{
//---
TSN::calendar.OnNewDay(time_curr);
//---
CBasicEvents::OnNewDay(time_curr);
TSNMQLART_U_BEVENTS_MAN_REM_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_DAY);
//---
if(CNewBarManager_IsNewBar(g_new_bar_manager, idx_controler_w1))
{
CBasicEvents::OnNewWeek(time_curr);
TSNMQLART_U_BEVENTS_MAN_REM_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_WEEK);
}
//--- Nuevo mes
// no uso tradeflags dado que no hay parametros para un Monthly.. pero si lo hubiera:
//TSNMQLART_U_BEVENTS_MAN_REM_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_MON);
if(CNewBarManager_IsNewBar(g_new_bar_manager, idx_bar_mn1))
CBasicEvents::OnNewMonth(time_curr);
}
//---
if(TSN::account_status_positions_open)
{
//--- Solo una cuenta
ACCOUNTSTATUS_ONEVERYTICK
//---
if(TSNMQLART_U_BEVENTS_MAN_TRADE_NOW(g_trade_flags))
{
if(g_loss_profit_manager.MaxLossIsSuperated())
{
const int type = g_loss_profit_manager.GetLastLossSuperatedType();
if(type < TSN::LP_ML)
{
TSN::risk.CloseAllPositions();
// añadimos segun corresponda
TSNMQLART_U_BEVENTS_MAN_ADD_F(g_trade_flags, TSNMQLART_RM_LP_M_BEVENTS_F_LOSS(type));
Print(TSN::g_mqarticles_lp_str_names[type], " is superated now");
}
else // Manejo de las demas perdidas (ML)
{
if(risk_mode == TSN::risk_mode_propfirm_dynamic_daiy_loss)
Print("The expert advisor lost the funding test");
else
Print("Maximum loss exceeded now");
//---
TSN::risk.CloseAllPositions();
Remover();
}
}
else
if(g_loss_profit_manager.MaxProfitIsSuperated())
{
// NOTA: ahora mismo solo hay un profit agregado (MDP), es el unico que se puede activar
TSN::risk.CloseAllPositions();
TSNMQLART_U_BEVENTS_MAN_ADD_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_DAY);
Print("Excellent Maximum daily profit achieved");
}
}
}
//---
if(use_trailing_stop)
g_trailing_stop.OnTickEvent(time_curr);
//--- Si hay almenos una bandera activa no se puede operar
if(TSNMQLART_U_BEVENTS_MAN_NO_TRADE_NOW(g_trade_flags))
return;
//--- Chekeamos si es hora
TSN::calendar.OnTickEvent(time_curr);
//--- Listo eventos ahora..
if(TSN::calendar.NewsIsComming())
{
TSN::calendar.GetEvents(time_curr);
TSN::calendar.OnEndNews(time_curr);
}
}
//+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
const MqlTradeRequest& request,
const MqlTradeResult& result)
{
//---
TSN::account_status.OnTradeTransactionEvent(trans);
}
//+------------------------------------------------------------------+