118 lines
9.9 KiB
MQL5
118 lines
9.9 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Stohastic.mqh |
|
|
//| Copyright 2021, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2021, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Объявление методов и свойства класса |
|
|
//+------------------------------------------------------------------+
|
|
class CStohastic
|
|
{
|
|
private:
|
|
int InitHandle(string symbol, ENUM_TIMEFRAMES period, int periodK1, int periodD1, int slowing, ENUM_MA_METHOD stohasticMAmode, ENUM_STO_PRICE stohasticSTOprice);
|
|
|
|
public:
|
|
CStohastic();
|
|
CStohastic(string symbol, ENUM_TIMEFRAMES period, int periodK1, int periodD1, int slowing, int lowLimit, int upLimit, ENUM_MA_METHOD stohasticMAmode, ENUM_STO_PRICE stohasticSTOprice);
|
|
~CStohastic();
|
|
|
|
bool IsLowLimit();
|
|
bool IsUpLimit();
|
|
|
|
double mainBuffer[];
|
|
double signalBuffer[];
|
|
|
|
int handle;
|
|
int lowLim;
|
|
int upLim;
|
|
|
|
void FillBuffer(int stohasticHadle);
|
|
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Конструктор по умолчанию. Если не заданы параметры. |
|
|
//+------------------------------------------------------------------+
|
|
CStohastic::CStohastic()
|
|
{
|
|
this.handle = InitHandle(_Symbol, PERIOD_CURRENT, 5, 3, 3, MODE_EMA, STO_LOWHIGH);
|
|
this.lowLim = 20;
|
|
this.upLim = 80;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Конструктор с параметрами |
|
|
//+------------------------------------------------------------------+
|
|
CStohastic::CStohastic(string symbol, ENUM_TIMEFRAMES period, int periodK1, int periodD1, int slowing, int lowLimit, int upLimit, ENUM_MA_METHOD stohasticMAmode, ENUM_STO_PRICE stohasticSTOprice)
|
|
{
|
|
this.handle = InitHandle(symbol, period, periodK1, periodD1, slowing, stohasticMAmode, stohasticSTOprice);
|
|
this.lowLim = lowLimit;
|
|
this.upLim = upLimit;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Деструктор |
|
|
//+------------------------------------------------------------------+
|
|
CStohastic::~CStohastic()
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
|
//+------------------------------------------------------------------+
|
|
//| Инициализуем хэндл для стохастического осциллятора |
|
|
//+------------------------------------------------------------------+
|
|
int CStohastic::InitHandle(string symbol, ENUM_TIMEFRAMES period, int periodK1, int periodD1, int slowing, ENUM_MA_METHOD stohasticMAmode, ENUM_STO_PRICE stohasticSTOprice)
|
|
{
|
|
int handleStohastic = iStochastic(symbol, period, periodK1, periodD1, slowing, stohasticMAmode, stohasticSTOprice);
|
|
if(handleStohastic < 0)
|
|
{
|
|
Print("Ошибка при создании Stochastic - № ошибки: ", _LastError, "!!");
|
|
return -1;
|
|
}
|
|
ChartIndicatorAdd(ChartID(), 1, handleStohastic);
|
|
return handleStohastic;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Заполняем массив данных стохастического осциллятора |
|
|
//+------------------------------------------------------------------+
|
|
void CStohastic::FillBuffer(int stohasticHadle)
|
|
{
|
|
ArraySetAsSeries(mainBuffer, true);
|
|
ArraySetAsSeries(signalBuffer, true);
|
|
ArrayResize(mainBuffer, 5);
|
|
ArrayResize(signalBuffer,5);
|
|
|
|
int St_main = CopyBuffer(stohasticHadle, 0, 0, 5, mainBuffer);
|
|
int St_signal = CopyBuffer(stohasticHadle, 1, 0, 5, signalBuffer);
|
|
|
|
if(St_main < 0 || St_signal < 0)
|
|
{
|
|
Print("Данные Stohastic_buffers не загрузились", _LastError);
|
|
SendMail(_Symbol + "Ошибка загрузки данных индикатора Stohastic_buffers ", _Symbol + " Ошибка загрузки данных индикаторов");
|
|
return;
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CStohastic::IsLowLimit()
|
|
{
|
|
if(mainBuffer[0] < lowLim)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CStohastic::IsUpLimit()
|
|
{
|
|
if(mainBuffer[0] > upLim)
|
|
return true;
|
|
return false;
|
|
}
|