//+------------------------------------------------------------------+
//| dNonLagTMA.mq4 |
//| Dmitry Zinoviev |
//|
http://www.qtraders.pro |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Silver
#property indicator_color3 Lime
#property indicator_color4 FireBrick
#property indicator_color5 Green
extern int HalfLength = 20;
extern int TimeFrame = 0;
extern double K1 = 2.0;
extern double K2 = 2.5;
extern bool Interpolate = true;
int PRICE_MODE = 0;
int ATR_PERIOD = 100;
double upper[], middle[], lower[], upper2[], lower2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,0);
SetIndexDrawBegin(0,0);
SetIndexBuffer(0,upper);
SetIndexStyle(1,DRAW_LINE);
SetIndexShift(1,0);
SetIndexDrawBegin(1,0);
SetIndexBuffer(1,middle);
SetIndexStyle(2,DRAW_LINE);
SetIndexShift(2,0);
SetIndexDrawBegin(2,0);
SetIndexBuffer(2,lower);
SetIndexStyle(3,DRAW_LINE);
SetIndexShift(3,0);
SetIndexDrawBegin(3,0);
SetIndexBuffer(3,upper2);
SetIndexStyle(4,DRAW_LINE);
SetIndexShift(4,0);
SetIndexDrawBegin(4,0);
SetIndexBuffer(4,lower2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
double avg;
if(TimeFrame > Period())
limit = TimeFrame / Period() * limit;
for(int x=0; x<limit; x++)
{
middle[x] = iMA(NULL, TimeFrame, HalfLength+1 , 0, 3, PRICE_MODE, iBarShift(NULL, TimeFrame, Time[x]));
avg = iATR(NULL,TimeFrame,ATR_PERIOD, iBarShift(NULL, TimeFrame, Time[x])+10);
upper[x] = middle[x] + K1*avg;
lower[x] = middle[x] - K1*avg;
upper2[x] = middle[x] + K2*avg;
lower2[x] = middle[x] - K2*avg;
}
/*
if (Interpolate)
{
int Processed = iBarShift(NULL, 0, Time[Processed]);
limit = MathMin((limit * TimeFrame) / Period(), (Processed * TimeFrame) / Period());
for(int idx = limit; idx >= 0; idx--){
int shift = iBarShift(NULL, TimeFrame, Time[idx]);
if (TimeFrame <= Period() || shift == iBarShift(NULL, TimeFrame, Time[idx -1])) continue;
if (!Interpolate) continue;
datetime time = iTime(NULL, TimeFrame, shift);
for(int n = 1; (idx +n) < (Processed * (TimeFrame / Period()) - HalfLength) && Time[idx +n] >= time; n++) continue;
for(int k = 1; k < n; k++){
middle[idx +k] = middle[idx] +(middle[idx +n] -middle[idx]) * k/n;
upper[idx +k] = upper[idx] +(upper[idx +n] -upper[idx]) * k/n;
lower[idx +k] = lower[idx] +(lower[idx +n] -lower[idx]) * k/n;
upper2[idx +k] = upper2[idx] +(upper2[idx +n] -upper2[idx]) * k/n;
lower2[idx +k] = lower2[idx] +(lower2[idx +n] -lower2[idx]) * k/n;
}
}
}
*/
return(0);
}
//+------------------------------------------------------------------+