PureBytes Links
Trading Reference Links
|
There is a esignal.efs code for square of nine lines and text to show
on the charts, has anyone revised this code for ami and might be
willing to share it?
this shows an example of a screen shot
http://share.esignal.com/groupcontents.jsp?folder=Square%20of%
209&picture=SquareOf9.png&groupid=114
//Button vertical offset
var nBase = 13;
var nFont = 10;
//Global Variables
var grID = 0;
var nStatus = 0;
var nBarCounter = 0;
var nPoint1 = null;
var nValue1 = null;
var nBaseInc = 0;
var aFPArray = new Array();
var bInitialized = false;
var bNormalize = true;
var bFreeform = false;
var txtFlags = Text.ONTOP | Text.RELATIVETOLEFT |
Text.RELATIVETOBOTTOM;
//== PreMain function required by eSignal to set things up
function preMain() {
var x;
setPriceStudy(true);
setStudyTitle("Square of 9");
setShowCursorLabel(false);
setShowTitleParameters( false );
x=0;
aFPArray[x] = new FunctionParameter( "fNormalize",
FunctionParameter.STRING);
with( aFPArray[x] ) {
setName( "Normalize Prices?" );
addOption( "T" );
addOption( "F" );
setDefault( "F" );
}
x++;
aFPArray[x] = new FunctionParameter( "fDegree",
FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setName( "Degree Increment" );
setLowerLimit( 1 );
setUpperLimit( 360 );
setDefault( 22.50 );
}
x++;
aFPArray[x] = new FunctionParameter( "fType",
FunctionParameter.STRING);
with( aFPArray[x] ) {
setName( "Type?" );
addOption( "Anchor on Price" );
addOption( "Freeform" );
setDefault( "Anchor on Price" );
}
grID = 0;
}
//== Main processing function
function main( fNormalize, fDegree, fType ) {
var x;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
if ( bInitialized == false ) {
bNormalize = fNormalize=="T";
bFreeform = fType=="Freeform";
nBaseInc = fDegree;
bInitialized = true;
}
//reset sequential counter on each new day
if ( getBarState() == BARSTATE_NEWBAR ) {
if ( nPoint1 != null ) {
nPoint1++;
}
nBarCounter++;
}
else {
return;
}
if ( nPoint1 != null ) {
clearLines();
clearText();
grID=0;
plotSquare( nPoint1, nValue1 );
}
if ( isLastBarOnChart() ) {
doMenu();
}
}
/*************************************************
SUPPORT FUNCTIONS
************************************************** /
//== draw the menu button
function doMenu() {
drawTextPixel(2, nBase, " Square-of-9 @URL=EFS:Step1", Color.black,
Color.aqua, txtFlags | Text.FRAME , "Arial", nFont, -56 );
}
//== draw the square of 9 levels based on selected anchor point
function plotSquare( nOffset, nValue ) {
var x = 0;
var nNorm = 1;
var nInc = nBaseInc;
var nBase = null;
var nVal1 = null;
var nVal2 = null;
var sTxt1 = null;
var sTxt2 = null;
var nColor1 = Color.maroon;
var nColor2 = Color.blue;
var nColor3 = Color.black;
drawLineRelative( -nOffset, nValue, 0, nValue, PS_SOLID, 2, nColor1,
gID() );
sTxt1 = " "+"0.00" + "° " + formatPriceNumber( nValue );
drawTextRelative( 2, nValue, sTxt1, nColor2, null, Text.VCENTER |
Text.BOLD | Text.ONTOP, null, 10, gID() );
if ( bNormalize==true ) {
nA = nValue;
if (nA>1000) {
while(1==1) {
nA = nA/10;
nNorm*=10;
if (nA<1000) break;
}
}
else if (nA<100) {
while(1==1) {
nA = nA*10;
nNorm/=10;
if (nA>=100) break;
}
}
nValue = nA;
}
nBase = Math.sqrt( nValue );
while ( x<16 ) {
nVal1 = Math.pow( ( nBase + nInc/180 ), 2 ) * nNorm;
nVal2 = Math.pow( ( nBase - nInc/180 ), 2 ) * nNorm;
sTxt1 = "+"+nInc.toFixed(2) + "° " + formatPriceNumber( nVal1 );
sTxt2 = "-"+nInc.toFixed(2) + "° " + formatPriceNumber( nVal2 );
drawLineRelative( -nOffset, nVal1, 0, nVal1, PS_SOLID, 2, nColor2, gID
() );
drawTextRelative( 2, nVal1, sTxt1, nColor3, null, Text.VCENTER |
Text.BOLD | Text.ONTOP, null, 10, gID() );
drawLineRelative( -nOffset, nVal2, 0, nVal2, PS_SOLID, 2, nColor2, gID
() );
drawTextRelative( 2, nVal2, sTxt2, nColor3, null, Text.VCENTER |
Text.BOLD | Text.ONTOP, null, 10, gID() );
nInc += nBaseInc;
x++;
}
}
//== event handler for left-mouse double-click
function onLButtonDblClk( barIndex, yValue) {
var nMid;
if ( nStatus==0 ) return;
nBuffer = close(barIndex) * 0.004;
//user double-clicks on first bar in range
if ( nStatus==1 ) {
if ( bFreeform==false ) {
if ( yValue>=low(barIndex)-nBuffer && yValue<=high(barIndex)
+nBuffer ) {
nMid = (low(barIndex)+high(barIndex))/2;
nPoint1 = Math.abs( barIndex );
if ( yValue<=nMid ) {
nValue1 = low(barIndex);
}
else {
nValue1 = high(barIndex);
}
plotSquare( nPoint1, nValue1 );
doMenu();
nStatus=0;
}
}
else {
nPoint1 = Math.abs( barIndex );
nValue1 = yValue;
plotSquare( nPoint1, nValue1 );
doMenu();
nStatus=0;
}
}
}
//== function determines if a button was pressed
function getButtonPressed(nButtonPressed) {
if(nButtonPressed == BUTTON_LEFT) {
return(1);
}
else {
return(0);
}
}
//== prompt user to double-click on anchor point
function Step1( nButtonPressed ) {
if ( getButtonPressed( nButtonPressed ) == 1 ) {
clearLines();
clearText();
nPoint1 = null;
nValue1 = null;
nStatus=1;
drawTextPixel(0, nBase, " Double-Click on Anchor Point for Square of
9...", Color.navy, null, txtFlags , "Arial", 11, -56);
}
return;
}
//== gID function assigns unique identifier to graphic/text routines
function gID() {
grID ++;
return( grID );
}
Thanks
------------------------ Yahoo! Groups Sponsor --------------------~-->
Try Online Currency Trading with GFT. Free 50K Demo. Trade
24 Hours. Commission-Free.
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~->
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 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/
<*> 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/
|