Insert pixels between last bar of a day and start bar of the next (X-axis)

Good morning,

Got stuck with a thought!

If I go with GfxSetOverlayMode(2), how to construct a dynamic X-Y axis identical to that of a chart overlay? Also, please shed some light on auto-scaling aspect of these custom-made axes?

Having said that, can we insert space between last bar of a day and start bar of the next (both on chart and X-axis) with SetChartOptions(2, chartShowDates) and GfxSetOverlayMode(0 or 1)?

Please help…

In low-level graphics, Status(“pxwidth”) and Status(“pxheight”) will give you the pixel width and height of the chart pane. From there you can work out where you want to draw your axes using the Gfx command set. Bear in mind in low-level graphics the origin is the top left, not the bottom left as you might expect.

Ref: https://www.amibroker.com/guide/afl/status.html

I’m not sure if your other query is possible.

Thank you very much for the information ! That helps …

If I may request, could you kindly share any reference AFL that shows how to display DateTime in the X-axis with auto-scaling (identical to that of a Price chart overlay).

Have a look here, lots of good examples:
http://www.amibroker.com/kb/index.php?s=low+level+graphics

Thanks @HelixTrader,

Before I go ahead and start manipulating the X-axis. I was wondering on how to replicate the price chart using GfxSetOverlayMode(2)?

Warm appreciation to @Tomasz. It is quite well possible using, GfxSetOverlayMode(0) and GfxSetOverlayMode(1). But I cannot get my head around on how to do it using GfxSetOverlayMode(2) and GfxSetCoordsMode(0).

Once I have the control over the pixels, I imagine to increase the number to space between a set of drawn bars (representing different time-frames), then, use that space to populate different mini-charts for instance VAP histograms and others. And put it in a loop to exhibit a regular repetition.

For example in C#.Net (below code) we can draw a line from (0,0) to (1,1) pretty easily using the DpiX property of the Graphics class "in dots per inch", for the horizontal resolution supported by the Graphics object. But how to replicate the same in AFL (in terms of co-ordinates)?

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Example1_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.BackColor = Color.LightBlue;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.PageUnit = GraphicsUnit.Inch;
            Pen blackPen = new Pen(Color.Black, 1 / g.DpiX);
            g.DrawLine(blackPen, 0, 0, 1, 1);
        }
    }
}

Output:

Hi there
Lennon
i think is worth to start with this example afl here,
this example can show you, most of what you looking for.
yes i know is old afl without the GfxSetOverlayMode function but i really beleave will teach you few thinks

thanks
Panos

1 Like

Drawing a straight line is pretty simple via GfxMoveTo and GfxLineTo

procedure GfxDrawSomeLine( x1, y1, x2, y2, color, style, width, bkmode ) {
	GfxSelectPen( color, width, style );
	GfxSetBkMode( bkmode );

	GfxMoveTo( x1, y1 );
	GfxLineTo( x2, y2 ); 
}

Title = "";
Plot( C, "Price", colorDefault, styleCandle );


// Note: If NOT calling GfxSetCoordsMode then default mode is GfxSetCoordsMode(0) -> pixel mode


// FIRST EXAMPLE #####################################
GfxDrawSomeLine( 0, 0, 100, 100, colorRed, 0, 1, 1 );


// SECOND EXAMPLE #####################################
bi = BarIndex();
fvb = FirstVisibleValue( bi );

GfxSetCoordsMode( 1 );
/// @link https://www.amibroker.com/guide/afl/gfxsetcoordsmode.html

GfxDrawSomeLine( fvb, C[fvb], fvb+10, C[fvb]+ 50*TickSize, colorOrange, 0, 1, 1 );

GfxSetOverlayMode is old z-order function which got improved by more flexible new function GfxSetZOrder.

4 Likes

In AFL, it is way easier and way shorter than in C#.

GfxSetOverlayMode( 2 );
GfxSelectPen( colorRed );
GfxMoveTo( 20, 20 );
GfxLineTo( 100, 100 );

Coordinates are in physical (screen) pixels.

1 Like

Thank you very much @phutch for creating this masterpiece!
Thank you @PanoS for sharing! I have a base to study now.

Shall ever remain indebted!

“The farther back you can look, the farther forward you are likely to see.” -Churchill