#property copyright "(С) 2014, Satori, 1.0"
#property link "http://fx-vladmih.ru"
#property version "1.0"
#property description "Однотаймовый супертренд. Используется в мультитаймовом. Поэтому не удалять!"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
extern int ATR_Period = 5;
double TrendUp[];
double TrendDown[];
int st = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function|
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0, TrendUp);
SetIndexBuffer(1, TrendDown);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function|
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function|
//+------------------------------------------------------------------+
int start()
{
int limit, i;
double cciTrendNow, cciTrendPrevious;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
for(i = limit; i >= 0; i--) {
cciTrendNow = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
cciTrendPrevious = iCCI(NULL, 0, 50, PRICE_TYPICAL, i+1);
if (cciTrendNow >= st && cciTrendPrevious < st) {
TrendUp[i+1] = TrendDown[i+1];
}
if (cciTrendNow <= st && cciTrendPrevious > st) {
TrendDown[i+1] = TrendUp[i+1];
}
if (cciTrendNow >= st) {
TrendUp[i] = Low[i] - iATR(NULL, 0, ATR_Period, i);
if (TrendUp[i] < TrendUp[i+1]) {
TrendUp[i] = TrendUp[i+1];
}
}
else if (cciTrendNow <= st) {
TrendDown[i] = High[i] + iATR(NULL, 0, ATR_Period, i);
if (TrendDown[i] > TrendDown[i+1]) {
TrendDown[i] = TrendDown[i+1];
}
}
}
//----
return(0);
}