Project_N_1/Include/CStohastic_oscillator.mqh

119 lines
9.9 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:18:18 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| 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"
//+------------------------------------------------------------------+
//| 1JO2;5=85 <5B>4>2 8 A2>9AB20 :;0AA0 |
//+------------------------------------------------------------------+
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);
};
//+------------------------------------------------------------------+
//| >=AB@C:B>@ ?> C<>;G0=8N. A;8 =5 7040=K ?0@0<5B@K. |
//+------------------------------------------------------------------+
CStohastic::CStohastic()
{
this.handle = InitHandle(_Symbol, PERIOD_CURRENT, 5, 3, 3, MODE_EMA, STO_LOWHIGH);
this.lowLim = 20;
this.upLim = 80;
}
//+------------------------------------------------------------------+
//| >=AB@C:B>@ A ?0@0<5B@0<8 |
//+------------------------------------------------------------------+
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;
}
//+------------------------------------------------------------------+
//| 5AB@C:B>@ |
//+------------------------------------------------------------------+
CStohastic::~CStohastic()
{
}
//+------------------------------------------------------------------+
//0 - MAIN_LINE, 1 - SIGNAL_LINE.
//+------------------------------------------------------------------+
//| =8F80;87C5< EM=4; 4;O AB>E0AB8G5A:>3> >AF8;;OB>@0 |
//+------------------------------------------------------------------+
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("H81:0 ?@8 A>740=88 Stochastic - ! >H81:8: ", _LastError, "!!");
return -1;
}
ChartIndicatorAdd(ChartID(), 1, handleStohastic);
return handleStohastic;
}
//+------------------------------------------------------------------+
//| 0?>;=O5< <0AA82 40==KE AB>E0AB8G5A:>3> >AF8;;OB>@0 |
//+------------------------------------------------------------------+
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("0==K5 Stohastic_buffers =5 703@C78;8AL", _LastError);
SendMail(_Symbol + "H81:0 703@C7:8 40==KE 8=48:0B>@0 Stohastic_buffers ", _Symbol + " H81:0 703@C7:8 40==KE 8=48:0B>@>2");
return;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CStohastic::IsLowLimit()
{
if(mainBuffer[0] < lowLim)
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CStohastic::IsUpLimit()
{
if(mainBuffer[0] > upLim)
return true;
return false;
}