hello and thanks for all ,can you convert 2 metatrader indicator code to amibroker , many many thanks for all of you , special KelvinHand for your help ,
//----------------------------------------------------------------------------------------------
//#1indicator nst
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Orange
#property indicator_level1 -50
#property indicator_level2 0
#property indicator_level3 50
#property indicator_levelcolor Gray
#property indicator_levelstyle 2
#property indicator_minimum -100
#property indicator_maximum 100
extern int NST_period = 20;
extern int SmLen = 10;
static datetime lastcalctime;
double NST[];
double RawNST[];
double maNST[];
double fC0Buffer[];
double fA8Buffer[];
double fC8Buffer[];
double list[128], ring1[128], ring2[11], buffer[62];
bool initFlag;
int limitValue, startValue, loopParam, loopCriteria;
int cycleLimit, highLimit, counterA, counterB;
double cycleDelta, lowDValue, highDValue, absValue, paramA, paramB;
double phaseParam, logParam, JMAValue, series, sValue, sqrtParam, lengthDivider;
int s58, s60, s40, s38, s68;
int init()
{
if(SmLen < 5) SmLen = 5;
else if(SmLen > 15) SmLen = 15;
string nstname = "NST(" + NST_period + ", " + SmLen + ")";
IndicatorShortName(nstname);
IndicatorDigits(0);
IndicatorBuffers(3);
SetIndexBuffer(0, NST);
SetIndexLabel(0, nstname);
SetIndexBuffer(1, RawNST);
SetIndexBuffer(2, maNST);
return(0);
}
int start()
{
if(bars <= NST_period + 3*SmLen) return(0);
if(counted_bars < 0) counted_bars = 0;
if(counted_bars > NST_period) limit = bars - counted_bars;
else limit = bars - NST_period - 1;
for(i = limit; i >= 0; i--)
{
double SumWgt = 0, SumDnm = 0, HghAry, LowAry, RngAry, FrcAry, TmeAry, WgtAry;
for(ii = 0; ii <= NST_period; ii++)
{
if(ii < 2) HghAry = High; else HghAry = High[iHighest(NULL, 0, MODE_HIGH, ii, i)];
if(ii < 2) LowAry = Low; else LowAry = Low[iLowest(NULL, 0, MODE_LOW, ii, i)];
RngAry = HghAry - LowAry;
if(RngAry == 0) FrcAry = 0; else FrcAry = (Close - LowAry) / RngAry;
TmeAry = 1 / MathPow(ii+1, 0.5);
WgtAry = TmeAry * FrcAry;
SumWgt += WgtAry;
SumDnm += TmeAry;
}
RawNST = (200 * SumWgt / SumDnm) - 100;
}
double ExpSmooth = 2, XAvg1, XAvg2, XAvg3;
ExpSmooth = ExpSmooth / (SmLen + 1);
for(i = bars - NST_period - 1; i >= 0; i--)
{
XAvg1 += ExpSmooth * (RawNST - XAvg1);
XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
maNST = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
if(i < bars - NST_period - 1 - 3*SmLen)
{
if(maNST > 85) NST = MathRound(85 + (maNST - 85) / 2);
else if(maNST < -85) NST = MathRound(-85 - (MathAbs(maNST) - 85) / 2);
else NST = MathRound(maNST);
}
}
return(0);
}
int IntPortion(double param)
{
if (param > 0) return (MathFloor (param));
if (param < 0) return (MathCeil (param));
return (0);
}
//----------------------------------------------------------------------------------------------
//----------#2 indicator nxc
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Lime
#property indicator_level1 -50
#property indicator_level2 0
#property indicator_level3 50
#property indicator_levelcolor Gray
#property indicator_levelstyle 2
#property indicator_minimum -100
#property indicator_maximum 100
extern int NDX_period = 40;
extern int NDX_SmLen = 20;
extern int NST_period = 20;
extern int NST_SmLen = 10;
static datetime lastcalctime;
double NXC[];
double ZH[];
double RawNDX[];
double RawNST[];
double maNDX[];
double maNST[];
double fC0Buffer[];
double fA8Buffer[];
double fC8Buffer[];
double list[128], ring1[128], ring2[11], buffer[62];
bool initFlag;
int limitValue, startValue, loopParam, loopCriteria;
int cycleLimit, highLimit, counterA, counterB;
double cycleDelta, lowDValue, highDValue, absValue, paramA, paramB;
double phaseParam, logParam, JMAValue, series, sValue, sqrtParam, lengthDivider;
int s58, s60, s40, s38, s68;
int init()
{
if(NDX_SmLen < 10) NDX_SmLen = 10;
else if(NDX_SmLen > 30) NDX_SmLen = 30;
if(NST_SmLen < 5) NST_SmLen = 5;
else if(NST_SmLen > 15) NST_SmLen = 15;
string nxcname = "NXC(" + NDX_period + ", " + NDX_SmLen + ", " +
NST_period + ", " + NST_SmLen + ")";
IndicatorShortName(nxcname);
IndicatorDigits(0);
IndicatorBuffers(4);
SetIndexBuffer(0, NXC);
SetIndexLabel(0, nxcname);
SetIndexBuffer(1, ZH);
SetIndexLabel(1, "NXC_ZH");
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, ZH_symbol);
SetIndexBuffer(2, RawNDX);
SetIndexBuffer(3, RawNST);
return(0);
}
int start()
{
double ExpSmooth, XAvg1, XAvg2, XAvg3, avg, sign;
if(MaxBars > 0) { bars = MaxBars; if(counted_bars > bars) counted_bars = bars - 2; } else bars = Bars;
int start = 3*MathMax(NDX_SmLen, NST_SmLen);
if(bars <= MathMax(NDX_period, NST_period) + start) return(0);
if(counted_bars < 0) counted_bars = 0;
if(counted_bars > MathMax(NDX_period, NST_period)) limit = bars - counted_bars;
else limit = bars - MathMax(NDX_period, NST_period) - 1;
for(i = limit; i >= 0; i--)
{
double SumWght = 0, SumDnom = 0, DifAry, DnomAry, FracAry, TimeAry, WghtAry;
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) - MathLog(Close[i+ii])) / DnomAry;
TimeAry = 1 / MathPow(ii, 0.5);
WghtAry = FracAry * TimeAry;
SumWght += WghtAry;
SumDnom += TimeAry;
}
RawNDX = 100 * SumWght / SumDnom;
}
ArrayResize(maNDX, bars - MathMax(NDX_period, NST_period));
ArraySetAsSeries(maNDX, true);
ArrayInitialize(maNDX, 0);
ExpSmooth = 2; XAvg1 = 0; XAvg2 = 0; XAvg3 = 0;
ExpSmooth = ExpSmooth / (NDX_SmLen + 1);
for(i = bars - MathMax(NDX_period, NST_period) - 1; i >= 0; i--)
{
XAvg1 += ExpSmooth * (RawNDX - XAvg1);
XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
maNDX = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
}
for(i = limit; i >= 0; i--)
{
double SumWgt = 0, SumDnm = 0, HghAry, LowAry, RngAry, FrcAry, TmeAry, WgtAry;
for(ii = 0; ii <= NST_period; ii++)
{
if(ii < 2) HghAry = High; else HghAry = High[iHighest(NULL, 0, MODE_HIGH, ii, i)];
if(ii < 2) LowAry = Low; else LowAry = Low[iLowest(NULL, 0, MODE_LOW, ii, i)];
RngAry = HghAry - LowAry;
if(RngAry == 0) FrcAry = 0; else FrcAry = (Close - LowAry) / RngAry;
TmeAry = 1 / MathPow(ii+1, 0.5);
WgtAry = TmeAry * FrcAry;
SumWgt += WgtAry;
SumDnm += TmeAry;
}
RawNST = (200 * SumWgt / SumDnm) - 100;
}
ArrayResize(maNST, bars - MathMax(NDX_period, NST_period));
ArraySetAsSeries(maNST, true);
ArrayInitialize(maNST, 0);
ExpSmooth = 2; XAvg1 = 0; XAvg2 = 0; XAvg3 = 0;
ExpSmooth = ExpSmooth / (NST_SmLen + 1);
for(i = bars - MathMax(NDX_period, NST_period) - 1; i >= 0; i--)
{
XAvg1 += ExpSmooth * (RawNST - XAvg1);
XAvg2 += ExpSmooth * (XAvg1 - XAvg2);
XAvg3 += ExpSmooth * (XAvg2 - XAvg3);
maNST = 3 * XAvg1 - 3 * XAvg2 + XAvg3;
}
for(i = limit; i >= 0; i--)
if(i < bars - MathMax(NDX_period, NST_period) - 1 - start)
{
avg = ((MathAbs(maNDX) * maNST) + (MathAbs(maNST) * maNDX)) / 2;
if(avg > 0) sign = 1;
else if(avg < 0) sign = -1;
else sign = 0;
NXC = MathRound(sign * MathSqrt(MathAbs(avg)));
}
return(0);
}
int IntPortion(double param)
{
if (param > 0) return (MathFloor (param));
if (param < 0) return (MathCeil (param));
return (0);
}