forked from animatedread/Warrior_EA
The //| box blocks were excluded from0b06f8eand5efdb48and were what remained: 160 of them ran to 10+ lines, the longest to 88. Compressed to their leading topic sentences - 5 lines for a function header, 8 for a file header - keeping the box format and the standard MQL5 name/author lines verbatim. Verified at the BYTE level this time, across every in-scope file: the list of non-comment lines is byte-identical to HEAD and braces balance. The first check compared a locale-decoded 'git show' against a UTF-8 read and flagged 25 files that had not changed at all - every BOM and every non-ASCII line mismatched. 47,696 -> 40,665 lines in scope; comment share 38% -> 26%. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
65 lines
3.9 KiB
MQL5
65 lines
3.9 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Warrior_EA |
|
|
//| AnimateDread |
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include <Expert\ExpertMoney.mqh>
|
|
#include "..\System\TradeChecks.mqh"
|
|
//+------------------------------------------------------------------+
|
|
//| Class CExpertMoneyCustom. Common base for every money-management |
|
|
//| strategy in this EA. |
|
|
//+------------------------------------------------------------------+
|
|
class CExpertMoneyCustom : public CExpertMoney
|
|
{
|
|
protected:
|
|
//--- The full #14/#3/#5/#2 gate. Returns the corrected volume in `lots`, or 0.0 with a
|
|
//--- populated `description` when no legal volume exists for this trade right now.
|
|
bool ValidateLotForTrade(const string symb, double &lots, ENUM_ORDER_TYPE type, string &description);
|
|
//--- Kept as thin wrappers over the shared library so the two names the existing money
|
|
//--- strategies already call (Money\MoneyRiskBase.mqh) keep working unchanged.
|
|
bool CheckAndCorrectVolumeValue(double &volume, string &description);
|
|
bool CheckAndAdjustMoneyForTrade(string symb, double &lots, ENUM_ORDER_TYPE type);
|
|
//--- Symbol this money object is sizing for. m_symbol is set by CExpertMoney::Init(); fall back
|
|
//--- to the chart symbol only if a strategy is used stand-alone before Init() has run.
|
|
string MoneySymbol(void) { return (m_symbol != NULL) ? m_symbol.Name() : _Symbol; }
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| Article #14/#3/#5/#2 - the complete pre-OrderSend volume gate. |
|
|
//+------------------------------------------------------------------+
|
|
bool CExpertMoneyCustom::ValidateLotForTrade(const string symb, double &lots, ENUM_ORDER_TYPE type, string &description)
|
|
{
|
|
if(!TCValidateVolumeForTrade(symb, lots, type, description))
|
|
{
|
|
//--- throttled: an exhausted margin/volume limit is true on every tick until it changes, and
|
|
//--- an unthrottled Print here floods the journal for as long as the condition lasts
|
|
TCLog("money:" + symb + ":" + EnumToString(type),
|
|
StringFormat("%s: no tradeable volume for %s %s - %s", __FUNCTION__, symb, EnumToString(type), description));
|
|
lots = 0.0;
|
|
return false;
|
|
}
|
|
if(description != "")
|
|
TCLog("money-adjust:" + symb + ":" + EnumToString(type),
|
|
StringFormat("%s: volume adjusted for %s %s - %s", __FUNCTION__, symb, EnumToString(type), description));
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Article #3 - check and correct the order volume. |
|
|
//| Delegates to TCNormalizeVolume(), which snaps to the volume step |
|
|
//| BEFORE clamping to [min,max] (see its comment for why the reverse |
|
|
//| order can emit an out-of-range volume) and then re-verifies the |
|
|
//| corrected value against all three properties. |
|
|
//+------------------------------------------------------------------+
|
|
bool CExpertMoneyCustom::CheckAndCorrectVolumeValue(double &volume, string &description)
|
|
{
|
|
return TCNormalizeVolume(MoneySymbol(), volume, description);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Article #2/#5 - fit the trade size to free margin and to the |
|
|
//| per-symbol aggregate volume limit. |
|
|
//+------------------------------------------------------------------+
|
|
bool CExpertMoneyCustom::CheckAndAdjustMoneyForTrade(string symb, double &lots, ENUM_ORDER_TYPE type)
|
|
{
|
|
string description;
|
|
return ValidateLotForTrade(symb, lots, type, description);
|
|
}
|
|
//+------------------------------------------------------------------+
|