mirror of
https://github.com/rithsila/MT5-EA-Sniper-Strategy.git
synced 2026-08-17 04:38:12 +00:00
Organize project in different folders
This commit is contained in:
@@ -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,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,209 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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;
|
||||
double lastBuyOrderPrice;
|
||||
double lastSellOrderPrice;
|
||||
double openedBuyPositionPrice;
|
||||
double openedSellPositionPrice;
|
||||
|
||||
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;}
|
||||
|
||||
virtual double getLastBuyOrderPrice() {return lastBuyOrderPrice;}
|
||||
virtual double getLastSellOrderPrice() {return lastSellOrderPrice;}
|
||||
virtual double getOpenedBuyPositionPrice() {return openedBuyPositionPrice;}
|
||||
virtual double getOpenedSellPositionPrice() {return openedSellPositionPrice;}
|
||||
};
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
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();
|
||||
|
||||
// Check the account balance equity for profit
|
||||
int pCountBuy = 0, pCountSell = 0, oCountBuy = 0, oCountSell = 0, totalBuy = 0, totalSell = 0, realTotalBuy = 0, realTotalSell = 0;
|
||||
int realOCountBuy = 0, realOCountSell = 0;
|
||||
ulong ticket;
|
||||
|
||||
SetSignal(OFX_ENTRY_SIGNAL, OFX_SIGNAL_NONE);
|
||||
|
||||
//If there're many positions and account balance is negative
|
||||
|
||||
if(PositionsTotal() > 0)
|
||||
{
|
||||
//Count the opened positions by type
|
||||
int cntP = PositionsTotal();
|
||||
for(int i = cntP-1; i>=0; i--)
|
||||
{
|
||||
ticket = PositionGetTicket(i);
|
||||
if(PositionSelectByTicket(ticket))
|
||||
{
|
||||
if(PositionGetString(POSITION_SYMBOL)==mSymbol && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY
|
||||
&& PositionGetInteger(POSITION_MAGIC)==m_magic)
|
||||
{
|
||||
openedBuyPositionPrice = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||
pCountBuy += 1;
|
||||
}
|
||||
|
||||
if(PositionGetString(POSITION_SYMBOL)==mSymbol && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL
|
||||
&& PositionGetInteger(POSITION_MAGIC)==m_magic)
|
||||
{
|
||||
openedSellPositionPrice = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||
pCountSell += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Print(GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
//Count the orders by type
|
||||
|
||||
int cntO = OrdersTotal();
|
||||
|
||||
for(int i = cntO-1; i>=0; i--)
|
||||
{
|
||||
|
||||
ticket = OrderGetTicket(i);
|
||||
if(OrderSelect(ticket))
|
||||
{
|
||||
if(OrderGetString(ORDER_SYMBOL)==mSymbol && OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP
|
||||
&& OrderGetInteger(ORDER_MAGIC)==m_magic)
|
||||
{
|
||||
oCountBuy += 1;
|
||||
lastBuyOrderPrice = OrderGetDouble(ORDER_PRICE_OPEN);
|
||||
}
|
||||
|
||||
Print("ORDER_SYMBOL ", OrderGetString(ORDER_SYMBOL), " Real symbol ", mSymbol, " ORDER_TYPE ", OrderGetInteger(ORDER_TYPE), " Real type ", ORDER_TYPE_SELL_STOP, " Magic ", OrderGetInteger(ORDER_MAGIC), " Real magic ", m_magic);
|
||||
if(OrderGetString(ORDER_SYMBOL)==mSymbol && OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP
|
||||
&& OrderGetInteger(ORDER_MAGIC)==m_magic)
|
||||
{
|
||||
oCountSell += 1;
|
||||
lastSellOrderPrice = OrderGetDouble(ORDER_PRICE_OPEN);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("Last error code ", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
double floatingProfitPercent = ((AccountInfoDouble(ACCOUNT_EQUITY) - AccountInfoDouble(ACCOUNT_BALANCE))*100)/AccountInfoDouble(ACCOUNT_BALANCE);
|
||||
// Check if profit is at least the mMaxRiskPerTrade
|
||||
|
||||
//The number of buy pending order should be twice the opened sell positions; and vice versa
|
||||
realOCountBuy = pCountSell+1;
|
||||
realOCountSell = pCountBuy+1;
|
||||
totalBuy = pCountBuy+oCountBuy;
|
||||
totalSell = pCountSell+oCountSell;
|
||||
realTotalBuy = pCountSell+1;
|
||||
realTotalSell = pCountBuy+1;
|
||||
|
||||
Print("Signal conditions ........................................................................");
|
||||
|
||||
if(OrdersTotal() == 0 && PositionsTotal() == 0)
|
||||
{
|
||||
SetSignal(OFX_ENTRY_SIGNAL, OFX_SIGNAL_BOTH);
|
||||
Print("1 - Open both position");
|
||||
}
|
||||
else
|
||||
{
|
||||
//If there's only one pending order left, close it.
|
||||
if(OrdersTotal() >= 1 && PositionsTotal() == 0)
|
||||
{
|
||||
SetSignal(OFX_EXIT_SIGNAL, OFX_SIGNAL_ALL);
|
||||
Print("2 - Exit if no opened position");
|
||||
}
|
||||
else
|
||||
{
|
||||
//When there are multiple positions, check is the account is making enough profit
|
||||
if(floatingProfitPercent > mMaxRiskPerTrade)
|
||||
{
|
||||
SetSignal(OFX_EXIT_SIGNAL, OFX_SIGNAL_ALL);
|
||||
Print("3 - Exit on profit target");
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("realTotalSell ", realTotalSell, " > ", " totalSell ", totalSell," && ", " pCountBuy ",pCountBuy," > 0");
|
||||
if(realTotalSell > totalSell && pCountBuy > 0)
|
||||
{
|
||||
SetSignal(OFX_ENTRY_SIGNAL, OFX_SIGNAL_SELL);
|
||||
Print("4 - Sell order (", oCountSell, ") is less than it should be (", realOCountSell, ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(realTotalBuy > totalBuy && pCountSell > 0)
|
||||
{
|
||||
SetSignal(OFX_ENTRY_SIGNAL, OFX_SIGNAL_BUY);
|
||||
//mEntrySignals[0].SetSignal(OFX_ENTRY_SIGNAL, OFX_SIGNAL_BUY);
|
||||
Print("5 - Buy order (", oCountBuy, ") is less than it should be (", realOCountBuy, ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user