Initial commit: MQL5 Indicators Collection (MetaTrader 5) - Part 2
This commit is contained in:
@@ -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:
|
||||
- `fdi.mq5`
|
||||
|
||||
### Screenshots:
|
||||

|
||||
|
||||
> Made with ❤️ for the trading community.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,342 @@
|
||||
//+------------------------------------------------------------------------------------------------------------------+
|
||||
//| fractal_dimension.mq5 |
|
||||
//| Copyright © 2008, iliko [arcsin5@netscape.net] |
|
||||
//| |
|
||||
//| |
|
||||
//| The Fractal Dimension Index determines the amount of market volatility. The easiest way to use this indicator is|
|
||||
//| to understand that a value of 1.5 suggests the market is acting in a completely random fashion. |
|
||||
//| As the market deviates from 1.5, the opportunity for earning profits is increased in proportion |
|
||||
//| to the amount of deviation. |
|
||||
//| But be carreful, the indicator does not show the direction of trends !! |
|
||||
//| |
|
||||
//| The indicator is RED when the market is in a trend. And it is blue when there is a high volatility. |
|
||||
//| When the FDI changes its color from red to blue, it means that a trend is finishing, the market becomes |
|
||||
//| erratic and a high volatility is present. Usually, these "blue times" do not go for a long time.They come before|
|
||||
//| a new trend. |
|
||||
//| |
|
||||
//| For more informations, see |
|
||||
//| http://www.forex-tsd.com/suggestions-trading-systems/6119-tasc-03-07-fractal-dimension-index.html |
|
||||
//| |
|
||||
//| |
|
||||
//| HOW TO USE INPUT PARAMETERS : |
|
||||
//| ----------------------------- |
|
||||
//| |
|
||||
//| 1) e_period [ integer >= 1 ] => 30 |
|
||||
//| |
|
||||
//| The indicator will compute the historical market volatility over this period. |
|
||||
//| Choose its value according to the average of trend lengths. |
|
||||
//| |
|
||||
//| 2) IPC [ ENAM = { |
|
||||
//| 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 |
|
||||
//| |
|
||||
//| Defines on which price type the Fractal Dimension is computed. |
|
||||
//| |
|
||||
//| 3) e_random_line [ 0.0 < double < 2.0 ] => 1.5 |
|
||||
//| |
|
||||
//| Defines your separation betwen a trend market (red) and an erratic/high volatily one. |
|
||||
//| |
|
||||
//| v1.0 - February 2007 |
|
||||
//+------------------------------------------------------------------------------------------------------------------+
|
||||
#property copyright "Copyright © 2008, iliko [arcsin5@netscape.net]"
|
||||
#property link "http://fractalfinance.blogspot.com/"
|
||||
//---- íîìåð âåðñèè èíäèêàòîðà
|
||||
#property version "1.02"
|
||||
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
|
||||
#property indicator_separate_window
|
||||
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ
|
||||
#property indicator_buffers 2
|
||||
//---- èñïîëüçîâàíî âñåãî îäíî ãðàôè÷åñêîå ïîñòðîåíèå
|
||||
#property indicator_plots 1
|
||||
//+-----------------------------------+
|
||||
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà |
|
||||
//+-----------------------------------+
|
||||
//---- îòðèñîâêà èíäèêàòîðà â âèäå öâåòíûõ çíà÷êîâ
|
||||
#property indicator_type1 DRAW_COLOR_ARROW
|
||||
//---- â êà÷åñòâå öâåòîâ òðåõöâåòíîé ëèíèè èñïîëüçîâàíû
|
||||
#property indicator_color1 clrYellow,clrRed,clrMediumPurple
|
||||
//---- ëèíèÿ èíäèêàòîðà - íåïðåðûâíàÿ êðèâàÿ
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 2
|
||||
#property indicator_width1 2
|
||||
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
|
||||
#property indicator_label1 "FDI"
|
||||
//+-----------------------------------+
|
||||
//| îáúÿâëåíèå ïåðå÷èñëåíèé |
|
||||
//+-----------------------------------+
|
||||
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
|
||||
};
|
||||
//+-----------------------------------+
|
||||
//| ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ |
|
||||
//+-----------------------------------+
|
||||
input uint e_period=30;
|
||||
input uint normal_speed=20;
|
||||
input Applied_price_ IPC=PRICE_CLOSE_;//Öåíîâàÿ êîíñòàíòà
|
||||
input double e_random_line=1.5; //Óðîâåíü ñðàáàòûâàíèÿ
|
||||
input int Shift=0; // Ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ
|
||||
//+-----------------------------------+
|
||||
|
||||
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â
|
||||
// äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
|
||||
double IndBuffer[];
|
||||
double ColorIndBuffer[];
|
||||
|
||||
//---- Îáúÿâëåíèå öåëûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
|
||||
int min_rates_total,g_period_minus_1;
|
||||
//---- îáúÿâëåíèå ãëîáàëüíûõ ïåðåìåííûõ
|
||||
int Count[];
|
||||
double Data[],LOG_2;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïåðåñ÷åò ïîçèöèè ñàìîãî íîâîãî ýëåìåíòà â ìàññèâå |
|
||||
//+------------------------------------------------------------------+
|
||||
void Recount_ArrayZeroPos(int &CoArr[],// Âîçâðàò ïî ññûëêå íîìåðà òåêóùåãî çíà÷åíèÿ öåíîâîãî ðÿäà
|
||||
int Size)
|
||||
{
|
||||
//----
|
||||
int numb,Max1,Max2;
|
||||
static int count=1;
|
||||
|
||||
Max2=Size;
|
||||
Max1=Max2-1;
|
||||
|
||||
count--;
|
||||
if(count<0) count=Max1;
|
||||
|
||||
for(int iii=0; iii<Max2; iii++)
|
||||
{
|
||||
numb=iii+count;
|
||||
if(numb>Max1) numb-=Max2;
|
||||
CoArr[iii]=numb;
|
||||
}
|
||||
//----
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//---- Èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
|
||||
g_period_minus_1=int(e_period)-1;
|
||||
min_rates_total=int(e_period)+g_period_minus_1;
|
||||
LOG_2=MathLog(2.0);
|
||||
//---- ðàñïðåäåëåíèå ïàìÿòè ïîä ìàññèâû ïåðåìåííûõ
|
||||
ArrayResize(Count,e_period);
|
||||
ArrayResize(Data,e_period);
|
||||
|
||||
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
|
||||
SetIndexBuffer(0,IndBuffer,INDICATOR_DATA);
|
||||
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â öâåòîâîé, èíäåêñíûé áóôåð
|
||||
SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
|
||||
ArraySetAsSeries(IndBuffer,true);
|
||||
//--- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
|
||||
ArraySetAsSeries(ColorIndBuffer,true);
|
||||
|
||||
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 1 ïî ãîðèçîíòàëè
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
|
||||
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
|
||||
//---- èíèöèàëèçàöèè ïåðåìåííîé äëÿ êîðîòêîãî èìåíè èíäèêàòîðà
|
||||
string shortname;
|
||||
StringConcatenate(shortname,"FDI(",e_period,", ",normal_speed,")");
|
||||
//---- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
|
||||
|
||||
//---- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,1);
|
||||
//---- êîëè÷åñòâî ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà 1
|
||||
IndicatorSetInteger(INDICATOR_LEVELS,1);
|
||||
//---- çíà÷åíèÿ ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,e_random_line);
|
||||
//---- â êà÷åñòâå öâåòà ëèíèè ãîðèçîíòàëüíîãî óðîâíÿ èñïîëüçîâàí ñåðûé öâåò
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrGray);
|
||||
//---- â ëèíèè ãîðèçîíòàëüíîãî óðîâíÿ èñïîëüçîâàí êîðîòêèé øòðèõ-ïóíêòèð
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT);
|
||||
//---- çàâåðøåíèå èíèöèàëèçàöèè
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator 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(rates_total<min_rates_total) return(0);
|
||||
//---- Îáúÿâëåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîñ÷èòàííûõ áàðîâ
|
||||
int limit,bar;
|
||||
|
||||
//--- ðàñ÷åò ñòàðòîâîãî íîìåðà limit äëÿ öèêëà ïåðåñ÷åòà áàðîâ
|
||||
if(prev_calculated>rates_total || prev_calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
|
||||
{
|
||||
limit=rates_total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
|
||||
ArrayInitialize(Count,0);
|
||||
ArrayInitialize(Data,0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
limit=rates_total-prev_calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ
|
||||
}
|
||||
|
||||
//--- èíäåêñàöèÿ ýëåìåíòîâ â ìàññèâàõ êàê â òàéìñåðèÿõ
|
||||
ArraySetAsSeries(open,true);
|
||||
ArraySetAsSeries(close,true);
|
||||
ArraySetAsSeries(high,true);
|
||||
ArraySetAsSeries(low,true);
|
||||
|
||||
//---- Îñíîâíîé öèêë ðàñ÷åòà èíäèêàòîðà
|
||||
for(bar=limit; bar>=0 && !IsStopped(); bar--)
|
||||
{
|
||||
//---- Âûçîâ ôóíêöèè PriceSeries äëÿ ïîëó÷åíèÿ âõîäíîé öåíû price
|
||||
Data[Count[0]]=PriceSeries(IPC,bar,open,low,high,close);
|
||||
//----
|
||||
double priceMax=0.0;
|
||||
for(int iii=0; iii<int(e_period); iii++) if(Data[Count[iii]]>priceMax) priceMax=Data[Count[iii]];
|
||||
double priceMin=99999999.0;
|
||||
for(int iii=0; iii<int(e_period); iii++) if(Data[Count[iii]]<priceMin) priceMin=Data[Count[iii]];
|
||||
double range=priceMax-priceMin;
|
||||
//----
|
||||
double length=0.0;
|
||||
double fdi,priorDiff=0.0;
|
||||
//----
|
||||
for(int kkk=0; kkk<=g_period_minus_1; kkk++)
|
||||
{
|
||||
if(range>0.0)
|
||||
{
|
||||
double diff=(Data[Count[kkk]]-priceMin)/range;
|
||||
if(kkk>0) length+=MathSqrt(MathPow(diff-priorDiff,2.0)+(1.0/MathPow(e_period,2.0)));
|
||||
priorDiff=diff;
|
||||
}
|
||||
}
|
||||
if(length>0.0)
|
||||
{
|
||||
fdi=1.0+(MathLog(length)+LOG_2)/MathLog(2*g_period_minus_1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
** The FDI algorithm suggests in this case a zero value.
|
||||
** I prefer to use the previous FDI value.
|
||||
*/
|
||||
fdi=0.0;
|
||||
}
|
||||
IndBuffer[bar]=fdi;
|
||||
if(bar) Recount_ArrayZeroPos(Count,e_period);
|
||||
}
|
||||
|
||||
//---- êîððåêòèðîâêà çíà÷åíèÿ ïåðåìåííîé first
|
||||
if(prev_calculated>rates_total || prev_calculated<=0) // ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
|
||||
limit--; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
|
||||
|
||||
//---- Îñíîâíîé öèêë ðàñêðàñêè ñèãíàëüíîé ëèíèè
|
||||
for(bar=limit; bar>=0 && !IsStopped(); bar--)
|
||||
{
|
||||
ColorIndBuffer[bar]=1;
|
||||
if(IndBuffer[bar]>e_random_line) ColorIndBuffer[bar]=0;
|
||||
if(IndBuffer[bar]<e_random_line) ColorIndBuffer[bar]=2;
|
||||
}
|
||||
//----
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå çíà÷åíèÿ öåíîâîé òàéìñåðèè |
|
||||
//+------------------------------------------------------------------+
|
||||
double PriceSeries
|
||||
(
|
||||
uint applied_price,// Öåíîâàÿ êîíñòàíòà
|
||||
uint bar,// Èíäåêñ ñäâèãà îòíîñèòåëüíî òåêóùåãî áàðà íà óêàçàííîå êîëè÷åñòâî ïåðèîäîâ íàçàä èëè âïåð¸ä).
|
||||
const double &Open[],
|
||||
const double &Low[],
|
||||
const double &High[],
|
||||
const double &Close[]
|
||||
)
|
||||
//PriceSeries(applied_price, bar, open, low, high, close)
|
||||
//+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
|
||||
{
|
||||
//----
|
||||
switch(applied_price)
|
||||
{
|
||||
//---- Öåíîâûå êîíñòàíòû èç ïåðå÷èñëåíèÿ ENUM_APPLIED_PRICE
|
||||
case PRICE_CLOSE: return(Close[bar]);
|
||||
case PRICE_OPEN: return(Open [bar]);
|
||||
case PRICE_HIGH: return(High [bar]);
|
||||
case PRICE_LOW: return(Low[bar]);
|
||||
case PRICE_MEDIAN: return((High[bar]+Low[bar])/2.0);
|
||||
case PRICE_TYPICAL: return((Close[bar]+High[bar]+Low[bar])/3.0);
|
||||
case PRICE_WEIGHTED: return((2*Close[bar]+High[bar]+Low[bar])/4.0);
|
||||
|
||||
//----
|
||||
case 8: return((Open[bar] + Close[bar])/2.0);
|
||||
case 9: return((Open[bar] + Close[bar] + High[bar] + Low[bar])/4.0);
|
||||
//----
|
||||
case 10:
|
||||
{
|
||||
if(Close[bar]>Open[bar])return(High[bar]);
|
||||
else
|
||||
{
|
||||
if(Close[bar]<Open[bar])
|
||||
return(Low[bar]);
|
||||
else return(Close[bar]);
|
||||
}
|
||||
}
|
||||
//----
|
||||
case 11:
|
||||
{
|
||||
if(Close[bar]>Open[bar])return((High[bar]+Close[bar])/2.0);
|
||||
else
|
||||
{
|
||||
if(Close[bar]<Open[bar])
|
||||
return((Low[bar]+Close[bar])/2.0);
|
||||
else return(Close[bar]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//----
|
||||
case 12:
|
||||
{
|
||||
double res=High[bar]+Low[bar]+Close[bar];
|
||||
if(Close[bar]<Open[bar]) res=(res+Low[bar])/2;
|
||||
if(Close[bar]>Open[bar]) res=(res+High[bar])/2;
|
||||
if(Close[bar]==Open[bar]) res=(res+Close[bar])/2;
|
||||
return(((res-Low[bar])+(res-High[bar]))/2);
|
||||
}
|
||||
//----
|
||||
default: return(Close[bar]);
|
||||
}
|
||||
//----
|
||||
//return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
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: 3.7 KiB |
Reference in New Issue
Block a user