Initial commit

This commit is contained in:
Nkondog Anselme
2021-11-14 05:36:01 +01:00
commit 407a205132
69 changed files with 5946 additions and 0 deletions
@@ -0,0 +1,16 @@
/*
All.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
Auto Generated at 2021-07-10 17:11:59
*/
//
// Extension go here
//
#include "AllIndicators.mqh"
#include "AllSignals.mqh"
#include "AllTPSL.mqh"
@@ -0,0 +1,6 @@
//
// Extension go here
//
#include "GridSignals.mqh"
#include "GridTPSL.mqh"
#include "GlobalEnumDefinitions.mqh"
@@ -0,0 +1,16 @@
/*
All.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
Auto Generated at 2021-07-10 17:11:59
*/
//
// Extension go here
//
#include "Indicators/IndicatorATR.mqh"
#include "Indicators/IndicatorMA.mqh"
#include "Indicators/IndicatorTemplate.mqh"
@@ -0,0 +1,17 @@
/*
All.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
Auto Generated at 2021-07-10 17:11:59
*/
//
// Extension go here
//
#include "Signals/SignalCombination.mqh"
#include "Signals/SignalCrossover.mqh"
#include "Signals/SignalTemplate.mqh"
#include "Signals/SignalGrid.mqh"
@@ -0,0 +1,15 @@
/*
All.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
Auto Generated at 2021-07-10 17:11:59
*/
//
// Extension go here
//
#include "TPSL/TPSLSimple.mqh"
#include "TPSL/TPSLTemplate.mqh"
@@ -0,0 +1,29 @@
//+------------------------------------------------------------------+
//| GlobalEnumDefinitions.mqh |
//| Copyright 2021, Nkondog Anselme Venceslas |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Nkondog Anselme Venceslas"
#property link "https://www.mql5.com"
enum ENUM_TRADING_SESSION
{
LONDON_SESSION=1,
NEWYORK_SESSION=2,
TOKYO_SESSION=3,
};
//Enumerative for the default risk size
enum ENUM_RISK_DEFAULT_SIZE
{
RISK_DEFAULT_FIXED=1, //FIXED SIZE
RISK_DEFAULT_AUTO=2, //AUTOMATIC SIZE BASED ON RISK
};
//Enumerative for the base used for risk calculation
enum ENUM_RISK_BASE
{
RISK_BASE_EQUITY=1, //EQUITY
RISK_BASE_BALANCE=2, //BALANCE
RISK_BASE_FREEMARGIN=3, //FREE MARGIN
};
@@ -0,0 +1,5 @@
//
// Extension go here
//
#include "Signals/SignalGrid.mqh"
@@ -0,0 +1,4 @@
//
// Extension go here
//
#include "TPSL/GridTPSL.mqh"
@@ -0,0 +1,77 @@
/*
IndicatorATR.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
#include "../../Framework.mqh"
class CIndicatorATR : public CIndicatorBase {
private:
protected: // member variables
int mPeriods;
public: // constructors
CIndicatorATR(int periods)
: CIndicatorBase()
{ Init(periods); }
CIndicatorATR(string symbol, ENUM_TIMEFRAMES timeframe,
int periods)
: CIndicatorBase(symbol, timeframe)
{ Init(periods); }
~CIndicatorATR();
virtual int Init(int periods);
public:
virtual double GetData(const int buffer_num,const int index);
};
CIndicatorATR::~CIndicatorATR() {
}
int CIndicatorATR::Init(int periods) {
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
mPeriods = periods;
#ifdef __MQL5__
mIndicatorHandle = iATR(mSymbol, mTimeframe, mPeriods);
if (mIndicatorHandle==INVALID_HANDLE) return(InitError("Failed to create indicator handle", INIT_FAILED));
#endif
return(INIT_SUCCEEDED);
}
double CIndicatorATR::GetData(const int buffer_num,const int index) {
double value = 0;
#ifdef __MQL4__
value = iATR(mSymbol, mTimeframe, mPeriods, index);
#endif
#ifdef __MQL5__
double bufferData[];
ArraySetAsSeries(bufferData, true);
int cnt = CopyBuffer(mIndicatorHandle, buffer_num, index, 1, bufferData);
if (cnt>0) value = bufferData[0];
#endif
return(value);
}
@@ -0,0 +1,82 @@
/*
IndicatorMA.mqh
Updated - requires version 2.01 or later
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
#include "../../Framework.mqh"
class CIndicatorMA : public CIndicatorBase {
private:
protected: // member variables
int mPeriods;
int mShift;
ENUM_MA_METHOD mMethod;
ENUM_APPLIED_PRICE mAppliedPrice;
public: // constructors
CIndicatorMA(int periods, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE appliedPrice)
: CIndicatorBase()
{ Init(periods, shift, method, appliedPrice); }
CIndicatorMA(string symbol, ENUM_TIMEFRAMES timeframe,
int periods, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE appliedPrice)
: CIndicatorBase(symbol, timeframe)
{ Init(periods, shift, method, appliedPrice); }
~CIndicatorMA();
virtual int Init(int periods, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE appliedPrice);
public:
virtual double GetData(const int buffer_num,const int index);
};
CIndicatorMA::~CIndicatorMA() {
}
int CIndicatorMA::Init(int periods, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE appliedPrice) {
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
mPeriods = periods;
mShift = shift;
mMethod = method;
mAppliedPrice = appliedPrice;
#ifdef __MQL5__
mIndicatorHandle = iMA(mSymbol, mTimeframe, mPeriods, mShift, mMethod, mAppliedPrice);
if (mIndicatorHandle==INVALID_HANDLE) return(InitError("Failed to create indicator handle", INIT_FAILED));
#endif
return(INIT_SUCCEEDED);
}
double CIndicatorMA::GetData(const int buffer_num,const int index) {
double value = 0;
#ifdef __MQL4__
value = iMA(mSymbol, mTimeframe, mPeriods, mShift, mMethod, mAppliedPrice, index);
#endif
#ifdef __MQL5__
double bufferData[];
ArraySetAsSeries(bufferData, true);
int cnt = CopyBuffer(mIndicatorHandle, buffer_num, index, 1, bufferData);
if (cnt>0) value = bufferData[0];
#endif
return(value);
}
@@ -0,0 +1,91 @@
/*
IndicatorTemplate.mqh
Updated as of framework version 2.02
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
// Next line assumes this file is located in .../Frameworks/Extensions/someFolder
#include "../../Framework.mqh"
class CIndicatorTemplate : public CIndicatorBase {
private:
protected: // member variables
// Place any required member variables here
public: // constructors
// Add any required constructor arguments
// e.g. CIndicatorXYZ(int periods, double multiplier)
CIndicatorTemplate()
: CIndicatorBase()
{ Init(); }
// Same constructor with symbol and timeframe added
CIndicatorTemplate(string symbol, ENUM_TIMEFRAMES timeframe)
: CIndicatorBase(symbol, timeframe)
{ Init(); }
~CIndicatorTemplate();
// Include all arguments to match the constructor
virtual int Init();
public:
// Add this line to override the same function from the parent class
virtual double GetData(const int buffer_num,const int index);
};
CIndicatorTemplate::~CIndicatorTemplate() {
// Any destructors here
}
int CIndicatorTemplate::Init() {
// Checks if init has been set to fail by any parent class already
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
// Assign variables and do any other initialisation here
#ifdef __MQL5__
// Just using iMA as an example here, replace as necessary
// mIndicatorHandle = iMA(mSymbol, mTimeframe, mPeriods, mShift, mMethod, mAppliedPrice);
// if (mIndicatorHandle==INVALID_HANDLE) return(InitError("Failed to create indicator handle", INIT_FAILED));
#endif
return(INIT_SUCCEEDED);
}
double CIndicatorTemplate::GetData(const int buffer_num,const int index) {
double value = 0;
#ifdef __MQL4__
// Next line is just an example using iMA
// value = iMA(mSymbol, mTimeframe, mPeriods, mShift, mMethod, mAppliedPrice, index);
#endif
#ifdef __MQL5__
// For MQL5 once indicator handle is set the code here should be common
// Declare a buffer to hold the data being retrieved
double bufferData[];
// Set as series so the sequence matches the chrt
ArraySetAsSeries(bufferData, true);
// Copy indicator data into the buffer and get the count of elements
int cnt = CopyBuffer(mIndicatorHandle, buffer_num, index, 1, bufferData);
// If not enough elements came back then don't use the data
if (cnt>0) value = bufferData[0];
#endif
return(value);
}
@@ -0,0 +1,86 @@
/*
SignalCombination.mqh
For framework version 1.0
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
#include "../../Framework.mqh"
class CSignalCombination : public CSignalBase {
private:
protected: // member variables
CSignalBase *mSignals[];
public: // constructors
CSignalCombination(string symbol, ENUM_TIMEFRAMES timeframe)
: CSignalBase(symbol, timeframe)
{ Init(); }
CSignalCombination()
: CSignalBase()
{ Init(); }
~CSignalCombination() { }
int Init();
public:
virtual void AddSignal(CSignalBase *signal);
virtual void UpdateSignal();
};
int CSignalCombination::Init() {
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
ArrayResize(mSignals, 0);
return(INIT_SUCCEEDED);
}
void CSignalCombination::UpdateSignal() {
int index = ArraySize(mSignals);
if (index<=0) {
mEntrySignal = OFX_SIGNAL_NONE;
mExitSignal = OFX_SIGNAL_NONE;
} else {
mSignals[0].UpdateSignal();
mEntrySignal = mSignals[0].EntrySignal();
mExitSignal = mSignals[0].ExitSignal();
for (int i = 1; i<index; i++) {
mSignals[i].UpdateSignal();
if (mSignals[i].EntrySignal()!=mEntrySignal) mEntrySignal = OFX_SIGNAL_NONE;
if (mSignals[i].ExitSignal()!=mExitSignal) mExitSignal = OFX_SIGNAL_NONE;
}
}
return;
}
void CSignalCombination::AddSignal(CSignalBase *signal) {
int index = ArraySize(mSignals);
ArrayResize(mSignals, index+1);
mSignals[index] = signal;
}
@@ -0,0 +1,78 @@
/*
SignalCrossover.mqh
For framework version 1.0
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
#include "../../Framework.mqh"
class CSignalCrossover : public CSignalBase {
private:
protected: // member variables
int mIndex1;
int mIndex2;
public: // constructors
CSignalCrossover(string symbol, ENUM_TIMEFRAMES timeframe,
int index1=1, int index2=2)
: CSignalBase(symbol, timeframe)
{ Init(index1, index2); }
CSignalCrossover(int index1=1, int index2=2)
: CSignalBase()
{ Init(index1, index2); }
~CSignalCrossover() { }
int Init(int index1, int index2);
public:
virtual void UpdateSignal();
};
int CSignalCrossover::Init(int index1, int index2) {
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
mIndex1 = index1;
mIndex2 = index2;
return(INIT_SUCCEEDED);
}
void CSignalCrossover::UpdateSignal() {
double fast1 = GetIndicatorData(0, mIndex1);
double fast2 = GetIndicatorData(0, mIndex2);
double slow1 = GetIndicatorData(1, mIndex1);
double slow2 = GetIndicatorData(1, mIndex2);
// There is a less common condition where the fast
// indicator touches the slow indicator and then
// reverses. With the conditions below this would
// appear like a cross.
if ( (fast1>slow1) && !(fast2>slow2) ) { // Crossed up
mEntrySignal = OFX_SIGNAL_BUY;
mExitSignal = OFX_SIGNAL_SELL;
} else
if ( (fast1<slow1) && !(fast2<slow2) ) { // Crossed down
mEntrySignal = OFX_SIGNAL_SELL;
mExitSignal = OFX_SIGNAL_BUY;
} else {
mEntrySignal = OFX_SIGNAL_NONE;
mExitSignal = OFX_SIGNAL_NONE;
}
return;
}
@@ -0,0 +1,79 @@
//+------------------------------------------------------------------+
//| SignalGrid.mqh |
//| Copyright 2021, Nkondog Anselme Venceslas |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Nkondog Anselme Venceslas"
#property link "https://www.mql5.com"
// Next line assumes this file is located in .../Frameworks/Extensions/someFolder
#include "../../GridFramework.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CSignalGrid : public CSignalBase
{
private:
protected: // member variables
// Place any required member variables here
int m_magic;
public: // constructors
// Add any required constructor arguments
// e.g. CSignalXYZ(int periods, double multiplier)
CSignalGrid()
: CSignalBase()
{ Init(); }
// Same constructor with symbol and timeframe added
CSignalGrid(string symbol, ENUM_TIMEFRAMES timeframe)
: CSignalBase(symbol, timeframe)
{ Init(); }
~CSignalGrid() { }
// Include all arguments to match the constructor
int Init();
public:
// Add this line to override the same function from the parent class
virtual void UpdateSignal();
virtual void setMmagic(int magic) {m_magic = magic;}
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CSignalGrid::Init()
{
// Checks if init has been set to fail by any parent class already
if(InitResult()!=INIT_SUCCEEDED)
return(InitResult());
// Assign variables and do any other initialisation here
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CSignalGrid::UpdateSignal()
{
// Just gather data from the indicators and
// decide on a trade direction
// This is the trade decision logic
//CSignalBase signal = new CSignalBase();
}
//+------------------------------------------------------------------+
@@ -0,0 +1,68 @@
/*
SignalTemplate.mqh
Updated as of framework version 2.02
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
// Next line assumes this file is located in .../Frameworks/Extensions/someFolder
#include "../../Framework.mqh"
class CSignalTemplate : public CSignalBase {
private:
protected: // member variables
// Place any required member variables here
public: // constructors
// Add any required constructor arguments
// e.g. CSignalXYZ(int periods, double multiplier)
CSignalTemplate()
: CSignalBase()
{ Init(); }
// Same constructor with symbol and timeframe added
CSignalTemplate(string symbol, ENUM_TIMEFRAMES timeframe)
: CSignalBase(symbol, timeframe)
{ Init(); }
~CSignalTemplate() { }
// Include all arguments to match the constructor
int Init();
public:
// Add this line to override the same function from the parent class
virtual void UpdateSignal();
};
int CSignalTemplate::Init() {
// Checks if init has been set to fail by any parent class already
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
// Assign variables and do any other initialisation here
return(INIT_SUCCEEDED);
}
void CSignalTemplate::UpdateSignal() {
// Just gather data from the indicators and
// decide on a trade direction
// This is the trade decision logic
mExitSignal = OFX_SIGNAL_NONE; // This strategy has no exit signal
// Just set the buy or sell signals now
return;
}
@@ -0,0 +1,57 @@
// Next line assumes this file is located in .../Frameworks/Extensions/someFolder
#include "../../Framework.mqh"
class GridTPSL : public CTPSLBase {
private:
double GetValue();
protected: // member variables
// Place any required member variables here
public: // constructors
// Add any required constructor arguments
// e.g. CTPSLXYZ(int periods, double multiplier)
GridTPSL() : CTPSLBase() { Init(); }
// Same constructor with symbol and timeframe added
GridTPSL(string symbol, ENUM_TIMEFRAMES timeframe)
: CTPSLBase(symbol, timeframe) { Init(); }
~GridTPSL() { }
int Init();
public:
// Get and Set functions for additional parameters
// Override these from the parent class to get required values
// GetValue here is just an example
virtual double GetTakeProfit() { return(GetValue()); }
virtual double GetStopLoss() { return(GetValue()); }
};
int GridTPSL::Init() {
// Checks if init has been set to fail by any parent class already
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
// Assign variables and do any other initialisation here
return(INIT_SUCCEEDED);
}
// A simple example of a value function
double GridTPSL::GetValue() {
// Pulls data from an assigned indicator number 0 for bar 1 and multiplies by 2
double value = 0;//GetIndicatorData(0, 1)*2;
return(value);
}
@@ -0,0 +1,62 @@
/*
TPSLSimple.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
#include "../../Framework.mqh"
class CTPSLSimple : public CTPSLBase {
private:
double GetValue();
protected: // member variables
double mMultiplier;
int mIndex;
public: // constructors
CTPSLSimple() : CTPSLBase() { Init(); }
CTPSLSimple(string symbol, ENUM_TIMEFRAMES timeframe)
: CTPSLBase(symbol, timeframe) { Init(); }
~CTPSLSimple() { }
int Init();
public:
virtual void SetIndex(int index) { mIndex = index; }
virtual double GetIndex() { return(mIndex); }
virtual void SetMultiplier(double multiplier) { mMultiplier = multiplier; }
virtual double GetMultiplier() { return(mMultiplier); }
virtual double GetTakeProfit() { return(GetValue()); }
virtual double GetStopLoss() { return(GetValue()); }
};
int CTPSLSimple::Init() {
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
mMultiplier = 1.0;
return(INIT_SUCCEEDED);
}
double CTPSLSimple::GetValue() {
double value = 0;//GetIndicatorData(0, mIndex)*mMultiplier;
return(value);
}
@@ -0,0 +1,67 @@
/*
TPSLTemplate.mqh
Updated as of framework version 2.02
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
// Next line assumes this file is located in .../Frameworks/Extensions/someFolder
#include "../../Framework.mqh"
class CTPSLTemplate : public CTPSLBase {
private:
double GetValue();
protected: // member variables
// Place any required member variables here
public: // constructors
// Add any required constructor arguments
// e.g. CTPSLXYZ(int periods, double multiplier)
CTPSLTemplate() : CTPSLBase() { Init(); }
// Same constructor with symbol and timeframe added
CTPSLTemplate(string symbol, ENUM_TIMEFRAMES timeframe)
: CTPSLBase(symbol, timeframe) { Init(); }
~CTPSLTemplate() { }
int Init();
public:
// Get and Set functions for additional parameters
// Override these from the parent class to get required values
// GetValue here is just an example
virtual double GetTakeProfit() { return(GetValue()); }
virtual double GetStopLoss() { return(GetValue()); }
};
int CTPSLTemplate::Init() {
// Checks if init has been set to fail by any parent class already
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
// Assign variables and do any other initialisation here
return(INIT_SUCCEEDED);
}
// A simple example of a value function
double CTPSLTemplate::GetValue() {
// Pulls data from an assigned indicator number 0 for bar 1 and multiplies by 2
double value = 0;//GetIndicatorData(0, 1)*2;
return(value);
}