Indicators Used
0
Views
0
Downloads
0
Favorites
wpr_histogram
//+------------------------------------------------------------------+
//| WPR_Histogram.mq5 |
//| Copyright © 2011, Nikolay Kositsin |
//| Khabarovsk, farria@mail.redcom.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
//---- íîìåð âåðñèè èíäèêàòîðà
#property version "1.00"
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ 3
#property indicator_buffers 3
//---- èñïîëüçîâàíî îäíî ãðàôè÷åñêîå ïîñòðîåíèå
#property indicator_plots 1
//+-----------------------------------+
//| îáúÿâëåíèå êîíñòàíò |
//+-----------------------------------+
#define RESET 0 // Êîíñòàíòà äëÿ âîçâðàòà òåðìèíàëó êîìàíäû íà ïåðåñ÷¸ò èíäèêàòîðà
//+-----------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà |
//+-----------------------------------+
//---- îòðèñîâêà èíäèêàòîðà â âèäå ãèñòîãðàììû
#property indicator_type1 DRAW_COLOR_HISTOGRAM2
//---- â êà÷åñòâå öâåòîâ èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color1 clrDodgerBlue,clrGray,clrDeepPink
//---- ëèíèÿ èíäèêàòîðà - ñïëîøíàÿ
#property indicator_style1 STYLE_SOLID
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 2
#property indicator_width1 2
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1 "WPR_Histogram"
//+-----------------------------------+
//| ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ |
//+-----------------------------------+
input uint WPRPeriod=14; // ïåðèîä èíäèêàòîðà
input int HighLevel=-30; // óðîâåíü ïåðåêóïëåííîñòè
input int LowLevel=-70; // óðîâåíü ïåðåïðîäàííîñòè
input int Shift=0; // Ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ
//+-----------------------------------+
//---- Îáúÿâëåíèå öåëûõ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
int min_rates_total;
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â
// äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double UpBuffer[],DnBuffer[],ColorBuffer[];
//---- Îáúÿâëåíèå öåëûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int WPR_Handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- Èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
min_rates_total=int(WPRPeriod);
//---- ïîëó÷åíèå õåíäëà èíäèêàòîðà iWPR
WPR_Handle=iWPR(NULL,0,WPRPeriod);
if(WPR_Handle==INVALID_HANDLE)
{
Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà iWPR");
return(INIT_FAILED);
}
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
SetIndexBuffer(0,UpBuffer,INDICATOR_DATA);
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷¸òà îòðèñîâêè èíäèêàòîðà
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà ïî ãîðèçîíòàëè íà InpKijun
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
ArraySetAsSeries(UpBuffer,true);
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
SetIndexBuffer(1,DnBuffer,INDICATOR_DATA);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
ArraySetAsSeries(DnBuffer,true);
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â öâåòîâîé, èíäåêñíûé áóôåð
SetIndexBuffer(2,ColorBuffer,INDICATOR_COLOR_INDEX);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
ArraySetAsSeries(ColorBuffer,true);
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
IndicatorSetString(INDICATOR_SHORTNAME,"WPR_Histogram("+string(WPRPeriod)+")");
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- êîëè÷åñòâî ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà 3
IndicatorSetInteger(INDICATOR_LEVELS,3);
//---- çíà÷åíèÿ ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,HighLevel);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,-50);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,LowLevel);
//---- â êà÷åñòâå öâåòîâ ëèíèé ãîðèçîíòàëüíûõ óðîâíåé èñïîëüçîâàíû
IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrLimeGreen);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrMagenta);
//---- â ëèíèè ãîðèçîíòàëüíîãî óðîâíÿ èñïîëüçîâàí êîðîòêèé øòðèõ-ïóíêòèð
IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DASHDOTDOT);
//---- çàâåðøåíèå èíèöèàëèçàöèè
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(WPR_Handle)<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-min_rates_total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
}
else limit=rates_total-prev_calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ
to_copy=limit+1;
//---- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
if(CopyBuffer(WPR_Handle,0,0,to_copy,UpBuffer)<=0) return(RESET);
//---- îñíîâíîé öèêë ðàñêðàñêè èíäèêàòîðà
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
DnBuffer[bar]=-50.0;
int clr=1.0;
if(UpBuffer[bar]>HighLevel) clr=0.0;
else if(UpBuffer[bar]<LowLevel) clr=2.0;
ColorBuffer[bar]=clr;
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---