Navigation:Home > Content >

LibDerksUtils_(3).mqh

Time: 2016-06-27 | Download file:LibDerksUtils_(3).mqh

//=============================================================================
//                                                        LibDerksUtils.mqh
//                                            Copyright © 2006, Derk Wehler 
//                                                    ashwoods155@yahoo.com
//
//  Companion header file for LibDerksUtils.mq4
//
//
// ***************************************************************************
// ***************************************************************************
//  LICENSING:  This is free, open source software, licensed under
//              Version 2 of the GNU General Public License (GPL).
//
//  In particular, this means that distribution of this software in a binary
//  format, e.g. as compiled in as part of a .ex4 format, must be accompanied
//  by the non-obfuscated source code of both this file, AND the .mq4 source
//  files which it is compiled with, or you must make such files available at
//  no charge to binary recipients.	If you do not agree with such terms you
//  must not use this code.  Detailed terms of the GPL are widely available
//  on the Internet.  The Library GPL (LGPL) was intentionally not used,
//  therefore the source code of files which link to this are subject to
//  terms of the GPL if binaries made from them are publicly distributed or
//  sold.
//
//  ANY USE OF THIS CODE NOT CONFORMING TO THIS LICENSE MUST FIRST RECEIVE 
//  PRIOR AUTHORIZATION FROM THE AUTHOR(S).  ANY COMMERCIAL USE MUST FIRST 
//  OBTAIN A COMMERCIAL LICENSE FROM THE AUTHOR(S).
//
//  Copyright (2007), Derk Wehler, derkwehler@gmail.com
// ***************************************************************************
// ***************************************************************************
//
//=============================================================================
#property copyright "Copyright © 2006, Derk Wehler"
#property link      "no site"

#import "LibDerksUtils.ex4"

int		DU_ErrorLevel 	= 3;
string	DU_FuncName		= "N/A";
string	DU_Version		= "v.21";

#define OP_BOTH				-1
#define ALL_OPEN			-1
#define ALL_PENDING			-1
#define ALL_PENDING_BUYS	-2
#define ALL_PENDING_SELLS	-3

// Money Management Helper Functions
double	CalcLotsMM(double TradeSizePercent, double MinLots, double MaxLots);
double	CalcLotsGivenRisk(double RiskPercent, double MinLots, double MaxLots, int StopLoss);
double	CalcLotsFixedLotCost(double TradeSizePercent, double MinLots, double MaxLots,double FixedPricePerLot);
double 	GetDualWinLots(double begLots, int magic, int TP_Pips);
double 	GetMartingaleLots(int magic, double begLots, double maxLots, double mult);
bool	TargetReached(int magic, int pips, double profit);
void 	DU_SetErrorLevel(int level);
void 	DU_Log(int level, string func, string s);

bool 	IsMakeUpTrade();
int 	GetLotDigits();

// These 2 are obsolete!  Do not use. 
//double LotsOptimized(double TradeSizePercent, double Lots, double MaxLots);
//double GetLots(bool MoneyManagement, double TradeSizePercent, double Lots, double MaxLots);

// Magic Number Helper & Conversion Functions
int 	TimeFrameConst2Val(int TF_In_Minutes);
string	TimeFrameVal2String(int value);
int 	SymbolConst2Val(string symbol);
string 	OrderType2String(int type); 
int 	OrderString2Num(string type);
string	Bool2Text(bool value);
string	GetBoolText(bool value);

// Trading Functions
bool 	IsNewCandle();
int 	NumOpenPositions(int magic, int dir);
int 	NumPendingOrders(int magic, int dir);
int 	ClosePendingOrders(int magic, int dir);
int 	PlacePendingBreakouts(string 	symbol,
							  double	buyPrice,
							  double	sellPrice,
							  int 		magic, 
							  int 		dir, 
							  bool 		allSameSL, 
							  bool 		allSameTP, 
							  int		SL,
							  int		TP,
							  int		qtyOrders,
							  int 		distBetween,
							  double	lots, 
							  int 		slippage,
							  string	comment,
							  color 	clr);

int 	ReplenishOrders(int			quantity,
						string		symbol,
						int 		dir[], 
						double 		lots,
						double 		price[], 
						int			slippage,
						double 		sls[], 
						double 		tps[],
						string		comment,
						int 		magic,
						datetime 	expir,
						color 		arrowClr,
						bool&		orderPlaced[]);

// Trailing Stop-Related Functions
void 	SetKeltnerLevels(double k0, double k1, double k2, double k3, double k4, 
						 double k5, double k6, double k7, double k8, double k9);
void 	SetKeltnerParams(int period, int maMode, int priceMode, int atrPeriod, bool atrMode);
void 	SetKeltnerStart(int idx);
void	RefreshKeltnerValues();
bool 	AdjTrailOnAllOrders(int TrailType, 
							int	TrailVal,
							int	Magic,
							int Direction,
							int FirstMove, 
							int FirstStopLoss, 
							int SecondMove, 
							int SecondStopLoss, 
							int ThirdMove);
							
double 	GetTrailingSLValue(int 		Ticket, 
						   int 		TrailType, 
						   int		TrailPips,
						   double 	CurSL,
						   int 		FirstMove, 
						   int 		FirstStopLoss, 
						   int 		SecondMove, 
						   int 		SecondStopLoss, 
						   int 		ThirdMove);

// Other utilities
string ErrorDescription(int error_code);


Recommend