emvcandle
Download scriptLogic Overview: EMVCandle Indicator
The EMVCandle script is a specialized visual tool designed for the MetaTrader platform. Its primary purpose is to generate a smoothed, "filtered" version of price action, represented as colored candles in a separate window. Instead of showing the raw, often jagged movements of the market, this indicator transforms price data into a cleaner format to help traders identify trends with less visual noise.
Core Functional Logic
1. Multi-Layered Smoothing Process The script does not rely on a single calculation. It acts as a wrapper that calls upon an underlying smoothing engine (referenced as "EMV"). This engine processes four distinct types of price data:
- Opening prices
- High prices
- Low prices
- Closing prices
By applying specific mathematical methods (such as SMA, EMA, or more complex variations like Jurik or T3), the script strips away minor market fluctuations to reveal the broader price direction.
2. Synthetic Candle Construction Once the smoothing engine provides the processed data for each price point, the script reconstructs "synthetic" candles. It determines:
- The Body: Based on the smoothed Open and Close values.
- The Extremes: It compares the smoothed Open/Close values against the smoothed High/Low values to ensure the candle's outer boundaries are mathematically consistent.
3. Dynamic Color Coding A key feature of this logic is its automated coloring system. The indicator assigns colors to these synthetic candles based on the relationship between the smoothed opening and closing prices:
- Bullish Sentiment: One color is assigned when the smoothed Close is higher than the Open.
- Bearish Sentiment: A different color is assigned when the smoothed Close is lower than the Open.
- Neutrality: A third color is applied if the smoothed prices are equal (indicating no movement).
User Inputs and Customization
The script allows for high levels of customization to suit different trading styles:
- Smoothing Method: Users can choose from various mathematical algorithms to decide how "reactive" or "smooth" the candles should be.
- Length and Phase: These parameters control the depth of the smoothing—higher values will result in much smoother, slower-moving candles, while lower values will follow the price more closely.
- Volume Integration: The logic includes a toggle to factor in tick volume, allowing the indicator to consider trading activity as part of its calculation.
Summary for the Trader
In essence, this script takes messy market data and "refines" it into a series of colored candles. It allows you to see the "true" trend by filtering out the noise, using different smoothing techniques to prioritize either immediate price action or long-term momentum.
//+------------------------------------------------------------------+
//| EMVCandle.mq5 |
//| Copyright © 2013, Nikolay Kositsin |
//| Khabarovsk, farria@mail.redcom.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
#property description "EMVCandle"
//---- íîìåð âåðñèè èíäèêàòîðà
#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 clrDeepPink,clrGray,clrBlue
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1 "EMVCandle Open;EMVCandle High;EMVCandle Low;EMVCandle 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_SMA; // Ìåòîä óñðåäíåíèÿ
input int XLength=14; // Ãëóáèíà ñãëàæèâàíèÿ
input int XPhase=15; // Ïàðàìåòð ñãëàæèâàíèÿ
//--- äëÿ JJMA èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
//--- äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK; // Îáúåì
//+----------------------------------------------+
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â
//---- äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorBuffer[];
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total;
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int Ind_Handle[4];
//+----------------------------------------------+
//| Îáúÿâëåíèå ïåðå÷èñëåíèé |
//+----------------------------------------------+
enum Applied_price_ //Òèï êîíñòàíòû
{
PRICE_CLOSE_ = 1, //PRICE_CLOSE
PRICE_OPEN_, //PRICE_OPEN
PRICE_HIGH_, //PRICE_HIGH
PRICE_LOW_, //PRICE_LOW
PRICE_MEDIAN_, //PRICE_MEDIAN
PRICE_TYPICAL_, //PRICE_TYPICAL
PRICE_WEIGHTED_, //PRICE_WEIGHTED
PRICE_SIMPL_, //PRICE_SIMPL_
PRICE_QUARTER_, //PRICE_QUARTER_
PRICE_TRENDFOLLOW0_,//PRICE_TRENDFOLLOW0_
PRICE_TRENDFOLLOW1_, //TrendFollow_2 Price
PRICE_DEMARK_ //Demark Price
};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- èíèöèàëèçàöèÿ ãëîáàëüíûõ ïåðåìåííûõ
min_rates_total=GetStartBars(XMA_Method,XLength,XPhase)+1;
//---- ïîëó÷åíèå õåíäëîâ èíäèêàòîðà EMV
Ind_Handle[0]=iCustom(NULL,0,"EMV",XMA_Method,XLength,XPhase,PRICE_OPEN_,VolumeType,0);
if(Ind_Handle[0]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iEMV["+string(0)+"]!");
return(INIT_FAILED);
}
//----
Ind_Handle[1]=iCustom(NULL,0,"EMV",XMA_Method,XLength,XPhase,PRICE_HIGH_,VolumeType,0);
if(Ind_Handle[1]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iEMV["+string(1)+"]!");
return(INIT_FAILED);
}
//----
Ind_Handle[2]=iCustom(NULL,0,"EMV",XMA_Method,XLength,XPhase,PRICE_LOW_,VolumeType,0);
if(Ind_Handle[2]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iEMV["+string(2)+"]!");
return(INIT_FAILED);
}
//----
Ind_Handle[3]=iCustom(NULL,0,"EMV",XMA_Method,XLength,XPhase,PRICE_CLOSE_,VolumeType,0);
if(Ind_Handle[3]==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iEMV["+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,_Digits);
//---- èìÿ äëÿ îêîí äàííûõ è ìåòêà äëÿ ñóáúîêîí
string short_name="EMVCandle";
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