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

Re: [amibroker] GFX problem: lining up price plots with pixel plots



PureBytes Links

Trading Reference Links

Herman,
 
In your code you do not make adjustment for Y axis width that's why it does not work.
(pxwidth represents ENTIRE chart width in pixels including axis area)
 
See example 4 in the User's Guide:
 
It shows exactly how to align custom graphics with built-in charts.
 
I have written the sample for you that shows how to do what you were trying to do:
 
Plot(C, "Price", colorBlack, styleLine );

GfxSetOverlayMode(0);
axisarea =
Param("axisarea", 56, 30, 100 ); // may need adjustment if you are using non-default font for axis

Miny =
Status("axisminy");
Maxy =
Status("axismaxy");

lvb =
Status("lastvisiblebar");
fvb =
Status("firstvisiblebar");

pxwidth =
Status("pxwidth");
pxheight =
Status("pxheight");

TotalBars = Lvb - fvb;

function GetPixelX( Value )
{
   x =
5 + Value * (pxwidth - axisarea - 10) / ( TotalBars + 1 );
  
return x;
}

function GetPixelY( Value )
{
   y =
5 + ( Value  - Miny ) * ( pxheight - 10 )/ ( Maxy - Miny );
  
return pxheight - y;

}

function gfxPlotHLine( YPixels, Color )
{
    
global pxwidth;
    
GfxSelectPen( Color ) ;
    
GfxMoveTo( 0, YPixels );
    
GfxLineTo( pxwidth, YPixels );
}


function gfxPlotVLine( XPixels, Color )
{
    
global pxheight;
    
GfxSelectPen( Color ) ;
    
GfxMoveTo( XPixels, 0 );
    
GfxLineTo( XPixels, pxheight );
}

function GetVisualBarIndex( )
{
  bi =
BarIndex();
  
return bi - bi[ 0 ] - fvb;
}

GfxSelectSolidBrush( colorRed );
GfxSelectPen( colorRed );
for( i = 0; i < TotalBars AND i < ( BarCount - fvb ); i++ )
{
   x = GetPixelX( i );

   y = GetPixelY (
C[ i + fvb ] );

  
GfxRectangle( x - 1, y - 1, x + 2, y + 2);
}

GfxPlotHLine( GetPixelY(
SelectedValue( C ) ), colorRed );
GfxPlotVLine( GetPixelX(
SelectedValue( GetVisualBarIndex() )), colorBrightGreen  );

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: Herman
Sent: Sunday, March 02, 2008 11:15 AM
Subject: Re: [amibroker] GFX problem: lining up price plots with pixel plots

thanks Dennis, I have doe that and it works fine but doesn't lend itself for automated adjustments.


bets regards,

herman


For tips on developing Real-Time Auto-Trading systems visit:

http://www.amibroker.org/userkb/


Saturday, March 1, 2008, 8:19:34 PM, you wrote:


>

Herman,


Perhaps if you make 4 params, 2 for x axis, and 2 for y axis for -- scaling m + offset b: mx+b.

Then adjust the parameters visually in real time until they align.  Then look at the values and see if it dawns what the issue is.


Best regards,

Dennis



On Mar 1, 2008, at 5:37 PM, Herman wrote:



I just can't manage to line up pixel plots with price charts. I copy my testing code below. I need is to line up horizontal and vertical lines produced with normal charting techniques, with lines produced using GFX functions. Any help would be much appreciated!!!


Herman


function GetPixelY( value )

{

    global MinY, MaxY;

    return Status"pxheight" ) * ( value - MinY ) / ( MaxY - MinY );

}


function GetPixelX( value )

{

    global MinX, MaxX;

    return Status"pxwidth" ) * ( value - MinX ) / ( MaxX - MinX );

}


function gfxPlotHLine( YPixels, Color )

{

    global pxwidth;

    GfxSelectPen( Color ) ;

    GfxMoveTo( 0, YPixels );

    GfxLineTo( pxwidth, YPixels );

}


function gfxPlotVLine( VPixels, Color )

{

    global pxheight;

    GfxSelectPen( Color ) ;

    GfxMoveTo( 0, VPixels );

    GfxLineTo( pxHeight, VPixels );

}


GraphXSpace = 0;

PlotC"", 1, 128 );

GfxSetOverlayMode( 1 );

GfxSetBkMode( 1 );

pxwidth = Status"pxwidth" );

pxheight = Status"pxheight" );

Miny = Status"axisminy" );

Maxy = Status"axismaxy" );


// Plot selected Low in price and in pixels

Lowprice = SelectedValueLow );

Plot( Lowprice, "", 2, 1 );

LowPixels = GetPixelY( Lowprice );

gfxPlotHLine( LowPixels, colorRed );


// plot vertical line on selected bar in GFX

CumBar = CumStatus"barVisible" ) );

NumBarsVisible = LastValue( CumBar );

PixelsPerbar = pxWidth / SelectedValue( NumBarsVisible );

BarPixels = SelectedValue( NumBarsVisible ) * PixelsPerbar;

gfxPlotVLine( BarPixels, colorBrightGreen );


Title = "\n" +

        " LowPixels: " + NumToStr( LowPixels, 1.0, False ) + "\n" +

        "Pixels/Bar: " + NumToStr( PixelsPerbar, 1.0, False ) + "\n" +

        " BarPixels: " + NumToStr( BarPixels, 1.0, False );



 

__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___