fatlmacdcandle
Download scriptThis script creates a specialized visual tool for the MetaTrader 5 platform designed to display price action in a stylized "candle" format within a separate window. Rather than showing standard price bars on the main chart, it transforms complex mathematical calculations into a readable, color-coded visual representation.
Core Logic and Functionality
Data Processing and Smoothing The script does not rely on raw price data alone. It utilizes a sophisticated smoothing method (specifically the T3 method by default) to process market information. This means the indicator filters out minor "noise" in the market to identify more significant trends. It applies these calculations to four specific price components: the Open, High, Low, and Close values.
Visual Construction The primary output of this script is a series of colored candles. Each candle is constructed based on the following logic:
- Highs and Lows: The script determines the vertical boundaries of each candle by comparing the smoothed opening and closing prices against the existing high and low data points. This ensures that the "candles" accurately reflect the range of price movement within each period.
- Dynamic Coloring: The script automatically assigns colors to these candles based on the relationship between the opening and closing values:
- Bullish Movement: If the smoothed price closes higher than it opened, the candle is assigned one specific color (Dodger Blue).
- Bearish Movement: If the smoothed price closes lower than it opened, the candle is assigned another color (Orange).
- Neutral/Flat Movement: If there is no change between the open and close, the candle is assigned a neutral gray color.
Operational Efficiency To ensure the platform remains responsive, the script includes logic to handle data updates efficiently:
- Smart Recalculation: It identifies exactly how much new data has arrived on the chart and only performs calculations for the new bars, rather than recalculating the entire history every time the price moves.
- Data Integrity Checks: The script verifies that it has received sufficient data from the underlying smoothing algorithms before attempting to draw anything on the screen, preventing visual errors or "broken" graphics during high-volatility periods.
Summary for the User
In simple terms, this tool takes raw market data and "smooths" it out using advanced mathematical filters. It then redraws that data as a set of colored candles in its own window, allowing you to see the momentum and trend direction clearly without the distraction of standard price fluctuations.
//+------------------------------------------------------------------+
//| FatlMacdCandle.mq5 |
//| Copyright © 2015, Nikolay Kositsin |
//| Khabarovsk, farria@mail.redcom.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
#property description "Èíäèêàòîð FatlMacd â ñâå÷íîì âèäå"
//---- íîìåð âåðñèè èíäèêàòîðà
#property version "1.00"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà |
//+----------------------------------------------+
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//---- äëÿ ðàñ÷åòà è îòðèñîâêè èíäèêàòîðà èñïîëüçîâàíî ïÿòü áóôåðîâ
#property indicator_buffers 5
//---- èñïîëüçîâàíî âñåãî îäíî ãðàôè÷åñêîå ïîñòðîåíèå
#property indicator_plots 1
//---- â êà÷åñòâå èíäèêàòîðà èñïîëüçîâàíû öâåòíûå ñâå÷è
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrOrange,clrGray,clrDodgerBlue
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1 "FatlMacdCandle Open;FatlMacdCandle High;FatlMacdCandle Low;FatlMacdCandle Close"
//+----------------------------------------------+
//| Îáúÿâëåíèå êîíñòàíò |
//+----------------------------------------------+
#define RESET 0 // êîíñòàíòà äëÿ âîçâðàòà òåðìèíàëó êîìàíäû íà ïåðåñ÷¸ò èíäèêàòîðà
//+----------------------------------------------+
//| Îïèñàíèå êëàññà CXMA |
//+----------------------------------------------+
#include <SmoothAlgorithms.mqh>
//+----------------------------------------------+
//| Îáúÿâëåíèå ïåðå÷èñëåíèé |
//+----------------------------------------------+
/*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 Smooth_Method XMA_Method=MODE_T3; // Ìåòîä óñðåäíåíèÿ ãèñòîãðàììû
input int XMA_Lengh = 20; // Ïåðèîä óñðåäíåíèÿ
input int XMA_Phase= 100; // Ïàðàìåòð óñðåäíåíèÿ ñêîëüçÿùèõ ñðåäíèõ
//---- äëÿ JJMA èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
//---- äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
//+----------------------------------------------+
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â
//---- äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorBuffer[];
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
int min_rates_total;
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int Ind_Handle[4];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- èíèöèàëèçàöèÿ ãëîáàëüíûõ ïåðåìåííûõ
min_rates_total=GetStartBars(XMA_Method,XMA_Lengh,XMA_Phase)+1;
//---- îáúÿâëåíèå ïåðå÷èñëåíèé
enum Applied_price_ //Òèï êîíñòàíòû
{
PRICE_CLOSE_ = 1, //PRICE_CLOSE
PRICE_OPEN_, //PRICE_OPEN
PRICE_HIGH_, //PRICE_HIGH
PRICE_LOW_ //PRICE_LOW
};
//---- ïîëó÷åíèå õåíäëîâ èíäèêàòîðà FatlMacd
Ind_Handle[0]=iCustom(NULL,0,"FatlMacd",XMA_Method,XMA_Lengh,XMA_Phase,PRICE_OPEN_);
if(Ind_Handle[0]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iFatlMacd["+string(0)+"]!");
return(INIT_FAILED);
}
//----
Ind_Handle[1]=iCustom(NULL,0,"FatlMacd",XMA_Method,XMA_Lengh,XMA_Phase,PRICE_HIGH_);
if(Ind_Handle[1]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iFatlMacd["+string(1)+"]!");
return(INIT_FAILED);
}
//----
Ind_Handle[2]=iCustom(NULL,0,"FatlMacd",XMA_Method,XMA_Lengh,XMA_Phase,PRICE_LOW_);
if(Ind_Handle[2]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iFatlMacd["+string(2)+"]!");
return(INIT_FAILED);
}
//----
Ind_Handle[3]=iCustom(NULL,0,"FatlMacd",XMA_Method,XMA_Lengh,XMA_Phase,PRICE_CLOSE_);
if(Ind_Handle[3]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iFatlMacd["+string(3)+"]!");
return(INIT_FAILED);
}
//---- ïðåâðàùåíèå äèíàìè÷åñêèõ ìàññèâîâ â èíäèêàòîðíûå áóôåðû
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â öâåòîâîé, èíäåêñíûé áóôåð
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðàõ êàê â òàéìñåðèÿõ
ArraySetAsSeries(ExtOpenBuffer,true);
ArraySetAsSeries(ExtHighBuffer,true);
ArraySetAsSeries(ExtLowBuffer,true);
ArraySetAsSeries(ExtCloseBuffer,true);
ArraySetAsSeries(ExtColorBuffer,true);
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà 1
PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);
//---- óñòàíîâêà ôîðìàòà òî÷íîñòè îòîáðàæåíèÿ èíäèêàòîðà
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- èìÿ äëÿ îêîí äàííûõ è ìåòêà äëÿ ñóáúîêîí
string short_name="FatlMacdCandle";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- çàâåðøåíèå èíèöèàëèçàöèè
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator 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(Ind_Handle[0])<rates_total
|| BarsCalculated(Ind_Handle[1])<rates_total
|| BarsCalculated(Ind_Handle[2])<rates_total
|| BarsCalculated(Ind_Handle[3])<rates_total
|| rates_total<min_rates_total)
return(RESET);
//---- îáúÿâëåíèÿ ëîêàëüíûõ ïåðåìåííûõ
int to_copy,limit,bar;
//---- ðàñ÷¸òû íåîáõîäèìîãî êîëè÷åñòâà êîïèðóåìûõ äàííûõ è ñòàðòîâîãî íîìåðà limit äëÿ öèêëà ïåðåñ÷¸òà áàðîâ
if(prev_calculated>rates_total || prev_calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷¸òà èíäèêàòîðà
{
limit=rates_total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà âñåõ áàðîâ
}
else
{
limit=rates_total-prev_calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà íîâûõ áàðîâ
}
//----
to_copy=limit+1;
//---- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
if(CopyBuffer(Ind_Handle[0],0,0,to_copy,ExtOpenBuffer)<=0) return(RESET);
if(CopyBuffer(Ind_Handle[1],0,0,to_copy,ExtHighBuffer)<=0) return(RESET);
if(CopyBuffer(Ind_Handle[2],0,0,to_copy,ExtLowBuffer)<=0) return(RESET);
if(CopyBuffer(Ind_Handle[3],0,0,to_copy,ExtCloseBuffer)<=0) return(RESET);
//---- îñíîâíîé öèêë èñïðàâëåíèÿ è îêðàøèâàíèÿ ñâå÷åé
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
double Max=MathMax(ExtOpenBuffer[bar],ExtCloseBuffer[bar]);
double Min=MathMin(ExtOpenBuffer[bar],ExtCloseBuffer[bar]);
//----
ExtHighBuffer[bar]=MathMax(Max,ExtHighBuffer[bar]);
ExtLowBuffer[bar]=MathMin(Min,ExtLowBuffer[bar]);
//----
if(ExtOpenBuffer[bar]<ExtCloseBuffer[bar]) ExtColorBuffer[bar]=2.0;
else if(ExtOpenBuffer[bar]>ExtCloseBuffer[bar]) ExtColorBuffer[bar]=0.0;
else ExtColorBuffer[bar]=1.0;
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments