Could some one please try to convert this mt4 Trix Trend Cycle 2 indicator into Ninja trader code.
#property link ""
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//
//
//
//
//
extern int TrixPeriod = 4;
extern int TrendCycle = 4;
//
//
//
//
//
double stcBuffer[];
double trix_buffer1[];
double trix_buffer2[];
double trix_buffer3[];
double cdBuffer[];
double fastKBuffer[];
double fastDBuffer[];
double fastKKBuffer[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(8);
SetIndexBuffer(0,stcBuffer);
SetIndexBuffer(1,trix_buffer1);
SetIndexBuffer(2,trix_buffer2);
SetIndexBuffer(3,trix_buffer3);
SetIndexBuffer(4,cdBuffer);
SetIndexBuffer(5,fastKBuffer);
SetIndexBuffer(6,fastDBuffer);
SetIndexBuffer(7,fastKKBuffer);
IndicatorShortName("Trix TC2 ("+TrixPeriod+","+TrendCycle+")");
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
double alphaCD = 2.0 / (1.0 + 3.0);
int counted_bars = IndicatorCounted();
int limit,i;
if(counted_bars < 0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
//
//
//
//
//
for(i=0; i<limit; i++) trix_buffer1[i]=iMA(NULL,0,TrixPeriod,0,MODE_SMMA,(PRICE_CLOSE+PR ICE_HIGH+PRICE_LOW),i);
for(i=0; i<limit; i++) trix_buffer2[i]=iMAOnArray(trix_buffer1,0,TrixPeriod,0,MODE_SMMA, i);
for(i=0; i<limit; i++) trix_buffer3[i]=iMAOnArray(trix_buffer2,0,TrixPeriod,0,MODE_EMA,i );
//
//
//
for(i = limit; i >= 0; i--)
{
cdBuffer[i] = cdBuffer[i+1]+alphaCD*(trix_buffer3[i]-trix_buffer3[i+1]);
//
//
//
//
//
double lowCd = minValue(cdBuffer,i);
double highCd = maxValue(cdBuffer,i)-lowCd;
if (highCd > 0)
fastKBuffer[i] = 100*((cdBuffer[i]-lowCd)/highCd);
else fastKBuffer[i] = fastKBuffer[i+1];
fastDBuffer[i] = fastDBuffer[i+1]+0.5*(fastKBuffer[i]-fastDBuffer[i+1]);
//
//
//
//
//
double lowStoch = minValue(fastDBuffer,i);
double highStoch = maxValue(fastDBuffer,i)-lowStoch;
if (highStoch > 0)
fastKKBuffer[i] = 100*((fastDBuffer[i]-lowStoch)/highStoch);
else fastKKBuffer[i] = fastKKBuffer[i+1];
stcBuffer[i] = stcBuffer[i+1]+0.5*(fastKKBuffer[i]-stcBuffer[i+1]);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double minValue(double& array[],int shift)
{
double minValue = array[shift];
for (int i=1; i<TrendCycle; i++) minValue = MathMin(minValue,array[shift+i]);
return(minValue);
}
double maxValue(double& array[],int shift)
{
double maxValue = array[shift];
for (int i=1; i<TrendCycle; i++) maxValue = MathMax(maxValue,array[shift+i]);
return(maxValue);
}
thanks.
Comment