derivato da nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| Ea.mq5 |
| |
//| Copyright 2025, Niquel Mendoza. |
| |
//| https://www.mql5.com/es/users/nique_372/news |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2025, Niquel Mendoza."
| |
#property link "https://www.mql5.com/es/users/nique_372/news"
| |
#property version "1.00"
| |
#property strict
| |
| |
//+------------------------------------------------------------------+
| |
//| Include |
| |
//+------------------------------------------------------------------+
| |
#include "Main.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| Inputs |
| |
//+------------------------------------------------------------------+
| |
sinput group ""
| |
sinput group "-------| Account Status |-------"
| |
input ENUM_VERBOSE_LOG_LEVEL InpLogLevelAccountStatus = VERBOSE_LOG_LEVEL_ALL; //(Account Status|Ticket Mangement) log level:
| |
| |
sinput group ""
| |
sinput group "-------| Breakeven |-------"
| |
input TSN::ENUM_BREAKEVEN_TYPE InpBeType = TSN::BREAKEVEN_TYPE_RR; // Calculation method (RR, ATR, or fixed points)
| |
input ENUM_VERBOSE_LOG_LEVEL InpBeLogLevel = VERBOSE_LOG_LEVEL_ALL; // 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 InpBeRrRatio = 1.0; // Risk/Reward ratio to activate Breakeven (e.g. 1.0)
| |
input TSN::ENUM_TYPE_EXTRA_BE_BY_RRR InpBeRrTypeExtra = TSN::EXTRA_BE_RRR_BY_ATR;// Method to adjust Breakeven price (ATR or points)
| |
input double InpBeRrExtraPointsOrAtrMultiplier = 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
| |
| |
//+------------------------------------------------------------------+
| |
//| Global variables |
| |
//+------------------------------------------------------------------+
| |
CBreakEvenPanel g_app;
| |
TSN::CAtrOptimizedZero g_atr_ultra_optimized(_Period, _Symbol, 14);
| |
| |
//+------------------------------------------------------------------+
| |
//| Expert initialization function |
| |
//+------------------------------------------------------------------+
| |
int OnInit()
| |
{
| |
//---
| |
g_breakeven_creator.SetBeByAtr(InpBeAtrMultiplier, InpBeAtrMultiplierExtra, GetPointer(g_atr_ultra_optimized));
| |
g_breakeven_creator.SetBeByFixedPoints(InpBeFixedPointsToPutBe, InpBeFixedPointsExtra);
| |
g_breakeven_creator.SetBeByRR(InpBeRrRatio, InpBeRrTypeExtra, InpBeRrExtraPointsOrAtrMultiplier, GetPointer(g_atr_ultra_optimized));
| |
| |
//--- Panel
| |
const int width = 500;
| |
const int height = 390;
| |
g_app.CreateGUI(width, height, InpBeType);
| |
| |
//--- Account status
| |
TSN::account_status.AddLogFlags(InpLogLevelAccountStatus);
| |
TSN::account_status.OnInitEvent();
| |
| |
//---
| |
CAutoCleaner::AddFunction(TSN::CAccountStatus_Deinit);
| |
CAutoCleaner::AddFunction(CBasicEvents::Deinit);
| |
| |
//---
| |
return(INIT_SUCCEEDED);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Expert deinitialization function |
| |
//+------------------------------------------------------------------+
| |
void OnDeinit(const int reason)
| |
{
| |
//---
| |
g_app.OnDeinitEvent(reason);
| |
CAutoCleaner::Deinit(reason);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Expert tick function |
| |
//+------------------------------------------------------------------+
| |
void OnTick()
| |
{
| |
g_app.OnTickEvent();
| |
}
| |
//+------------------------------------------------------------------+
| |
//| TradeTransaction function |
| |
//+------------------------------------------------------------------+
| |
void OnTradeTransaction(const MqlTradeTransaction& trans,
| |
const MqlTradeRequest& request,
| |
const MqlTradeResult& result)
| |
{
| |
//---
| |
TSN::account_status.OnTradeTransactionEvent(trans);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| ChartEvent function |
| |
//+------------------------------------------------------------------+
| |
void OnChartEvent(const int id,
| |
const long &lparam,
| |
const double &dparam,
| |
const string &sparam)
| |
{
| |
//---
| |
g_app.ChartEvent(id, lparam, dparam, sparam);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void OnTimer()
| |
{
| |
g_app.OnTimerEvent();
| |
}
| |
//+------------------------------------------------------------------+
|