#property version "1.00"
#property description "An example of an OOP random entry system"
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Indicators\Indicators.mqh>
input int Magic=12345;
input int Slippage=30;
input int ProfitTarget=1000;
input int StopLoss=10000;
input double Lots=0.1;
input bool ReallyRandom=true;
class CGuruEx01
{
private:
int Dig;
double Points;
bool Initialized;
bool Running;
ulong OrderNumber;
double GetSize();
protected:
string m_Pair; // Currency pair to trade
CTrade m_Trade; // Trading object
CSymbolInfo m_Symbol; // Symbol info object
CPositionInfo m_Position; // Position info object
void InitSystem();
bool CheckEntry();
bool CheckExit();
public:
CGuruEx01(); // Constructor
~CGuruEx01() { Deinit(); } // Destructor
bool Init(string Pair);
void Deinit();
bool Validated();
bool Execute();
};
CGuruEx01 GuruEx01;
CGuruEx01::CGuruEx01()
{
Initialized=false;
}
bool CGuruEx01::Init(string Pair)
{
m_Pair=Pair;
m_Symbol.Name(m_Pair); // Symbol
m_Trade.SetExpertMagicNumber(Magic); // Magic number
Dig=m_Symbol.Digits();
Points=m_Symbol.Point();
m_Trade.SetDeviationInPoints(Slippage);
Print("Digits = ",Dig,", Points = ",DoubleToString(Points,Dig));
if(ReallyRandom)
MathSrand(int(TimeLocal())); // Initialize random number generator
else
MathSrand(1); // Same every time
Initialized=true;
return(true);
}
CGuruEx01::Deinit()
{
Initialized=false;
Print("DeInitialized OK");
}
double CGuruEx01::GetSize()
{
return(Lots);
}
bool CGuruEx01::Validated()
{
return(Initialized);
}
void CGuruEx01::InitSystem()
{
Running=false;
Initialized=true;
}
bool CGuruEx01::Execute()
{
if(Running)
{ // Are we in a trade at the moment?
if(CheckExit() > 0)
{ // Yes - Last trade complete?
Initialized = false; // Yes - Indicate we need to reinitialise
InitSystem(); // and start all over again!
}
}
else
{
if(CheckEntry(Показано первые 50% кода (символов: 3464)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.