Vertical shapes across various indicators

Hi

is it possible to draw e.g. rectangular shapes like in the attached picture accross different indicators in the same sheet?

Thank you very much for your support!

Kind regards,

Kurt

(lVertical%20rectangulars

Hello

One way to do this is with GFX functions

Below are 2 afl.... ready made to use

  1. Column Cursor A.afl you must have it in ONLY one chart, lets say the top chart with candlesticks

  2. Column Cursor Β.afl you must insert to the bottom charts with the indicators.

Please read how to make an Include afl. To make your life easier

you can find more GFX examples http://www.amibroker.org/userkb/

_SECTION_BEGIN("GFXColumn Cursor A");   
// Column Cursor A.afl  you must have it in ONLY one chart, lets say the top chart with candlesticks
// by Herman 11/2010
// Formula contain 2 afl , "Column Cursor A.afl" και  "Column Cursor Β.afl "
// 
ShowColumnCursor  = ParamToggle( "Column Cursor", "OFF|ON", 0 );
pxCursor = GetCursorXPosition( 1 );
StaticVarSet( "~MainPxCursor", pxcursor );
if( ShowColumnCursor ) 
{
    if( pxcursor )
    {
    pxChartbottom = Status( "pxchartbottom" );
    pxcharttop = Status( "pxcharttop" );
    Wpx = 30 ;
    CPx = Min( Status( "pxchartwidth" )-30, Max( Status("pxchartleft") + WPx, PxCursor ) );
    GfxSetOverlayMode( 1 );
    GfxSelectSolidBrush( colorYellow );
    GfxSelectPen( colorYellow, 1 );
    x1 = Cpx - Wpx;                                 StaticVarSet( "ColCurX1", x1 );
    y1 = pxcharttop;                                StaticVarSet( "ColCurY1", y1 );
    x2 = CPx + Wpx;                                StaticVarSet( "ColCurX2", x2 );
    y2 = pxchartbottom + 1;         StaticVarSet( "ColCury2", y2 );
    GfxRectangle( x1, y1, x2, y2 );
    }
    RequestMouseMoveRefresh();
}
_SECTION_END();

second part

_SECTION_BEGIN("GFXColumn Cursor Β");
// Drag & Drop second part  
//Paste this code at the bottom of all other panes, in the same window:

if( StaticVarGet( "~MainPxCursor") )  
{
    x1 = Nz( StaticVarGet( "ColCurX1" ));
    y1 = Nz( StaticVarGet( "ColCurY1" ));
    x2 = Nz( StaticVarGet( "ColCurX2" ));
    y2 = Nz( StaticVarGet( "ColCurY2" ));
    GfxSetOverlayMode( 1 );
    GfxSelectSolidBrush( colorYellow );
    GfxSelectPen( colorYellow, 1 );
    GfxRectangle( x1, y1, x2, y2 );
    RequestTimedRefresh( 0.1 );
}

_SECTION_END();

Note: RequestMouseMoveRefresh() is a new function (AFL 4.30)

2 Likes

Hi PanoS

thank you for the quick reply. I'm currently using Amibroker professional Edition (64-bit) Version 6.20.1 Build Feb 17 2017. This version does not know the function RequestMouseMoveRefresh(). The syntax check on the first include therefore gives the error: "Error 30 - Syntax error, identifier RequestMouseMoveRefresh() is undefined".

Could you please advice. Thanks!

Kind regards,

Kurt

hello
Ok then, Just replace the lines RequestMouseMoveRefresh();
with RequestTimedRefresh( 1 );

1 Like

@Panos - you know I like you :slight_smile: but frankly I see no point in using these AFL's in this case. Why use such CPU demanding codes (refreshing all panes at least 10 times per second) only to draw a rectangle following a mouse position in all panes when instead you can use:

  1. Mouse Crosshair (Ctrl + H)
  2. Selected value (click)
  3. Begin value (first double click or F12)
  4. End value (second double click or Shift + F12)

Without any coding and without straining the CPU?

1

2 Likes

@Milosz. thank you for the correction

But he ask for “rectangular shapes” that’s why I gave this example solution (many people they still donot know of how to Gfx and static vars)

Yes what you said is true, and I bet he knows your answer. I mean the way how you describe it.
Also there is one more way and maybe he likes this is How to fill background between hand-drawn trend lines

One more Note for the example code by Herman That I provide on post 2

@Kurt if you like to use it please just DELETE the lines RequestMouseMoveRefresh(); and RequestTimedRefresh( 1 );
and the example code will still run and NOT straining the CPU

1 Like

@Milosz, @Panos - thank you both for your support! Unfortunately, both solutions are not quite what I'm looking for: I would like to be able to highlight several areas in a sheet at the same time (as shown in my print screen). For documentation purposes, I would also like to be able to save this sheet, including the highlighted areas - just like I can do that within one chart or indicator. Do you see any option how I can achieve this? Thanks.

Kind regards,
Kurt

if you know how to use statickvariables i am 100% sure you can use this examble

How to fill background between hand-drawn trend lines

2 Likes

@Kurt everything can be coded, but requires time and effort.

The simplest and the easiest way is drawing these rectangles manually. Remember that you can also copy and paste such objects - for this reasons it doesn't require much work. You draw such rectangle (in each pane) once and copy it (Ctrl + C, Ctrl + V) as many times as you like. See here:

Manually drawn rectangles (or copied) meet all your criteria.

2 Likes

Modifying @Milosz code and @Herman concept....
to plot vertical line use Left Mouse click & ctrl.
code 1

_SECTION_BEGIN("GFXColumn Cursor A");
//  --- Milosz Mazurkiewicz Code--- edit by @Fossil

Title = " Ctrl + Left Mouse Button on chart --> Select/Clear selected spots    |   Ctrl + Left Mouse Button on the right axis area --> Delete all spots";
LookBackPeriod = 500;
SetBarsRequired( LookBackPeriod );

IdSet = Name() + Interval() + GetChartID();
ConditionArray = Nz( StaticVarGet( "ConditionArray" + IdSet ) );

bi = BarIndex();

MouseButtonPressed = GetCursorMouseButtons();
CtrlPressed =  GetAsyncKeyState( 17 ) < 0 ;
x = GetCursorXPosition( 0 );
y = GetCursorYPosition( 0 );

if( CtrlPressed )
{
    x = LastValue( ValueWhen( x == DateTime(), bi ) );
    
    if( MouseButtonPressed & 8 )
    {
        if( x == 0 AND IsEmpty( y ) )
            ConditionArray = 0;
        else if( ConditionArray[x] )
            ConditionArray[x] = 0;
        else
            ConditionArray[x] = 1;
        StaticVarSet( "ConditionArray" + IdSet, ConditionArray, persist = False );
    }
}

Plot( ConditionArray, "", colorBlue, styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, 0, -60 );

ClickBar = ValueWhen(ConditionArray,bi);
StaticVarSet( "~MainPxCursor", ClickBar );

Plot( C, "C", colorDefault, styleCandle );

_SECTION_END();

Code 2

_SECTION_BEGIN("GFXColumn Cursor B");

LookBackPeriod = 500;
SetBarsRequired( LookBackPeriod );

barNo = BarIndex();
x1 = Nz( StaticVarGet( "~MainPxCursor" ));
x2 = IIf(barNo == x1, barNo, Null);

Plot( x2, "", colorBlue, styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, 0, -60 );
RequestTimedRefresh( 1 );

_SECTION_END();
1 Like

Code 2 ...trim

_SECTION_BEGIN("GFXColumn Cursor B");
LookBackPeriod = 500;
SetBarsRequired( LookBackPeriod );

barNo=BarIndex();
x1 = Nz( StaticVarGet( "~MainPxCursor" ));
Plot( barNo == x1, "", colorBlue, styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, 0, -60 );
_SECTION_END();

Vertical%20Line

4 Likes