[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Converting Trade Station Code?



PureBytes Links

Trading Reference Links

Just wondering if there is an easy way to convert Trade Station code
into AFL language?

I've struggled through some programming but this one is beyond me.

Any help would be appreciated.

Thanks, Randy

This is the script I have (permission has been granted to use it):

/********************************************************************
Title:		Value Chart Indicator Script for eSignal 7.x
By:         Chris D. Kryza (Divergence Software, Inc.)
Email:      c.kryza@xxxxxxx
Incept:     09/26/2003
Version:    1.0.0


=====================================================================
Fix History:

09/26/2003 -   Initial Release
1.0.0

=====================================================================
Project Description:   

David Stenhahl's Value Chart Indicator. From the book "Dynamic
Trading Indicators" by Mark Helweg and David Stendahl.

If you come across any fixes or have any ideas on how to spruce it up, I
would appreciate it if you would let me know (c.kryza@xxxxxxx).

Dislaimer: For educational purposes only! Obviously, no guarantees 
whatsoever and use at your own risk.

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


//Global Variables
var grID                = 0;
var nBarCounter			= 0;
var aFPArray			= new Array();
var aArray				= new Array();
var nVarP				= null;
var bInitialized		= false;
var nTotalBars			= null;
var nMaxBars			= 200;

var nStudyMin			= -12;
var nStudyMax			=  12;


//== PreMain function required by eSignal to set things up
function preMain() {
var x;

    setPriceStudy(false);
    setStudyTitle("Value Chart");
    
    addBand(  8, PS_SOLID, 1, Color.red,  -10 );
    addBand(  4, PS_SOLID, 1, Color.teal, -11 );
    addBand( -4, PS_SOLID, 1, Color.teal, -12 );
    addBand( -8, PS_SOLID, 1, Color.red,  -13 );            

	//unrem this if you don't want the labels in cursor window
    setShowCursorLabel(false);
    
    setStudyMin( nStudyMin );
    setStudyMax( nStudyMax );
    
    setComputeOnClose();
    grID = 0;
    
    //initialize formula parameters
	x=0; 
	aFPArray[x] = new FunctionParameter( "NumBars",
FunctionParameter.NUMBER);
	with( aFPArray[x] ) {
		setName( "Input: Bars" );
		setLowerLimit( 2 );
		setUpperLimit( 1000 );
		setDefault( 5 );
	}  
	x++;
	aFPArray[x] = new FunctionParameter( "MaxToDraw",
FunctionParameter.NUMBER);
	with( aFPArray[x] ) {
		setName( "Max Bars to Draw" );
		setLowerLimit( 20 );
		setUpperLimit( 5000 );
		setDefault( 100 );
	}  

	for ( x=0; x<50; x++ ) {
		aArray[x] = 0.0;
	}

}

//== Main processing function
function main( NumBars, MaxToDraw ) {
var x;
var nVarA;
var nVarB;
var nVarC;
var nVarD;
var nVarE;
var nVarR1;
var nVarR2;
var nVarR3;
var nVarR4;
var nVarR5;
var nVarR0;
var nOpen, nHigh, nLow, nClose;
	
	//script is initializing
    if ( getBarState() == BARSTATE_ALLBARS ) {
        return null;
    }

	if ( bInitialized == false ) {
		nVarP = Math.round( NumBars/5 );
		nMaxBars = MaxToDraw*3;
		nMaxBars += (nMaxBars % 3)-1;
		nTotalBars = getNumBars();
		bInitialized = true;
	}

	//called on each new bar
	if ( getBarState() == BARSTATE_NEWBAR ) {
	
		aArray.pop();
		aArray.unshift(0);
	
		nBarCounter++;
		
	}

	if ( nBarCounter < (nTotalBars-(nMaxBars/3))-10 ) return;


	if ( NumBars > 7 ) {
		nVarA = Highest( nVarP, 0 ) - Lowest( nVarP, 0 );
		if ( nVarA == 0 && nVarP ==1 ) 
			nVarR1 = Math.abs( close()-close(-nVarP) );
		else
			nVarR1 = nVarA;
			
		nVarB = Highest( nVarP, nVarP+1 ) - Lowest( nVarP, nVarP );
		if ( nVarB == 0 && nVarP==1 )
			nVarR2 = Math.abs( close(-nVarP)-close(-(nVarP*2)));
		else
			nVarR2 = nVarB;
			
		nVarC = Highest( nVarP, nVarP*2 ) - Lowest( nVarP, nVarP*2 );
		if ( nVarC == 0 && nVarP==1 )
			nVarR3 = Math.abs( close(-(nVarP*2))-close(-(nVarP*3)));
		else
			nVarR3 = nVarC;

		nVarD = Highest( nVarP, nVarP*3 ) - Lowest( nVarP, nVarP*3 );
		if ( nVarD == 0 && nVarP==1 )
			nVarR4 = Math.abs( close(-(nVarP*3))-close(-(nVarP*4)));
		else
			nVarR4 = nVarD;
		
		nVarE = Highest( nVarP, nVarP*4 ) - Lowest( nVarP, nVarP*4 );
		if ( nVarE == 0 && nVarP==1 )
			nVarR5 = Math.abs( close(-(nVarP*4))-close(-(nVarP*5)));
		else
			nVarR5 = nVarE;
		
		nLRange = ( ( nVarR1 + nVarR2 + nVarR3 + nVarR4 + nVarR5 ) / 5 ) * 0.20;
	}
	else {
		if ( Math.abs( close()-close(-1) ) > (high()-low())) 
			nVar0 = Math.abs( close()-close(-1) );
		else
			nVar0 = high()-low();
			
		if ( high()==low() )
			nVar0 = Math.abs( close()-close(-1) );
			
		aArray[0] = nVar0;
			
		nLRange = Average( aArray, 5 ) * 0.20;
	}
		
		
	if ( nLRange <= 0 ) return;
	
	nOpen  = (  open() - HLAverage( NumBars ) ) / nLRange;
	nHigh  = (  high() - HLAverage( NumBars ) ) / nLRange;
	nLow   = (   low() - HLAverage( NumBars ) ) / nLRange;
	nClose = ( close() - HLAverage( NumBars ) ) / nLRange;	
	
	//adjust study window height, as necessary
	if ( nBarCounter > (nTotalBars-(nMaxBars/3))) {
		if ( nHigh > nStudyMax ) {
			nStudyMax = nHigh;
			setStudyMax( nStudyMax );
		}
		if ( nLow < nStudyMin ) {
			nStudyMin = nLow;
			setStudyMin( nStudyMin );
		}
	}		
		
	//draw the OHLC bar in the study window		
	drawBar( nOpen, nHigh, nLow, nClose );


}


/*************************************************
             SUPPORT FUNCTIONS                    
**************************************************/   

function drawBar( nO, nH, nL, nC ) {

	drawLineRelative( 0, nL, 0, nH, PS_SOLID, 3, Color.navy, gID() );
	drawLineRelative( 0, nO, 0, nO, PS_SOLID, 5, Color.lime, gID() );
	drawLineRelative( 0, nC, 0, nC, PS_SOLID, 5, Color.red, gID() );	
	
}
	

function HLAverage( nBars ) {
var x = 0;
var nTmp = 0;

	while ( x<nBars ) {
		nTmp += ( high(-x) + low(-x) ) / 2;
		x++;
	}
	
	return( nTmp/nBars );
	
}    
 
    
function Average( Arr, nBars ) {
var x = 0;
var nTmp = 0;

	while ( x<nBars ) {
		nTmp += Arr[x];
		x++;
	}
	
	return( nTmp/nBars );
	
}    
    
function Highest( nBars, nOffset ) {
var x = nOffset;
var nTmp = -9999999999.0;

	while ( x<nBars+nOffset ) {
		nTmp = Math.max( nTmp, high(-(x)) );
		x++;
	}
	
	return( nTmp );
	
}    

function Lowest( nBars, nOffset ) {
var x = nOffset;
var nTmp = 9999999999.0;

	while ( x<nBars+nOffset ) {
		nTmp = Math.min( nTmp, low(-(x)) );
		x++;
	}
	
	return( nTmp );
	
}    

    
//== gID function assigns unique identifier to graphic/text routines
function gID() {
    grID ++;
    if ( grID>nMaxBars ) grID = 0;
    return( grID );
}






Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/