NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-21-2006, 12:03 AM   #1
Akros
 
Join Date: May 2006
Location: , ,
Posts: 28
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Other interesting indicators:

KELTNER BANDS

function preMain() {
setPriceStudy(true);

setStudyTitle("Keltner EMA of Close w/ ATR Bands ");

setCursorLabelName("K-Upper", 0);
setCursorLabelName("K-Basis", 1);
setCursorLabelName("K-Lower", 2);

setDefaultBarFgColor(Color.blue, 0); // upper
setDefaultBarFgColor(Color.red, 1); // basis
setDefaultBarFgColor(Color.blue, 2); // lower
}

function ATR(nInputLength) {
var dSum = 0;
var dH = high(0, -nInputLength);
var dL = low(0, -nInputLength);
var dC = close(-1, -nInputLength);
if (dH == null || dL == null || dC == null) {
return;
}
var i = 0;
for (i = 0; i < nInputLength; ++i) {
var vTrueHigh = Math.max(dH[i], dC[i]);
var vTrueLow = Math.min(dL[i], dC[i]);
var vTrueRange = (vTrueHigh - vTrueLow);
dSum += vTrueRange;
}
dSum /= nInputLength;
return dSum;
}

var BarCntr = 0;

function main(nInputLength, nRangeFactor) {
if(nInputLength == null)
nInputLength = 20;
if(nInputLength <= 0)
nInputLength = 20;

if(nRangeFactor == null)
nRangeFactor = 2.5;
if(nRangeFactor <= 0)
nRangeFactor = 2.5;

if (getBarState() == BARSTATE_NEWBAR) {
BarCntr += 1;
Rval1 = Rval;
}

if (BarCntr < nInputLength) {
return;
} else {
var dKeltnerBasis = getKeltner(nInputLength);
var dATR = ATR(nInputLength);
return new Array(dKeltnerBasis + (nRangeFactor * dATR), dKeltnerBasis, dKeltnerBasis - (nRangeFactor * dATR));
}
}



var dPercent = null;
var bPrimed = false;
var Rval = null;
var Rval1 = null;

function getKeltner(nInputLength) {
var i = 0;
var dC;
var dSum = 0.0;
var dRef;

if(dPercent == null) {
dPercent = (2.0 / (nInputLength + 1.0));
bPrimed = false;
}

if(bPrimed == false) {
dC = close(0, -nInputLength);
if(dC == null) return;
for(i = 0; i < nInputLength; i++) {
dSum += dC[i];
}
bPrimed = true;
Rval = (dSum / nInputLength);
return Rval;
} else {
dC = close();
if(dC == null) return null;
Rval = (dC - Rval1) * dPercent + Rval1;
return Rval;
}

return null;
}

LEAST SQUARE MOVING AVERAGE:

Description: Calculates the Least Square Moving Average (LSMA)
off the high and also off the low to create a channel.


Version Control:

*/



function preMain()
{
setPriceStudy(true);
setStudyTitle("LSMA Channel");
setCursorLabelName("LSMA Hi",0);
setCursorLabelName("LSMA Lo",1);
setDefaultBarThickness(2,0);
setDefaultBarThickness(2,1);

var fp1 = new FunctionParameter("HiLength", FunctionParameter.NUMBER);
fp1.setName("Length of LSMA(High)");
fp1.setDefault(25);

var fp2 = new FunctionParameter("LoLength", FunctionParameter.NUMBER);
fp2.setName("Length of LSMA(Low)");
fp2.setDefault(25);

var fp3 = new FunctionParameter("HiOffset", FunctionParameter.NUMBER);
fp3.setName("Offset of LSMA(High)");
fp3.setDefault(0);

var fp4 = new FunctionParameter("LoOffset", FunctionParameter.NUMBER);
fp4.setName("Offset of LSMA(Low)");
fp4.setDefault(0);

var fp5 = new FunctionParameter("HiColor", FunctionParameter.COLOR);
fp5.setName("Color of LSMA(High)");
fp5.setDefault(Color.blue);

var fp6 = new FunctionParameter("LoColor", FunctionParameter.COLOR);
fp6.setName("Color of LSMA(Low)");
fp6.setDefault(Color.red);
}


var aHigh = null;
var aLow = null;
var aHiLSMA = null;
var aLoLSMA = null;
var vInit = false;
var LSMA_Array = new Array();


function main(HiLength,LoLength,HiOffset,LoOffset,HiColor,L oColor)
{


if (vInit == false) {
aHigh = new Array(HiLength);
aLow = new Array(LoLength);
aHiLSMA = new Array(HiLength);
aLoLSMA = new Array(LoLength);
setDefaultBarFgColor(HiColor,0);
setDefaultBarFgColor(LoColor,1);
preMain();
vInit = true;
}

vHigh = high();
vLow = low();

if (vHigh == null) return;
if (vLow == null) return;

if (getBarState() == BARSTATE_NEWBAR) {
if (aHigh[HiLength-1] != null) aHigh.pop();
aHigh.unshift(vHigh);
if (aLow[LoLength-1] != null) aLow.pop();
aLow.unshift(vLow);
}

aHigh[0] = vHigh;
aLow[0] = vLow;

if (aHigh[HiLength-1] == null || aLow[LoLength-1] == null) return;

// get LSMA values and assign to arrays
var vHiLSMA = getLSMA(aHigh, HiLength);
var vLoLSMA = getLSMA(aLow, LoLength);

if (getBarState() == BARSTATE_NEWBAR) {
if (aHiLSMA[HiLength-1] != null) aHiLSMA.pop();
aHiLSMA.unshift(vHiLSMA);
if (aLoLSMA[LoLength-1] != null) aLoLSMA.pop();
aLoLSMA.unshift(vLoLSMA);
}

aHiLSMA[0] = vHiLSMA;
aLoLSMA[0] = vLoLSMA;


return new Array (aHiLSMA[HiOffset], aLoLSMA[LoOffset]);
}


// ------------------------------------
// Get a LSMA value
function getLSMA(aPrice, nLength) {
var Num1 = 0.0;
var Num2 = 0.0;
var SumBars = nLength * (nLength - 1) * 0.5;
var SumSqrBars = (nLength - 1) * nLength * (2 * nLength - 1) / 6;
var SumY = 0.0;
var Sum1 = 0.0;
var Sum2 = 0.0;
var Slope = 0.0;
var Intercept = 0.0;

for (i = 0; i < nLength; ++i) {
SumY += aPrice[i];
Sum1 += i * aPrice[i];
}
Sum2 = SumBars * SumY;
Num1 = nLength * Sum1 - Sum2;
Num2 = SumBars * SumBars - nLength * SumSqrBars;
if (Num2 != 0) Slope = Num1 / Num2;
Intercept = (SumY - Slope * SumBars) / nLength;
var LinearRegValue = Intercept + Slope * (nLength - 1);


return LinearRegValue;
}




HEIKEN ASHI BARS:

Notes:
* Non-price study
* Draws most recent 200 bars
* Formula Parameters
- Bullish Color Default: Green
- Bearish Color Default: Red

************************************************** ***************/

function preMain() {
setPriceStudy(true);
setStudyTitle("Heikin-Ashi FX Chart ");
setCursorLabelName("HA-High", 0);
setCursorLabelName("HA-Low", 1);
setCursorLabelName("HA-Open", 2);
setCursorLabelName("HA-Close", 3);
setDefaultBarFgColor(Color.black, 0);
setDefaultBarFgColor(Color.black, 1);
setDefaultBarFgColor(Color.black, 2);
setDefaultBarFgColor(Color.black, 3);
setPlotType(PLOTTYPE_DOT, 0);
setPlotType(PLOTTYPE_DOT, 1);
setPlotType(PLOTTYPE_DOT, 2);
setPlotType(PLOTTYPE_DOT, 3);
setDefaultBarThickness(0, 0);
setDefaultBarThickness(0, 1);
setDefaultBarThickness(0, 2);
setDefaultBarThickness(0, 3);

var fp1 = new FunctionParameter("cBull", FunctionParameter.COLOR);
fp1.setName("Bullish Candles");
fp1.setDefault(Color.green);

var fp2 = new FunctionParameter("cBear", FunctionParameter.COLOR);
fp2.setName("Bearish Candles");
fp2.setDefault(Color.red);


}

var haClose = null;
var haOpen = null;
var haClose1 = null;
var haOpen1 = null;
var iCntr = 0;

function main(cBull, cBear) {
var nState = getBarState();

if (nState == BARSTATE_NEWBAR) {
if ((haClose == null || haOpen == null) && close(-1) != null) {
haClose = close(-1);
haOpen = open(-1);
}
haClose1 = haClose;
haOpen1 = haOpen;
iCntr += 1;
if (iCntr > 200) iCntr = 0;
}

if (haClose1 == null || haOpen1 == null) return;

haOpen = (haOpen1 + haClose1) / 2;
haClose = (open() + high() + low() + close()) / 4;
var haHigh = Math.max(high(), haOpen, haClose);
var haLow = Math.min(low(), haOpen, haClose);

//candlesticks
var vColor = Color.black;
if (haClose > haOpen) vColor = cBull;
if (haClose < haOpen) vColor = cBear;
setBarFgColor(vColor, 2);
setBarFgColor(vColor, 3);

var retArray = new Array(4);

//var nFactor = 100000;
var nFactor = 1;
retArray[0] = (haHigh.toFixed(4)*nFactor);
retArray[1] = (haLow.toFixed(4)*nFactor);
retArray[2] = (haOpen.toFixed(4)*nFactor);
retArray[3] = (haClose.toFixed(4)*nFactor);


drawLineRelative(0, retArray[0], 0, retArray[1], PS_SOLID, 1, Color.black, "Shadow"+iCntr);
drawLineRelative(0, retArray[2], 0, retArray[3], PS_SOLID, 3, vColor, "Body"+iCntr);

return retArray;
} // End of Heikin-Ashi code




Akros is offline  
Reply With Quote
Old 06-21-2006, 12:24 AM   #2
NinjaTrader_Vincent
NinjaTrader Customer Service
 
NinjaTrader_Vincent's Avatar
 
Join Date: Mar 2005
Location: Amsterdam, The Netherlands
Posts: 2,042
Thanks: 0
Thanked 3 times in 3 posts
Post imported post

Akros,

Thanks for sharing this.

Vince
NinjaTrader_Vincent is offline  
Reply With Quote
Old 06-21-2006, 07:17 AM   #3
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Akros,

We already support LSMA, see our LinReg indicator, same thing.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-29-2006, 11:32 AM   #4
garciaal
Member
 
Join Date: Aug 2006
Location: Kennesaw, GA, ,
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Akros,

Is there a way to apply Stochastics to price panel?

Thanks,

Alex
garciaal is offline  
Reply With Quote
Old 08-29-2006, 11:54 AM   #5
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

No there is not.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-05-2006, 02:24 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

HeikenAshi indicator for NT6.
Attached Images
File Type: png HeikenAshi.png (50.3 KB, 212 views)
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-09-2006, 08:43 AM   #7
babamini
 
Join Date: Nov 2006
Location: , ,
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

[align=left]Hi,
I beg to use this means to seriously beg you to help me. I have a couple of indicators which were written with MT4 language for metatrader platform.

I need these indicators on Ninja but I am the furthest you can find from programming. I know next to nothing. Please help me or direct me to where I can get help.

Cheers
Babamini
[/align]
babamini is offline  
Reply With Quote
Old 11-09-2006, 08:10 PM   #8
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

Please send me PM to "dierk AT ninjatrader.com" and I will ge you in touch with someone who eventually could code your indicators in NinjaScript on a contractual base.
NinjaTrader_Dierk is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:58 AM.