mirror of
https://github.com/rithsila/MT5-EA-Sniper-Strategy.git
synced 2026-08-20 22:28:19 +00:00
Organize project in different folders
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
AllSignals.mqh
|
||||
|
||||
Copyright 2013-2020, Orchard Forex
|
||||
https://www.orchardforex.com
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "SignalBase.mqh"
|
||||
|
||||
//
|
||||
// Other signals go here
|
||||
//
|
||||
#include "Crossover/SignalCrossover.mqh"
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
SignalCrossover.mqh
|
||||
For framework version 1.0
|
||||
|
||||
Copyright 2013-2020, Orchard Forex
|
||||
https://www.orchardforex.com
|
||||
|
||||
*/
|
||||
|
||||
#include "../SignalBase.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,85 @@
|
||||
/*
|
||||
SignalBase.mqh
|
||||
|
||||
Copyright 2013-2020, Orchard Forex
|
||||
https://www.orchardforex.com
|
||||
|
||||
*/
|
||||
|
||||
#include "../CommonBase.mqh"
|
||||
#include "../Indicators/IndicatorBase.mqh"
|
||||
|
||||
struct SIndicatorItem {
|
||||
CIndicatorBase *indicator;
|
||||
int bufferNum;
|
||||
};
|
||||
|
||||
enum ENUM_OFX_SIGNAL_DIRECTION {
|
||||
OFX_SIGNAL_NONE = 0,
|
||||
OFX_SIGNAL_BUY = 1,
|
||||
OFX_SIGNAL_SELL = 2,
|
||||
OFX_SIGNAL_BOTH = 3
|
||||
};
|
||||
|
||||
class CSignalBase : public CCommonBase {
|
||||
|
||||
private:
|
||||
|
||||
protected: // member variables
|
||||
|
||||
ENUM_OFX_SIGNAL_DIRECTION mEntrySignal;
|
||||
ENUM_OFX_SIGNAL_DIRECTION mExitSignal;
|
||||
SIndicatorItem mIndicatorList[];
|
||||
|
||||
public: // constructors
|
||||
|
||||
CSignalBase() : CCommonBase()
|
||||
{ Init(); }
|
||||
CSignalBase(string symbol, ENUM_TIMEFRAMES timeframe) : CCommonBase(symbol, timeframe)
|
||||
{ Init(); }
|
||||
~CSignalBase() { }
|
||||
|
||||
int Init();
|
||||
|
||||
public:
|
||||
|
||||
virtual void UpdateSignal() { return; }
|
||||
virtual ENUM_OFX_SIGNAL_DIRECTION EntrySignal() { return(mEntrySignal); }
|
||||
virtual ENUM_OFX_SIGNAL_DIRECTION ExitSignal() { return(mExitSignal); }
|
||||
|
||||
virtual void AddIndicator(CIndicatorBase *indicator, int bufferNum);
|
||||
virtual double GetIndicatorData(int indicatorNum, int index);
|
||||
|
||||
};
|
||||
|
||||
int CSignalBase::Init() {
|
||||
|
||||
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
|
||||
|
||||
mEntrySignal = OFX_SIGNAL_NONE;
|
||||
mExitSignal = OFX_SIGNAL_NONE;
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
|
||||
}
|
||||
|
||||
void CSignalBase::AddIndicator(CIndicatorBase *indicator, int bufferNum) {
|
||||
|
||||
SIndicatorItem indicatorItem = {NULL, 0};
|
||||
indicatorItem.indicator = indicator;
|
||||
indicatorItem.bufferNum = bufferNum;
|
||||
int cnt = ArraySize(mIndicatorList);
|
||||
ArrayResize(mIndicatorList, cnt+1);
|
||||
mIndicatorList[cnt] = indicatorItem;
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double CSignalBase::GetIndicatorData(int indicatorNum,int index) {
|
||||
|
||||
return(mIndicatorList[indicatorNum].indicator.GetData(mIndicatorList[indicatorNum].bufferNum, index));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user