geforkt von nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| Order Block EA MT5.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
| |
#property tester_indicator "OrderBlockIndPart2.ex5"
| |
| |
// Esto sirve para usar solo el profit del EA para los limites no de los demas ea
| |
// Util si se corre con varios EAs..
| |
//#define MQLARTICLES_RM_MULTI_EA_MODE
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
//#define MORE_INFO_LOSS_PROFIT_DEFINE
| |
| |
//---
| |
#include "..\\..\\..\\PosMgmt\\BE\\Breakeven.mqh"
| |
#include "..\\..\\..\\PosMgmt\\Partials.mqh"
| |
#include "..\\..\\..\\Account\\RM\\RiskManagement\\Main.mqh"
| |
#include "..\\..\\..\\Account\\RM\\RiskManagement\\LPMods\\Examples.mqh"
| |
| |
#include <TSN\\Std\\Memory.mqh>
| |
#include <TSN\\Std\\Basics\\Try.mqh>
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CTrade tradep;
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
sinput group "-------| Order Block EA settings |-------"
| |
input ulong InpMagic = 545244; //Magic number
| |
| |
//---
| |
#include "..\\..\\Indicator\\EaCommon.mqh"
| |
| |
//---
| |
sinput group ""
| |
sinput group "-------| Account Status |-------"
| |
input ENUM_VERBOSE_LOG_LEVEL InpLogLevelAccountStatus = VERBOSE_LOG_LEVEL_ERROR_ONLY; //(Account Status|Ticket Mangement) log level:
| |
| |
sinput group ""
| |
sinput group "-------| Risk Management |-------"
| |
input TSN::ENUM_LOTE_TYPE InpLoteType = TSN::Dinamico; //Lote Type:
| |
input double InpLote = 0.1; //Lot size (only for fixed lot)
| |
input TSN::ENUM_MODE_RISK_MANAGEMENT InpRiskMode = TSN::risk_mode_personal_account; //type of risk management mode
| |
input TSN::ENUM_GET_LOT InpGetMode = TSN::GET_LOT_BY_STOPLOSS_AND_RISK_PER_OPERATION; //How to get the lot
| |
input double InpPropFirmBalance = 0; //If risk mode is Prop Firm FTMO, then put your ftmo account balance
| |
input ENUM_VERBOSE_LOG_LEVEL InpLogLevelRiskManagement = VERBOSE_LOG_LEVEL_ERROR_ONLY; //Risk Management log level:
| |
| |
sinput group "- ML/Maximum loss/Maximum loss -"
| |
input double InpPercentageOrMoneyMlInput = 0; //percentage or money (0 => not used ML)
| |
input TSN::ENUM_RISK_CALCULATION_MODE InpModeCalculationMl = TSN::percentage; //Mode calculation Max Loss
| |
input TSN::ENUM_APPLIED_PERCENTAGES InpAppliedPercentagesMl = TSN::Balance; //ML percentage applies to:
| |
| |
sinput group "- MWL/Maximum weekly loss/Maximum weekly loss -"
| |
input double InpPercentageOrMoneyMwlInput = 0; //percentage or money (0 => not used MWL)
| |
input TSN::ENUM_RISK_CALCULATION_MODE InpModeCalculationMwl = TSN::percentage; //Mode calculation Max weekly Loss
| |
input TSN::ENUM_APPLIED_PERCENTAGES InpAppliedPercentagesMwl = TSN::Balance;//MWL percentage applies to:
| |
| |
sinput group "- MDL/Maximum daily loss/Maximum daily loss -"
| |
input double InpPercentageOrMoneyMdlInput = 3.0; //percentage or money (0 => not used MDL)
| |
input TSN::ENUM_RISK_CALCULATION_MODE InpModeCalculationMdl = TSN::percentage; //Mode calculation Max daily loss
| |
input TSN::ENUM_APPLIED_PERCENTAGES InpAppliedPercentagesMdl = TSN:: Balance; //MDL percentage applies to:
| |
| |
sinput group "- GMLPO/Gross maximum loss per operation/Percentage to risk per operation -"
| |
input TSN::ENUM_OF_DYNAMIC_MODES_OF_GMLPO InpModeGmlpo = TSN::NO_DYNAMIC_GMLPO; //Select GMLPO mode:
| |
input double InpPercentageOrMoneyGmlpoInput = 2.0; //percentage or money (0 => not used GMLPO)
| |
input TSN::ENUM_RISK_CALCULATION_MODE InpModeCalculationGmlpo = TSN::percentage; //Mode calculation Max Loss per operation
| |
input TSN::ENUM_APPLIED_PERCENTAGES InpAppliedPercentagesGmlpo = TSN::Balance;//GMPLO percentage applies to:
| |
| |
sinput group "-- Optional GMLPO settings, Dynamic GMLPO"
| |
sinput group "--- Full customizable dynamic GMLPO"
| |
input string InpNote1 = "subtracted from your total balance to establish a threshold."; //This parameter determines a specific percentage that will be
| |
input string InpStrPercentagesToBeReviewed = "15,30,50"; //percentages separated by commas.
| |
input string InpNote2 = "a new risk level will be triggered on your future trades: "; //When the current balance (equity) falls below this threshold
| |
input string InpStrPercentagesToApply = "10,20,25"; //percentages separated by commas.
| |
input string InpNote3 = "0 in both parameters => do not use dynamic risk in gmlpo"; //Note:
| |
| |
sinput group "--- Fixed dynamic GMLPO with parameters"
| |
sinput group "- 1 -"
| |
input string InpNote11 = "subtracted from your total balance to establish a threshold."; //This parameter determines a specific percentage that will be
| |
input double InpBalancePercentageToActivateTheRisk1 = 2.0; //percentage 1 that will be exceeded to modify the risk separated by commas
| |
input string InpNote21 = "a new risk level will be triggered on your future trades: "; //When the current balance (equity) falls below this threshold
| |
input double InpPercentageToBeModified1 = 1.0;//new percentage 1 to which the gmlpo is modified
| |
sinput group "- 2 -"
| |
input double InpBalancePercentageToActivateTheRisk2 = 5.0;//percentage 2 that will be exceeded to modify the risk separated by commas
| |
input double InpPercentageToBeModified2 = 0.7;//new percentage 2 to which the gmlpo is modified
| |
sinput group "- 3 -"
| |
input double InpBalancePercentageToActivateTheRisk3 = 7.0;//percentage 3 that will be exceeded to modify the risk separated by commas
| |
input double InpPercentageToBeModified3 = 0.5;//new percentage 3 to which the gmlpo is modified
| |
sinput group "- 4 -"
| |
input double InpBalancePercentageToActivateTheRisk4 = 9.0;//percentage 4 that will be exceeded to modify the risk separated by commas
| |
input double InpPercentageToBeModified4 = 0.33;//new percentage 4 1 to which the gmlpo is modified
| |
| |
sinput group "-- MDP/Maximum daily profit/Maximum daily profit --"
| |
input bool InpMdpIsStrict = true; //MDP is strict?
| |
input double InpPercentageOrMoneyMdpInput = 11.0; //percentage or money (0 => not used MDP)
| |
input TSN::ENUM_RISK_CALCULATION_MODE InpModeCalculationMdp = TSN::percentage; //Mode calculation Max Daily Profit
| |
input TSN::ENUM_APPLIED_PERCENTAGES InpAppliedPercentagesMdp = TSN::Balance;//MDP percentage applies to:
| |
| |
sinput group ""
| |
sinput group "-------| Risk Modifier |-------"
| |
input bool InpActivarModificadorDeRiesgo = false; // Enables dynamic risk adjustment (Booster)
| |
input double InpStepMod = 2.0; // Increment applied to risk each time the condition is met
| |
input double InpStart = 2.0; // Profit percentage from which risk adjustment begins
| |
input TSN::ENUM_MULTIPLIER_METHOD_DR InpMethodDr = TSN::DR_EXPONECIAL; // Type of progression used to increase risk
| |
| |
sinput group ""
| |
sinput group "-------| Risk modifier 2 |-------"
| |
input bool InpActivarModificadorDeRiesgo2 = false; //Activate risk modifier 2
| |
input string InpStrPercentagesToApplyRiesgoCts = "6, 8, 10, 20, 25"; //Percentages to apply
| |
| |
sinput group ""
| |
sinput group "-------| Risk modifier 3 by Kevin |-------"
| |
input bool InpActivarModificadorDeRiesgo3 = false; //Activate risk modifier 3
| |
input double InpConstante = 8.0; //Function constant
| |
| |
sinput group ""
| |
sinput group "-------| Session |-------"
| |
input char InpPaSessionStartHour = 1; // Start hour to operate (0-23)
| |
input char InpPaSessionStartMinute = 0; // Start minute to operate (0-59)
| |
input char InpPaSessionEndHour = 23; // End hour to operate (1-23)
| |
input char InpPaSessionEndMinute = 0; // End minute to operate (0-59)
| |
| |
sinput group ""
| |
sinput group "-------| Breakeven |-------"
| |
input bool InpUseBe = true; // Enable Breakeven logic
| |
input TSN::ENUM_BREAKEVEN_TYPE InpTypeBreakEven = TSN::BREAKEVEN_TYPE_RR; // Calculation method (RR, ATR, or fixed points)
| |
input ENUM_VERBOSE_LOG_LEVEL InpLogLevelBe = VERBOSE_LOG_LEVEL_ERROR_ONLY; // Break Even log level:
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
sinput group "--- Breakeven based on Risk/Reward (RR) ---"
| |
input string InpBeRrAdv = "Requires a configured Stop Loss."; // Warning: Stop Loss is required to calculate RR
| |
input double InpBeRrDbl = 1.0; // Risk/Reward ratio to activate Breakeven (e.g. 1.0)
| |
input TSN::ENUM_TYPE_EXTRA_BE_BY_RRR InpBeTypeExtraRr = TSN::EXTRA_BE_RRR_BY_ATR; // Method to adjust Breakeven price (ATR or points)
| |
input double InpBeExtraPointsRrOrAtrMultiplier = 1.0; // Adjustment value: ATR multiplier (atr 14 period) if method = ATR, or fixed points if method = Points
| |
| |
sinput group "--- Breakeven based solely on ATR ---"
| |
input double InpBeAtrMultiplier = 2.0; // ATR multiplier to trigger Breakeven (atr 14 period)
| |
input double InpBeAtrMultiplierExtra = 1.0; // Additional multiplier for precise Breakeven adjustment (atr 14 period)
| |
| |
sinput group "--- Breakeven based on fixed points ---"
| |
input int InpBeFixedPointsToPutBe = 200; // Minimum distance (in points) to trigger Breakeven
| |
input int InpBeFixedPointsExtra = 100; // Extra points added when Breakeven is triggered
| |
| |
sinput group ""
| |
sinput group "-------| Partial Closures |-------"
| |
input ENUM_VERBOSE_LOG_LEVEL InpLogLevelPartials = VERBOSE_LOG_LEVEL_ALL; // Partial Closures log level
| |
input string InpComentVolumen4 = "Use '0' in both to disable. Order from lowest to highest."; //->
| |
input string InpPartesDelTpDondeSeTomaraParciales = "0"; // Percentage of TP distance where partials trigger
| |
input string InpComentParciales1 = "List of TP levels (%) to trigger partials."; //->
| |
input string InpComentParciales2 = "Ex: \"25,50,75\" triggers at 25%, 50%, 75%."; //->
| |
input string InpComentParciales3 = "String allows multiple dynamic levels."; //->
| |
input string InpSeparatorPar = ""; // -------
| |
input string InpVolumenQueSeQuitaraDeLaPosicionEnPorcentaje = "0"; // Volume to close at each defined level
| |
input string InpComentVolumen1 = "Percentage of total volume closed at each level."; //->
| |
input string InpComentVolumen2 = "Must match count of TP level entries."; //->
| |
input string InpComentVolumen3 = "Ex: \"30,40,30\" closes 30%, 40%, then 30%."; //->
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
TSN::CRiskManagemet *risk;
| |
TSN::CBasicPartials g_partials;
| |
TSN::CBreakEvenBase* g_breakeven;
| |
const bool g_partials_enabled = InpPartesDelTpDondeSeTomaraParciales != PARTIAL_NO_APPLIED
| |
&& InpVolumenQueSeQuitaraDeLaPosicionEnPorcentaje != PARTIAL_NO_APPLIED;
| |
| |
//--- Handles
| |
int order_block_indicator_handle = INVALID_HANDLE;
| |
int hanlde_ma = INVALID_HANDLE;
| |
| |
//--- Global buffers
| |
double tp1[];
| |
double tp2[];
| |
double sl1[];
| |
double sl2[];
| |
| |
//--- Session
| |
datetime start_sesion;
| |
datetime end_sesion;
| |
| |
//--- General
| |
TSN::CBarControlerFastMinors_D1 bar_d1;
| |
TSN::CBarControlerFastW1 bar_w1;
| |
TSN::CBarControlerFastMN1 bar_mn1;
| |
TSN::CBarControlerFast bar_curr(PERIOD_CURRENT);
| |
TSN::CDynamicRisk riesgo_c(InpStepMod, InpStart, TSN::LP_GMLPO, InpMethodDr);
| |
TSN::CModifierDynamicRisk risk_modificator(InpStrPercentagesToApplyRiesgoCts);
| |
TSN::CMathDynamicRisk risk_modificator_kevin(InpConstante);
| |
| |
//---
| |
uint g_trade_flags = 0;
| |
TSN::CAtrOptimizedZero atr_ultra_optimized(_Period, _Symbol, 14);
| |
TSN::CLossProfitManager g_loss_profit_manager; // LossProfitManager
| |
//+------------------------------------------------------------------+
| |
//| Expert initialization function |
| |
//+------------------------------------------------------------------+
| |
int OnInit()
| |
{
| |
//---
| |
tradep.LogLevel(LOG_LEVEL_NO);
| |
| |
//---
| |
string _what = NULL;
| |
TSNSTD_TRY_INI
| |
{
| |
| |
//--- We set the breakeven values so its use is allowed
| |
if(InpUseBe)
| |
{
| |
TSN::CBreakEvenCreator be;
| |
be.SetBeByAtr(InpBeAtrMultiplier, InpBeAtrMultiplierExtra, GetPointer(atr_ultra_optimized));
| |
be.SetBeByFixedPoints(InpBeFixedPointsToPutBe, InpBeFixedPointsExtra);
| |
be.SetBeByRR(InpBeRrDbl, InpBeTypeExtraRr, InpBeExtraPointsRrOrAtrMultiplier, GetPointer(atr_ultra_optimized));
| |
TSN::BreakEvenCreatorRes be_res = be.Create(InpTypeBreakEven, _Symbol, InpMagic);
| |
TSNSTD_TRY_EF(be_res.ok, true,
| |
TSN::CErrorTrace::FormatTrace(_what))
| |
g_breakeven = be_res.ptr;
| |
g_breakeven.AddLogFlags(InpLogLevelBe);
| |
CAutoCleaner::AddPtr(g_breakeven);
| |
}
| |
| |
//--- Partials
| |
if(g_partials_enabled)
| |
{
| |
g_partials.AddLogFlags(InpLogLevelPartials);
| |
TSNSTD_TRY_EF(g_partials.Init(InpMagic, _Symbol, InpVolumenQueSeQuitaraDeLaPosicionEnPorcentaje, InpPartesDelTpDondeSeTomaraParciales), true,
| |
TSN::CErrorTrace::FormatTrace(_what))
| |
}
| |
| |
//--- Indicators
| |
::ResetLastError();
| |
// Create ob handle
| |
TSNSTD_TRY_N_EF((order_block_indicator_handle = CreateIndicatorObHandle()), INVALID_HANDLE,
| |
StringFormat("The ob indicator is not available latest error: _LastError=%d", _LastError))
| |
| |
TSNSTD_TRY_EF(TESTER_FLAG || ChartIndicatorAdd(0, 0, order_block_indicator_handle), true,
| |
StringFormat("Error in add ob: _LastError=%d", _LastError))
| |
| |
// Create ma handle
| |
TSNSTD_TRY_N_EF((hanlde_ma = iMA(_Symbol, InpTimeframeOrderBlock, 30, 0, MODE_EMA, PRICE_CLOSE)), INVALID_HANDLE,
| |
StringFormat("The ema indicator is not available latest error: _LastError=%d", _LastError))
| |
| |
TSNSTD_TRY_EF(TESTER_FLAG || ChartIndicatorAdd(0, 0, hanlde_ma), true,
| |
StringFormat("Error in add ma: _LastError=%d", _LastError))
| |
| |
//--- Trade
| |
tradep.SetExpertMagicNumber(InpMagic);
| |
| |
//--- Risk management
| |
TSN::CRiskManagementCreator manager;
| |
manager.SetPropirm(InpPropFirmBalance);
| |
| |
//---
| |
TSN::MQLArtRMCreatorRes result = manager.GetRiskPointer(InpRiskMode, InpMagic, InpGetMode);
| |
TSNSTD_TRY_EF(result.ok, true,
| |
TSN::CErrorTrace::FormatTrace(_what))
| |
| |
//---
| |
risk = result.ptr;
| |
risk.AddLogFlags(InpLogLevelRiskManagement);
| |
// risk.LotCalc().SetSymbol(_Symbol); no hace falta dado que por defecto ya usa curr_symbol
| |
// si estuveimoas pasando un simbolo custom para uqe calcule ahi si..
| |
risk.SetLossProfitManager(g_loss_profit_manager);
| |
CAutoCleaner::AddPtr(risk);
| |
| |
// We set the parameters
| |
string to_apply = InpStrPercentagesToApply, to_modfied = InpStrPercentagesToBeReviewed;
| |
| |
if(InpModeGmlpo == TSN::DYNAMIC_GMLPO_FIXED_PARAMETERS)
| |
{
| |
TSN::CRmFunctions::SetDynamicUsingFixedParameters(InpBalancePercentageToActivateTheRisk1, InpBalancePercentageToActivateTheRisk2,
| |
InpBalancePercentageToActivateTheRisk3
| |
, InpBalancePercentageToActivateTheRisk4, InpPercentageToBeModified1, InpPercentageToBeModified2,
| |
InpPercentageToBeModified3, InpPercentageToBeModified4
| |
, to_modfied, to_apply);
| |
}
| |
| |
| |
//--- Risk management
| |
TSNSTD_TRY_INI_S // nota: genera bool _err implicito
| |
{
| |
TSNSTD_TRY_SE(risk.AddLP(InpPercentageOrMoneyMdlInput, InpAppliedPercentagesMdl, InpModeCalculationMdl, TSN::LP_MDL, true), true);
| |
TSNSTD_TRY_SE(risk.AddLP(InpPercentageOrMoneyGmlpoInput, InpAppliedPercentagesGmlpo, InpModeCalculationGmlpo, TSN::LP_GMLPO, true,
| |
(InpModeGmlpo != TSN::NO_DYNAMIC_GMLPO), to_modfied, to_apply), true);
| |
TSNSTD_TRY_SE(risk.AddLP(InpPercentageOrMoneyMlInput, InpAppliedPercentagesMl, InpModeCalculationMl, TSN::LP_ML, true), true);
| |
TSNSTD_TRY_SE(risk.AddLP(InpPercentageOrMoneyMwlInput, InpAppliedPercentagesMwl, InpModeCalculationMwl, TSN::LP_MWL, true), true);
| |
TSNSTD_TRY_SE(risk.AddLP(InpPercentageOrMoneyMdpInput, InpAppliedPercentagesMdp, InpModeCalculationMdp, TSN::LP_MDP, InpMdpIsStrict), true);
| |
risk.EndAddProfitLoss(); // Execute this every time we finish setting the maximum losses and profits
| |
| |
// We add modifiers
| |
if(InpActivarModificadorDeRiesgo)
| |
TSNSTD_TRY_SE(risk.AddModificator(riesgo_c), true);
| |
| |
if(InpActivarModificadorDeRiesgo2)
| |
TSNSTD_TRY_SE(risk.AddModificator(risk_modificator), true);
| |
| |
if(InpActivarModificadorDeRiesgo3)
| |
TSNSTD_TRY_SE(risk.AddModificator(risk_modificator_kevin), true);
| |
| |
}
| |
TSNSTD_TRY_END;
| |
| |
//---
| |
TSNSTD_TRY_N_EF(_err, true, TSN::CErrorTrace::FormatTrace(_what))
| |
}
| |
TSNSTD_TRY_END;
| |
| |
//---
| |
if(_what != NULL) // error final
| |
{
| |
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, _what);
| |
return INIT_FAILED;
| |
}
| |
| |
| |
//--- We initialize the account
| |
TSN::account_status.AddLogFlags(InpLogLevelAccountStatus);
| |
TSN::account_status.OnInitEvent();
| |
| |
//---
| |
CAutoCleaner::AddFunction(TSN::CAccountStatus_Deinit);
| |
CAutoCleaner::AddFunction(CBasicEvents::Deinit);
| |
| |
//--- We configure the arrays in series
| |
ArraySetAsSeries(tp1, true);
| |
ArraySetAsSeries(tp2, true);
| |
ArraySetAsSeries(sl1, true);
| |
ArraySetAsSeries(sl2, true);
| |
return(INIT_SUCCEEDED);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Expert deinitialization function |
| |
//+------------------------------------------------------------------+
| |
void OnDeinit(const int reason)
| |
{
| |
//---
| |
if(!TESTER_FLAG)
| |
{
| |
ChartIndicatorDelete(0, 0, ChartIndicatorName(0, 0, GetMovingAverageIndex()));
| |
ChartIndicatorDelete(0, 0, "Order Block Indicator");
| |
}
| |
| |
//---
| |
if(hanlde_ma != INVALID_HANDLE)
| |
IndicatorRelease(hanlde_ma);
| |
| |
//---
| |
if(order_block_indicator_handle != INVALID_HANDLE)
| |
IndicatorRelease(order_block_indicator_handle);
| |
| |
//---
| |
CAutoCleaner::Deinit(reason);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Expert tick function |
| |
//+------------------------------------------------------------------+
| |
void OnTick()
| |
{
| |
//--- General
| |
const datetime time_curr = TimeCurrent();
| |
| |
//--- Code that runs every new day
| |
if(bar_d1.IsNewBar(time_curr))
| |
{
| |
//---
| |
CBasicEvents::OnNewDay(time_curr);
| |
TSNMQLART_U_BEVENTS_MAN_REM_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_DAY);
| |
| |
//---
| |
if(bar_w1.IsNewBar(time_curr))
| |
{
| |
CBasicEvents::OnNewWeek(time_curr);
| |
TSNMQLART_U_BEVENTS_MAN_REM_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_WEEK);
| |
}
| |
| |
//---
| |
if(bar_mn1.IsNewBar(time_curr))
| |
{
| |
CBasicEvents::OnNewMonth(time_curr);
| |
// no uso tradeflags dado que no hay prameotrs para un Monthly.. pero si lo hubiera:
| |
//TSNMQLART_U_BEVENTS_MAN_REM_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_MON);
| |
}
| |
}
| |
| |
//---
| |
if(TSN::account_status_positions_open)
| |
{
| |
#ifdef MQLARTICLES_RM_MULTI_EA_MODE
| |
risk.CalcProfit();
| |
#else // MQLARTICLES_RM_MULTI_EA_MODE
| |
ACCOUNTSTATUS_ONEVERYTICK
| |
#endif // MQLARTICLES_RM_MULTI_EA_MODE
| |
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)
| |
{
| |
risk.CloseAllPositions();
| |
// añadimos segnu 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 perdidad (Aqui tambien entra pico como no lo tenemos "agregado" en los patrmos no importa pero si estuviera manejra caso especial)
| |
{
| |
if(InpRiskMode == TSN::risk_mode_propfirm_dynamic_daiy_loss)
| |
Print("The expert advisor lost the funding test");
| |
else
| |
Print("Maximum loss exceeded now");
| |
| |
//---
| |
risk.CloseAllPositions();
| |
Remover();
| |
}
| |
}
| |
else
| |
if(g_loss_profit_manager.MaxProfitIsSuperated())
| |
{
| |
// NOTA: no compruebo nada dado que ahora mismo solo hay un profit agregado.. MDP
| |
// Entonces el es el unico que se peude activbar igual si hubieran mas haria algo similar a la rama de losses..
| |
risk.CloseAllPositions();
| |
TSNMQLART_U_BEVENTS_MAN_ADD_F(g_trade_flags, BASICEVENT_REG_FLAG_ON_NEW_DAY);
| |
Print("Excellent Maximum daily profit achieved");
| |
}
| |
}
| |
}
| |
| |
//--- Check Session
| |
if(time_curr > end_sesion)
| |
{
| |
start_sesion = HoraYMinutoADatetime(InpPaSessionStartHour, InpPaSessionStartMinute, time_curr);
| |
end_sesion = HoraYMinutoADatetime(InpPaSessionEndHour, InpPaSessionEndMinute, time_curr);
| |
| |
if(start_sesion > end_sesion)
| |
end_sesion = end_sesion + 86400;
| |
}
| |
| |
//--- Breakeven
| |
if(InpUseBe)
| |
g_breakeven.BreakEven();
| |
| |
//--- Partials
| |
if(g_partials_enabled)
| |
g_partials.CheckTrackedPositions();
| |
| |
//--- Si hay almenos una bandera activa no se puede operar
| |
if(TSNMQLART_U_BEVENTS_MAN_NO_TRADE_NOW(g_trade_flags))
| |
return;
| |
| |
//--- Strategy
| |
if(bar_curr.IsNewBar(time_curr))
| |
{
| |
if(time_curr > start_sesion && time_curr < end_sesion)
| |
{
| |
if(risk.GetPositionsTotal() == 0)
| |
{
| |
CopyBuffer(order_block_indicator_handle, 2, 0, 1, tp1);
| |
CopyBuffer(order_block_indicator_handle, 3, 0, 1, tp2);
| |
CopyBuffer(order_block_indicator_handle, 4, 0, 1, sl1);
| |
CopyBuffer(order_block_indicator_handle, 5, 0, 1, sl2);
| |
| |
if(tp1[0] > 0 && tp2[0] > 0 && sl1[0] > 0 && sl2[0] > 0)
| |
{
| |
if(tp2[0] > sl2[0]) // buy orders
| |
{
| |
const double ASK = (SymbolInfoDouble(_Symbol, SYMBOL_ASK));
| |
risk.SetStopLoss(_Symbol, ASK - sl1[0]);
| |
const double lot = (InpLoteType == TSN::Dinamico ? risk.GetLote(ORDER_TYPE_BUY, ASK, 0, 0) : InpLote);
| |
tradep.Buy(lot, _Symbol, ASK, sl1[0], tp2[0], "Order Block EA Buy");
| |
}
| |
else
| |
if(sl2[0] > tp2[0]) // sell orders
| |
{
| |
const double BID = (SymbolInfoDouble(_Symbol, SYMBOL_BID));
| |
risk.SetStopLoss(_Symbol, sl1[0] - BID);
| |
const double lot = (InpLoteType == TSN::Dinamico ? risk.GetLote(ORDER_TYPE_SELL, BID, 0, 0) : InpLote);
| |
tradep.Sell(lot, _Symbol, BID, sl1[0], tp2[0], "Order Block EA Sell");
| |
}
| |
}
| |
}
| |
}
| |
}
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| TradeTransaction function |
| |
//+------------------------------------------------------------------+
| |
void OnTradeTransaction(const MqlTradeTransaction & trans,
| |
const MqlTradeRequest & request,
| |
const MqlTradeResult & result)
| |
{
| |
TSN::account_status.OnTradeTransactionEvent(trans);
| |
}
| |
| |
//+------------------------------------------------------------------+
|