Consolidate Python ignore rules into root gitignore
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MoneyFixedLot.mqh |
|
||||
//| Copyright 2000-2026, MetaQuotes Ltd. |
|
||||
//| www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Expert\ExpertMoney.mqh>
|
||||
// wizard description start
|
||||
//+------------------------------------------------------------------+
|
||||
//| Description of the class |
|
||||
//| Title=Trading with fixed trade volume |
|
||||
//| Type=Money |
|
||||
//| Name=FixLot |
|
||||
//| Class=CMoneyFixedLot |
|
||||
//| Page= |
|
||||
//| Parameter=Percent,double,10.0,Percent |
|
||||
//| Parameter=Lots,double,0.1,Fixed volume |
|
||||
//+------------------------------------------------------------------+
|
||||
// wizard description end
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CMoneyFixedLot. |
|
||||
//| Purpose: Class of money management with fixed lot. |
|
||||
//| Derives from class CExpertMoney. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CMoneyFixedLot : public CExpertMoney
|
||||
{
|
||||
protected:
|
||||
//--- input parameters
|
||||
double m_lots;
|
||||
|
||||
public:
|
||||
CMoneyFixedLot(void);
|
||||
~CMoneyFixedLot(void);
|
||||
//---
|
||||
void Lots(double lots) { m_lots=lots; }
|
||||
virtual bool ValidationSettings(void);
|
||||
//---
|
||||
virtual double CheckOpenLong(double price,double sl) { return(m_lots); }
|
||||
virtual double CheckOpenShort(double price,double sl) { return(m_lots); }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyFixedLot::CMoneyFixedLot(void) : m_lots(0.1)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyFixedLot::~CMoneyFixedLot(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Validation settings protected data. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CMoneyFixedLot::ValidationSettings(void)
|
||||
{
|
||||
if(!CExpertMoney::ValidationSettings())
|
||||
return(false);
|
||||
//--- initial data checks
|
||||
if(m_lots<m_symbol.LotsMin() || m_lots>m_symbol.LotsMax())
|
||||
{
|
||||
printf(__FUNCTION__+": lots amount must be in the range from %f to %f",m_symbol.LotsMin(),m_symbol.LotsMax());
|
||||
return(false);
|
||||
}
|
||||
if(MathAbs(m_lots/m_symbol.LotsStep()-MathRound(m_lots/m_symbol.LotsStep()))>1.0E-10)
|
||||
{
|
||||
printf(__FUNCTION__+": lots amount is not corresponding with lot step %f",m_symbol.LotsStep());
|
||||
return(false);
|
||||
}
|
||||
//--- ok
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,76 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MoneyFixedMargin.mqh |
|
||||
//| Copyright 2000-2026, MetaQuotes Ltd. |
|
||||
//| www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Expert\ExpertMoney.mqh>
|
||||
// wizard description start
|
||||
//+------------------------------------------------------------------+
|
||||
//| Description of the class |
|
||||
//| Title=Trading with fixed margin |
|
||||
//| Type=Money |
|
||||
//| Name=FixMargin |
|
||||
//| Class=CMoneyFixedMargin |
|
||||
//| Page= |
|
||||
//| Parameter=Percent,double,10.0,Percentage of margin |
|
||||
//+------------------------------------------------------------------+
|
||||
// wizard description end
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CMoneyFixedMargin. |
|
||||
//| Purpose: Class of money management with fixed percent margin. |
|
||||
//| Derives from class CExpertMoney. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CMoneyFixedMargin : public CExpertMoney
|
||||
{
|
||||
public:
|
||||
CMoneyFixedMargin(void);
|
||||
~CMoneyFixedMargin(void);
|
||||
//---
|
||||
virtual double CheckOpenLong(double price,double sl);
|
||||
virtual double CheckOpenShort(double price,double sl);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyFixedMargin::CMoneyFixedMargin(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyFixedMargin::~CMoneyFixedMargin(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open long position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneyFixedMargin::CheckOpenLong(double price,double sl)
|
||||
{
|
||||
if(m_symbol==NULL)
|
||||
return(0.0);
|
||||
//--- select lot size
|
||||
double lot;
|
||||
if(price==0.0)
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_BUY,m_symbol.Ask(),m_percent);
|
||||
else
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_BUY,price,m_percent);
|
||||
//--- return trading volume
|
||||
return(lot);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open short position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneyFixedMargin::CheckOpenShort(double price,double sl)
|
||||
{
|
||||
if(m_symbol==NULL)
|
||||
return(0.0);
|
||||
//--- select lot size
|
||||
double lot;
|
||||
if(price==0.0)
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_SELL,m_symbol.Bid(),m_percent);
|
||||
else
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_SELL,price,m_percent);
|
||||
//--- return trading volume
|
||||
return(lot);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,109 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MoneyFixedRisk.mqh |
|
||||
//| Copyright 2000-2026, MetaQuotes Ltd. |
|
||||
//| www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Expert\ExpertMoney.mqh>
|
||||
// wizard description start
|
||||
//+------------------------------------------------------------------+
|
||||
//| Description of the class |
|
||||
//| Title=Trading with fixed risk |
|
||||
//| Type=Money |
|
||||
//| Name=FixRisk |
|
||||
//| Class=CMoneyFixedRisk |
|
||||
//| Page= |
|
||||
//| Parameter=Percent,double,10.0,Risk percentage |
|
||||
//+------------------------------------------------------------------+
|
||||
// wizard description end
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CMoneyFixedRisk. |
|
||||
//| Purpose: Class of money management with fixed percent risk. |
|
||||
//| Derives from class CExpertMoney. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CMoneyFixedRisk : public CExpertMoney
|
||||
{
|
||||
public:
|
||||
CMoneyFixedRisk(void);
|
||||
~CMoneyFixedRisk(void);
|
||||
//---
|
||||
virtual double CheckOpenLong(double price,double sl);
|
||||
virtual double CheckOpenShort(double price,double sl);
|
||||
virtual double CheckClose(CPositionInfo *position) { return(0.0); }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyFixedRisk::CMoneyFixedRisk(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyFixedRisk::~CMoneyFixedRisk(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open long position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneyFixedRisk::CheckOpenLong(double price,double sl)
|
||||
{
|
||||
if(m_symbol==NULL)
|
||||
return(0.0);
|
||||
//--- select lot size
|
||||
double lot;
|
||||
double minvol=m_symbol.LotsMin();
|
||||
if(sl==0.0)
|
||||
lot=minvol;
|
||||
else
|
||||
{
|
||||
double loss;
|
||||
if(price==0.0)
|
||||
loss=-m_account.OrderProfitCheck(m_symbol.Name(),ORDER_TYPE_BUY,1.0,m_symbol.Ask(),sl);
|
||||
else
|
||||
loss=-m_account.OrderProfitCheck(m_symbol.Name(),ORDER_TYPE_BUY,1.0,price,sl);
|
||||
double stepvol=m_symbol.LotsStep();
|
||||
lot=MathFloor(m_account.Balance()*m_percent/loss/100.0/stepvol)*stepvol;
|
||||
}
|
||||
//---
|
||||
if(lot<minvol)
|
||||
lot=minvol;
|
||||
//---
|
||||
double maxvol=m_symbol.LotsMax();
|
||||
if(lot>maxvol)
|
||||
lot=maxvol;
|
||||
//--- return trading volume
|
||||
return(lot);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open short position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneyFixedRisk::CheckOpenShort(double price,double sl)
|
||||
{
|
||||
if(m_symbol==NULL)
|
||||
return(0.0);
|
||||
//--- select lot size
|
||||
double lot;
|
||||
double minvol=m_symbol.LotsMin();
|
||||
if(sl==0.0)
|
||||
lot=minvol;
|
||||
else
|
||||
{
|
||||
double loss;
|
||||
if(price==0.0)
|
||||
loss=-m_account.OrderProfitCheck(m_symbol.Name(),ORDER_TYPE_SELL,1.0,m_symbol.Bid(),sl);
|
||||
else
|
||||
loss=-m_account.OrderProfitCheck(m_symbol.Name(),ORDER_TYPE_SELL,1.0,price,sl);
|
||||
double stepvol=m_symbol.LotsStep();
|
||||
lot=MathFloor(m_account.Balance()*m_percent/loss/100.0/stepvol)*stepvol;
|
||||
}
|
||||
//---
|
||||
if(lot<minvol)
|
||||
lot=minvol;
|
||||
//---
|
||||
double maxvol=m_symbol.LotsMax();
|
||||
if(lot>maxvol)
|
||||
lot=maxvol;
|
||||
//--- return trading volume
|
||||
return(lot);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,71 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MoneyNone.mqh |
|
||||
//| Copyright 2000-2026, MetaQuotes Ltd. |
|
||||
//| www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Expert\ExpertMoney.mqh>
|
||||
// wizard description start
|
||||
//+------------------------------------------------------------------+
|
||||
//| Description of the class |
|
||||
//| Title=Trading with minimal allowed trade volume |
|
||||
//| Type=Money |
|
||||
//| Name=MinLot |
|
||||
//| Class=CMoneyNone |
|
||||
//| Page= |
|
||||
//+------------------------------------------------------------------+
|
||||
// wizard description end
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CMoneyNone. |
|
||||
//| Appointment: Class no money managment. |
|
||||
//| Derives from class CExpertMoney. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CMoneyNone : public CExpertMoney
|
||||
{
|
||||
public:
|
||||
CMoneyNone(void);
|
||||
~CMoneyNone(void);
|
||||
//---
|
||||
virtual bool ValidationSettings(void);
|
||||
//---
|
||||
virtual double CheckOpenLong(double price,double sl);
|
||||
virtual double CheckOpenShort(double price,double sl);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyNone::CMoneyNone(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneyNone::~CMoneyNone(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Validation settings protected data. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CMoneyNone::ValidationSettings(void)
|
||||
{
|
||||
Percent(100.0);
|
||||
//--- initial data checks
|
||||
if(!CExpertMoney::ValidationSettings())
|
||||
return(false);
|
||||
//--- ok
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open long position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneyNone::CheckOpenLong(double price,double sl)
|
||||
{
|
||||
return(m_symbol.LotsMin());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open short position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneyNone::CheckOpenShort(double price,double sl)
|
||||
{
|
||||
return(m_symbol.LotsMin());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,155 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MoneySizeOptimized.mqh |
|
||||
//| Copyright 2000-2026, MetaQuotes Ltd. |
|
||||
//| www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Expert\ExpertMoney.mqh>
|
||||
#include <Trade\DealInfo.mqh>
|
||||
// wizard description start
|
||||
//+------------------------------------------------------------------+
|
||||
//| Description of the class |
|
||||
//| Title=Trading with optimized trade volume |
|
||||
//| Type=Money |
|
||||
//| Name=SizeOptimized |
|
||||
//| Class=CMoneySizeOptimized |
|
||||
//| Page= |
|
||||
//| Parameter=DecreaseFactor,double,3.0,Decrease factor |
|
||||
//| Parameter=Percent,double,10.0,Percent |
|
||||
//+------------------------------------------------------------------+
|
||||
// wizard description end
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CMoneySizeOptimized. |
|
||||
//| Purpose: Class of money management with size optimized. |
|
||||
//| Derives from class CExpertMoney. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CMoneySizeOptimized : public CExpertMoney
|
||||
{
|
||||
protected:
|
||||
double m_decrease_factor;
|
||||
|
||||
public:
|
||||
CMoneySizeOptimized(void);
|
||||
~CMoneySizeOptimized(void);
|
||||
//---
|
||||
void DecreaseFactor(double decrease_factor) { m_decrease_factor=decrease_factor; }
|
||||
virtual bool ValidationSettings(void);
|
||||
//---
|
||||
virtual double CheckOpenLong(double price,double sl);
|
||||
virtual double CheckOpenShort(double price,double sl);
|
||||
|
||||
protected:
|
||||
double Optimize(double lots);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneySizeOptimized::CMoneySizeOptimized(void) : m_decrease_factor(3.0)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
void CMoneySizeOptimized::~CMoneySizeOptimized(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Validation settings protected data. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CMoneySizeOptimized::ValidationSettings(void)
|
||||
{
|
||||
if(!CExpertMoney::ValidationSettings())
|
||||
return(false);
|
||||
//--- initial data checks
|
||||
if(m_decrease_factor<=0.0)
|
||||
{
|
||||
printf(__FUNCTION__+": decrease factor must be greater then 0");
|
||||
return(false);
|
||||
}
|
||||
//--- ok
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open long position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneySizeOptimized::CheckOpenLong(double price,double sl)
|
||||
{
|
||||
if(m_symbol==NULL)
|
||||
return(0.0);
|
||||
//--- select lot size
|
||||
double lot;
|
||||
if(price==0.0)
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_BUY,m_symbol.Ask(),m_percent);
|
||||
else
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_BUY,price,m_percent);
|
||||
//--- return trading volume
|
||||
return(Optimize(lot));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Getting lot size for open short position. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneySizeOptimized::CheckOpenShort(double price,double sl)
|
||||
{
|
||||
if(m_symbol==NULL)
|
||||
return(0.0);
|
||||
//--- select lot size
|
||||
double lot;
|
||||
if(price==0.0)
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_SELL,m_symbol.Bid(),m_percent);
|
||||
else
|
||||
lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_SELL,price,m_percent);
|
||||
//--- return trading volume
|
||||
return(Optimize(lot));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Optimizing lot size for open. |
|
||||
//+------------------------------------------------------------------+
|
||||
double CMoneySizeOptimized::Optimize(double lots)
|
||||
{
|
||||
double lot=lots;
|
||||
//--- calculate number of losses orders without a break
|
||||
if(m_decrease_factor>0)
|
||||
{
|
||||
//--- select history for access
|
||||
HistorySelect(0,TimeCurrent());
|
||||
//---
|
||||
int orders=HistoryDealsTotal(); // total history deals
|
||||
int losses=0; // number of consequent losing orders
|
||||
CDealInfo deal;
|
||||
//---
|
||||
for(int i=orders-1;i>=0;i--)
|
||||
{
|
||||
deal.Ticket(HistoryDealGetTicket(i));
|
||||
if(deal.Ticket()==0)
|
||||
{
|
||||
Print("CMoneySizeOptimized::Optimize: HistoryDealGetTicket failed, no trade history");
|
||||
break;
|
||||
}
|
||||
//--- check symbol
|
||||
if(deal.Symbol()!=m_symbol.Name())
|
||||
continue;
|
||||
//--- check profit
|
||||
double profit=deal.Profit();
|
||||
if(profit>0.0)
|
||||
break;
|
||||
if(profit<0.0)
|
||||
losses++;
|
||||
}
|
||||
//---
|
||||
if(losses>1)
|
||||
lot=NormalizeDouble(lot-lot*losses/m_decrease_factor,2);
|
||||
}
|
||||
//--- normalize and check limits
|
||||
double stepvol=m_symbol.LotsStep();
|
||||
lot=stepvol*NormalizeDouble(lot/stepvol,0);
|
||||
//---
|
||||
double minvol=m_symbol.LotsMin();
|
||||
if(lot<minvol)
|
||||
lot=minvol;
|
||||
//---
|
||||
double maxvol=m_symbol.LotsMax();
|
||||
if(lot>maxvol)
|
||||
lot=maxvol;
|
||||
//---
|
||||
return(lot);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user