Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #property indicator_separate_window
- #property indicator_buffers 1
- #property indicator_color1 Red
- #property indicator_level1 0
- #property indicator_level2 50
- #property indicator_level3 -50
- #property indicator_levelcolor Gray
- #property indicator_levelstyle 2
- extern int NDX_period = 40;
- extern int SmLen = 20;
- double NDX[];
- double RawNDX[];
- int init()
- {
- if(SmLen < 10) SmLen = 10;
- else if(SmLen > 30) SmLen = 30;
- string ndxname = "NDX(" + NDX_period + ")";
- IndicatorShortName(ndxname);
- IndicatorDigits(0);
- IndicatorBuffers(2);
- SetIndexBuffer(0, NDX);
- SetIndexLabel(0, ndxname);
- SetIndexBuffer(1, RawNDX);
- return(0);
- }
- int start()
- {
- int limit, i, ii, counted_bars = IndicatorCounted();
- if(Bars <= NDX_period + 3*SmLen) return(0);
- if(counted_bars < 0) counted_bars = 0;
- if(counted_bars > NDX_period) limit = Bars - counted_bars;
- else limit = Bars - NDX_period - 1;
- for(i = limit; i >= 0; i--)
- {
- double SumWght = 0, SumDnom = 0, DifAry, DnomAry, FracAry, TimeAry, WgtAry;
- for(ii = 1; ii <= NDX_period; ii++)
- {
- DifAry = MathLog(Close[i+ii-1]) - MathLog(Close[i+ii]);
- if(ii == 1) DnomAry = MathAbs(DifAry); else DnomAry += MathAbs(DifAry);
- if(DnomAry == 0) FracAry = 0; else FracAry = (MathLog(Close[i]) - MathLog(Close[i+ii])) / DnomAry;
- TimeAry = 1 / MathPow(ii, 0.5);
- WgtAry = FracAry * TimeAry;
- SumWght += WgtAry;
- SumDnom += TimeAry;
- }
- RawNDX[i] = 100 * SumWght / SumDnom;
- }
- double ExpSmooth = 2, XAvg1, XAvg2, XAvg3, TemaNDX;
- ExpSmooth = ExpSmooth / (SmLen + 1);
- for(i = Bars - NDX_period - 1; i >= 0; i--)
- {
- XAvg1 += ExpSmooth * (RawNDX[i] - XAvg1);
- XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
- XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
- TemaNDX = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
- if(i < Bars - NDX_period - 1 - 3*SmLen)
- {
- if(TemaNDX > 90) NDX[i] = MathRound(90 + (TemaNDX - 90) / 2);
- else if(TemaNDX < -90) NDX[i] = MathRound(-90 - (MathAbs(TemaNDX) - 90) / 2);
- else NDX[i] = MathRound(TemaNDX);
- }
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement