Initial commit: MQL5 Indicators Collection (MetaTrader 5) - Part 1
This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
//+---------------------------------------------------------------------+
|
||||
//| ATR_Channels.mq5 |
|
||||
//| Copyright © 2005, Luis Guilherme Damiani |
|
||||
//| http://www.damianifx.com.br |
|
||||
///+---------------------------------------------------------------------+
|
||||
//| Äëÿ ðàáîòû èíäèêàòîðà ñëåäóåò ïîëîæèòü ôàéë SmoothAlgorithms.mqh |
|
||||
//| â ïàïêó (äèðåêòîðèþ): êàòàëîã_äàííûõ_òåðìèíàëà\\MQL5\Include |
|
||||
//+---------------------------------------------------------------------+
|
||||
#property copyright "Copyright © 2005, Luis Guilherme Damiani"
|
||||
#property link "http://www.damianifx.com.br"
|
||||
#property description "ATR Channels"
|
||||
//---- íîìåð âåðñèè èíäèêàòîðà
|
||||
#property version "1.00"
|
||||
//---- îòðèñîâêà èíäèêàòîðà â ãëàâíîì îêíå
|
||||
#property indicator_chart_window
|
||||
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ
|
||||
#property indicator_buffers 7
|
||||
//---- èñïîëüçîâàíî âñåãî ñåìü ãðàôè÷åñêèõ ïîñòðîåíèé
|
||||
#property indicator_plots 7
|
||||
//+-----------------------------------+
|
||||
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà |
|
||||
//+-----------------------------------+
|
||||
//---- îòðèñîâêà èíäèêàòîðà â âèäå ëèíèè
|
||||
#property indicator_type1 DRAW_LINE
|
||||
//---- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàí ñèíå-ôèîëåòîâûé öâåò
|
||||
#property indicator_color1 clrBlueViolet
|
||||
//---- ëèíèÿ èíäèêàòîðà - øòðèõïóíêòèðíàÿ êðèâàÿ
|
||||
#property indicator_style1 STYLE_DASHDOTDOT
|
||||
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 1
|
||||
#property indicator_width1 1
|
||||
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
|
||||
#property indicator_label1 "ATR"
|
||||
|
||||
//+--------------------------------------------------+
|
||||
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà Envelope óðîâíåé |
|
||||
//+--------------------------------------------------+
|
||||
//---- îòðèñîâêà óðîâíåé â âèäå ëèíèé
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_type7 DRAW_LINE
|
||||
//---- ââûáîð öâåòîâ óðîâíåé
|
||||
#property indicator_color2 clrPurple
|
||||
#property indicator_color3 clrRed
|
||||
#property indicator_color4 clrBlue
|
||||
#property indicator_color5 clrBlue
|
||||
#property indicator_color6 clrRed
|
||||
#property indicator_color7 clrPurple
|
||||
//---- óðîâíè - øòðèõïóíêòèðíûå êðèâûå
|
||||
#property indicator_style2 STYLE_DASHDOTDOT
|
||||
#property indicator_style3 STYLE_DASHDOTDOT
|
||||
#property indicator_style4 STYLE_DASHDOTDOT
|
||||
#property indicator_style5 STYLE_DASHDOTDOT
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
//---- òîëùèíà óðîâíåé ðàâíà 1
|
||||
#property indicator_width2 1
|
||||
#property indicator_width3 1
|
||||
#property indicator_width4 1
|
||||
#property indicator_width5 1
|
||||
#property indicator_width6 1
|
||||
#property indicator_width7 1
|
||||
//---- îòîáðàæåíèå ìåòîê óðîâíåé
|
||||
#property indicator_label2 "+3 Envelope"
|
||||
#property indicator_label3 "+2 Envelope"
|
||||
#property indicator_label4 "+1 Envelope"
|
||||
#property indicator_label5 "-1 Envelope"
|
||||
#property indicator_label6 "-2 Envelope"
|
||||
#property indicator_label7 "-3 Envelope"
|
||||
//+-----------------------------------+
|
||||
//| îáúÿâëåíèå êîíñòàíò |
|
||||
//+-----------------------------------+
|
||||
#define RESET 0 // Êîíñòàíòà äëÿ âîçâðàòà òåðìèíàëó êîìàíäû íà ïåðåñ÷åò èíäèêàòîðà
|
||||
//+-----------------------------------+
|
||||
//| Îïèñàíèå êëàññîâ óñðåäíåíèé |
|
||||
//+-----------------------------------+
|
||||
#include <SmoothAlgorithms.mqh>
|
||||
//+-----------------------------------+
|
||||
//---- îáúÿâëåíèå ïåðåìåííûõ êëàññà CXMA èç ôàéëà SmoothAlgorithms.mqh
|
||||
CXMA XMA;
|
||||
//+-----------------------------------+
|
||||
//| îáúÿâëåíèå ïåðå÷èñëåíèé |
|
||||
//+-----------------------------------+
|
||||
enum Applied_price_ //Òèï êîíñòàíòû
|
||||
{
|
||||
PRICE_CLOSE_ = 1, //Close
|
||||
PRICE_OPEN_, //Open
|
||||
PRICE_HIGH_, //High
|
||||
PRICE_LOW_, //Low
|
||||
PRICE_MEDIAN_, //Median Price (HL/2)
|
||||
PRICE_TYPICAL_, //Typical Price (HLC/3)
|
||||
PRICE_WEIGHTED_, //Weighted Close (HLCC/4)
|
||||
PRICE_SIMPL_, //Simpl Price (OC/2)
|
||||
PRICE_QUARTER_, //Quarted Price (HLOC/4)
|
||||
PRICE_TRENDFOLLOW0_, //TrendFollow_1 Price
|
||||
PRICE_TRENDFOLLOW1_, //TrendFollow_2 Price
|
||||
PRICE_DEMARK_ //Demark Price
|
||||
};
|
||||
//+-----------------------------------+
|
||||
//| îáúÿâëåíèå ïåðå÷èñëåíèé |
|
||||
//+-----------------------------------+
|
||||
/*enum Smooth_Method - ïåðå÷èñëåíèå îáúÿâëåíî â ôàéëå SmoothAlgorithms.mqh
|
||||
{
|
||||
MODE_SMA_, //SMA
|
||||
MODE_EMA_, //EMA
|
||||
MODE_SMMA_, //SMMA
|
||||
MODE_LWMA_, //LWMA
|
||||
MODE_JJMA, //JJMA
|
||||
MODE_JurX, //JurX
|
||||
MODE_ParMA, //ParMA
|
||||
MODE_T3, //T3
|
||||
MODE_VIDYA, //VIDYA
|
||||
MODE_AMA, //AMA
|
||||
}; */
|
||||
//+-----------------------------------+
|
||||
//| ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ |
|
||||
//+-----------------------------------+
|
||||
input uint ATRPeriod=18;
|
||||
input double Mult_Factor1= 1.6;
|
||||
input double Mult_Factor2= 3.2;
|
||||
input double Mult_Factor3= 4.8;
|
||||
//----
|
||||
input Smooth_Method XMA_Method=MODE_SMA_; //ìåòîä óñðåäíåíèÿ
|
||||
input uint XLength=100; //ãëóáèíà ñãëàæèâàíèÿ
|
||||
input int XPhase=15; //ïàðàìåòð óñðåäíåíèÿ,
|
||||
//---- äëÿ JJMA èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
|
||||
//---- Äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
|
||||
input Applied_price_ IPC=PRICE_CLOSE_;//öåíîâàÿ êîíñòàíòà
|
||||
input int Shift=0; // ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ
|
||||
input int PriceShift=0; // cäâèã èíäèêàòîðà ïî âåðòèêàëè â ïóíêòàõ
|
||||
//+-----------------------------------+
|
||||
|
||||
//---- îáúÿâëåíèå äèíàìè÷åñêîãî ìàññèâà, êîòîðûé áóäåò â
|
||||
// äàëüíåéøåì èñïîëüçîâàí â êà÷åñòâå èíäèêàòîðíîãî áóôåðà
|
||||
double ExtLineBuffer0[];
|
||||
|
||||
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â
|
||||
// äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
|
||||
double ExtLineBuffer1[],ExtLineBuffer2[],ExtLineBuffer3[];
|
||||
double ExtLineBuffer4[],ExtLineBuffer5[],ExtLineBuffer6[];
|
||||
|
||||
//---- Îáúÿâëåíèå ïåðåìåííîé çíà÷åíèÿ âåðòèêàëüíîãî ñäâèãà ìóâèíãà
|
||||
double dPriceShift;
|
||||
//---- Îáúÿâëåíèå ïåðåìåííîé äëÿ õðàíåíèÿ õåíäëà èíäèêàòîðà
|
||||
int ATR_Handle;
|
||||
//---- Îáúÿâëåíèå öåëûõ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
|
||||
int min_rates_XMA,min_rates_ATR,min_rates_total;
|
||||
//+------------------------------------------------------------------+
|
||||
//| ATR Channels indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//---- ïîëó÷åíèå õåíäëà èíäèêàòîðà ATR
|
||||
ATR_Handle=iATR(NULL,PERIOD_CURRENT,ATRPeriod);
|
||||
if(ATR_Handle==INVALID_HANDLE)
|
||||
{
|
||||
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà ATR");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
//---- Èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
|
||||
min_rates_XMA=GetStartBars(XMA_Method,XLength,XPhase)+1;
|
||||
min_rates_ATR=min_rates_XMA+int(ATRPeriod);
|
||||
min_rates_total=min_rates_XMA+min_rates_ATR;
|
||||
|
||||
//---- óñòàíîâêà àëåðòîâ íà íåäîïóñòèìûå çíà÷åíèÿ âíåøíèõ ïåðåìåííûõ
|
||||
XMA.XMALengthCheck("XLength",XLength);
|
||||
XMA.XMAPhaseCheck("XPhase",XPhase,XMA_Method);
|
||||
|
||||
//---- Èíèöèàëèçàöèÿ ñäâèãà ïî âåðòèêàëè
|
||||
dPriceShift=_Point*PriceShift;
|
||||
|
||||
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
|
||||
SetIndexBuffer(0,ExtLineBuffer0,INDICATOR_DATA);
|
||||
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 1 ïî ãîðèçîíòàëè
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
|
||||
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷¸òà îòðèñîâêè èíäèêàòîðà
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
|
||||
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðàõ êàê â òàéìñåðèÿõ
|
||||
ArraySetAsSeries(ExtLineBuffer0,true);
|
||||
|
||||
//---- ïðåâðàùåíèå äèíàìè÷åñêèõ ìàññèâîâ â èíäèêàòîðíûå áóôåðû
|
||||
SetIndexBuffer(1,ExtLineBuffer1,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLineBuffer2,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtLineBuffer3,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtLineBuffer4,INDICATOR_DATA);
|
||||
SetIndexBuffer(5,ExtLineBuffer5,INDICATOR_DATA);
|
||||
SetIndexBuffer(6,ExtLineBuffer6,INDICATOR_DATA);
|
||||
//---- óñòàíîâêà ïîçèöèè, ñ êîòîðîé íà÷èíàåòñÿ îòðèñîâêà óðîâíåé
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
//---- çàïðåò íà îòðèñîâêó èíäèêàòîðîì ïóñòûõ çíà÷åíèé
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðàõ êàê â òàéìñåðèÿõ
|
||||
ArraySetAsSeries(ExtLineBuffer1,true);
|
||||
ArraySetAsSeries(ExtLineBuffer2,true);
|
||||
ArraySetAsSeries(ExtLineBuffer3,true);
|
||||
ArraySetAsSeries(ExtLineBuffer4,true);
|
||||
ArraySetAsSeries(ExtLineBuffer5,true);
|
||||
ArraySetAsSeries(ExtLineBuffer6,true);
|
||||
|
||||
//---- èíèöèàëèçàöèè ïåðåìåííîé äëÿ êîðîòêîãî èìåíè èíäèêàòîðà
|
||||
string shortname;
|
||||
string Smooth=XMA.GetString_MA_Method(XMA_Method);
|
||||
StringConcatenate(shortname,"ATR Channels(",XLength," ",Smooth,")");
|
||||
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
|
||||
|
||||
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- çàâåðøåíèå èíèöèàëèçàöèè
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| ATR Channels iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(
|
||||
const int rates_total, // êîëè÷åñòâî èñòîðèè â áàðàõ íà òåêóùåì òèêå
|
||||
const int prev_calculated,// êîëè÷åñòâî èñòîðèè â áàðàõ íà ïðåäûäóùåì òèêå
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[]
|
||||
)
|
||||
{
|
||||
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷¸òà
|
||||
if(BarsCalculated(ATR_Handle)<rates_total || rates_total<min_rates_total) return(RESET);
|
||||
|
||||
//---- Îáúÿâëåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé
|
||||
double price_,xxma,Range[];
|
||||
//---- Îáúÿâëåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîñ÷èòàííûõ áàðîâ
|
||||
int to_copy,limit,bar;
|
||||
|
||||
//---- ðàñ÷¸òû íåîáõîäèìîãî êîëè÷åñòâà êîïèðóåìûõ äàííûõ è
|
||||
//ñòàðòîâîãî íîìåðà limit äëÿ öèêëà ïåðåñ÷¸òà áàðîâ
|
||||
if(prev_calculated>rates_total || prev_calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷¸òà èíäèêàòîðà
|
||||
{
|
||||
to_copy=rates_total; // ðàñ÷¸òíîå êîëè÷åñòâî âñåõ áàðîâ
|
||||
limit=rates_total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà âñåõ áàðîâ
|
||||
}
|
||||
else
|
||||
{
|
||||
limit=rates_total-prev_calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà íîâûõ áàðîâ
|
||||
to_copy=limit+1; // ðàñ÷¸òíîå êîëè÷åñòâî òîëüêî íîâûõ áàðîâ
|
||||
}
|
||||
|
||||
//---- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâ Range[]
|
||||
if(CopyBuffer(ATR_Handle,0,0,to_copy,Range)<=0) return(RESET);
|
||||
|
||||
//---- èíäåêñàöèÿ ýëåìåíòîâ â ìàññèâàõ êàê â òàéìñåðèÿõ
|
||||
ArraySetAsSeries(Range,true);
|
||||
ArraySetAsSeries(open,true);
|
||||
ArraySetAsSeries(high,true);
|
||||
ArraySetAsSeries(low,true);
|
||||
ArraySetAsSeries(close,true);
|
||||
|
||||
|
||||
//---- Îñíîâíîé öèêë ðàñ÷¸òà èíäèêàòîðà
|
||||
for(bar=limit; bar>=0 && !IsStopped(); bar--)
|
||||
{
|
||||
//---- Âûçîâ ôóíêöèè PriceSeries äëÿ ïîëó÷åíèÿ âõîäíîé öåíû price_
|
||||
price_=PriceSeries(IPC,bar,open,low,high,close);
|
||||
|
||||
xxma = XMA.XMASeries(rates_total-1,prev_calculated,rates_total,XMA_Method,XPhase,XLength,price_,bar,true);
|
||||
//----
|
||||
ExtLineBuffer0[bar]=xxma+dPriceShift;
|
||||
|
||||
ExtLineBuffer1[bar]=xxma+Range[bar]*Mult_Factor3+dPriceShift;
|
||||
ExtLineBuffer2[bar]=xxma+Range[bar]*Mult_Factor2+dPriceShift;
|
||||
ExtLineBuffer3[bar]=xxma+Range[bar]*Mult_Factor1+dPriceShift;
|
||||
ExtLineBuffer4[bar]=xxma-Range[bar]*Mult_Factor1+dPriceShift;
|
||||
ExtLineBuffer5[bar]=xxma-Range[bar]*Mult_Factor2+dPriceShift;
|
||||
ExtLineBuffer6[bar]=xxma-Range[bar]*Mult_Factor3+dPriceShift;
|
||||
}
|
||||
//----
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,21 @@
|
||||
# 🚀 Unlock the Power of Trading!
|
||||
|
||||
Welcome to this open-source trading project. Here you will find powerful tools to enhance your trading journey. If you find this project useful, please consider starring ⭐, sharing, or donating to support further development!
|
||||
|
||||
---
|
||||
|
||||
**Support the project:**
|
||||
- Star this repository on GitHub
|
||||
- Share it with your trading friends
|
||||
- [Donate here](https://www.paypal.com/donate/?hosted_button_id=YOUR_BUTTON_ID) to help us grow!
|
||||
|
||||
---
|
||||
|
||||
## Files included:
|
||||
### Source Files:
|
||||
- `ATR_Channels.mq5`
|
||||
|
||||
### Screenshots:
|
||||

|
||||
|
||||
> Made with ❤️ for the trading community.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
Reference in New Issue
Block a user