Hello,
I could not locate Sine Weighted MA indicator for NT. I have used it in eSignal and it is normalized and is very smooth. Below is code in esignal. Can someone help code this in NT 6.5?
_______________________________________
Title: Sine Weighted MA for eSignal 7.x
By: Chris D. Kryza (Divergence Software, Inc.)
Email: [email protected]
Incept: 02/17/2004
Version: 1.0.0
================================================== ===================
Fix History:
02/17/2004 - Initial Release
1.0.0
================================================== ===================
Project Description:
Sine Weighted Moving Average plot.
Dislaimer: For educational purposes only! Obviously, no guarantees
whatsoever and use at your own risk.
************************************************** ********************/
//External Variables
var nBarCounter = 0;
var nFac = null;
var nVal2 = null;
var aFPArray = new Array();
var bInitialized = false;
//== PreMain function required by eSignal to set things up
function preMain() {
var x;
setPriceStudy(true);
setStudyTitle("Sine Weighted MA");
setCursorLabelName("SineMA", 0);
setDefaultBarFgColor( Color.blue, 0 );
setShowTitleParameters( false );
//initialize formula parameters
x=0;
aFPArray[x] = new FunctionParameter( "Period", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 2 );
setUpperLimit( 125 );
setDefault( 15 );
}
x++;
aFPArray[x] = new FunctionParameter( "Price", FunctionParameter.STRING);
with( aFPArray[x] ) {
addOption( "Close" );
addOption( "HL/2" );
addOption( "HLC/3" );
addOption( "OHLC/4" );
addOption( "High" );
addOption( "Low" );
setDefault( "Close" );
}
x++;
aFPArray[x] = new FunctionParameter( "Color", FunctionParameter.COLOR);
with( aFPArray[x] ) {
setDefault( Color.blue );
}
x++;
aFPArray[x] = new FunctionParameter( "Thickness", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 10 );
setDefault( 2 );
}
}
//== Main processing function
function main( Period, Price, Color, Thickness ) {
var x;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
if ( bInitialized == false ) {
setDefaultBarFgColor( Color, 0 );
setDefaultBarThickness( Math.round( Thickness ), 0 );
nFac = Math.PI / ( Period+1 );
nVal2 = 0;
//calculate the denominator. This won't change
for ( x=0; x<Math.round(Period); x++ ) {
nVal2 += Math.sin( (x+1) * nFac );
}
bInitialized = true;
}
//called on each new bar
if ( getBarState() == BARSTATE_NEWBAR ) {
nBarCounter++;
}
nVal1 = 0;
nMax = Math.round( Period );
for ( x=0; x<nMax; x++ ) {
nVal1 += Math.sin( (x+1) * nFac ) * getPrice( Price, x );
}
nPlot = nVal1/nVal2;
return( nPlot );
}
/*************************************************
SUPPORT FUNCTIONS
**************************************************/
//== gID function assigns unique identifier to graphic/text routines
function gID() {
grID ++;
return( grID );
}
//== return price type selected by user
function getPrice( Price, nOffset ) {
if ( Price == "Close" ) {
return( close(-nOffset ) );
}
else if ( Price == "HL/2" ) {
return( (high(-nOffset)+low(-nOffset)) / 2 );
}
else if ( Price == "HLC/3" ) {
return( (high(-nOffset)+low(-nOffset)+close(-nOffset)) / 3 );
}
else if ( Price == "OHLC/4" ) {
return( (open(-nOffset)+high(-nOffset)+low(-nOffset)+close(-nOffset)) / 4 );
}
else if ( Price == "Low" ) {
return( low(-nOffset) );
}
else if ( Price == "High" ) {
return( high(-nOffset) );
}
}
__________________________
Thanks much
Sam
Comment