Need help - trying to semi automate

augubhai

Well-Known Member
#1
How to I create a gfx button (rectangle) after the last bar on the chart, like in the GDFL NEST plugin? (screenshot below)

In the GDFL NEST plugin, the buttons appear after the last bar. The buttons are not at fixed pixels - they always appear after the last bar. When Amibroker is opened, these buttons are not visible in the chart. To see them the END key has to be clicked a couple of times, to see more blank area after the last bar.

Any solutions?

I am just searching the net, and one probable clue is http://www.amibroker.com/kb/2009/03/30/how-to-convert-from-bar-value-to-pixel-co-ordinates/

 

augubhai

Well-Known Member
#5
For anyone that might be interested, here is the code so far. It is just the UI part... and it is customized to my requirement.

I have not yet looked into the code that will actually call NOW/Nest. Still have time. I still have to be migrated to Nest (by RKSV), and am not even currently subscribed to Nest Plus AT. So, I'll look into that part next week.

Code:
//SetOption("RequireDeclarations", True ); 

procedure kStaticVarSet( SName, SValue ) 	{ StaticVarSet("158"+Sname+GetChartID()+Name()+Interval(), Svalue); }
function kStaticVarGet( SName ) { 	return StaticVarGet("158"+Sname+GetChartID()+Name()+Interval());	}

procedure DrawButton( Text, x1, y1, x2, y2, BackColor, TextColor )
{
    GfxSetOverlayMode( 0 );
    GfxSelectFont( "Tahoma", 12, 800 );
    GfxSelectPen( colorBlack );
    GfxSetBkMode( 1 );
    GfxSelectSolidBrush( BackColor );
    GfxSetBkColor( BackColor );
    GfxSetTextColor( TextColor );
    GfxRectangle( x1, y1, x2, y2 );
    GfxDrawText( Text, x1, y1, x2, y2, 32 | 1 | 4 );
}

ButtonX0 = 80;//offset from right
ButtonWidth = 80;
ButtonHeight = 40;
ButtonX1=Status("pxwidth")-ButtonX0-ButtonWidth;
ButtonX2=Status("pxwidth")-ButtonX0;

armButtonLabel = "ERROR";
armButtonY1 = 20;
armButtonBackColor = colorWhite;
armButtonTextColor = colorBlack;

longButtonLabel = "LONG";
longButtonY1 = 80;
longButtonBackColor = colorWhite;
longButtonTextColor = colorLightGrey;

flatButtonLabel = "FLAT";
flatButtonY1 = 120;
flatButtonBackColor = colorYellow;
flatButtonTextColor = colorBlack;

shortButtonLabel = "SHORT";
shortButtonY1 = 160;
shortButtonBackColor = colorWhite;
shortButtonTextColor = colorLightGrey;

LButtonTrigger	= GetCursorMouseButtons() == 9;
MousePx  = Nz( GetCursorXPosition( 1 ) );
MousePy  = Nz( GetCursorYPosition( 1 ) );
 
CursorInArmButton = MousePx > ButtonX1 AND MousePx < ButtonX2 AND MousePy > armButtonY1 AND MousePy < (armButtonY1+ButtonWidth);
CursorInLongButton = MousePx > ButtonX1 AND MousePx < ButtonX2 AND MousePy > longButtonY1 AND MousePy < (longButtonY1+ButtonWidth);
CursorInFlatButton = MousePx > ButtonX1 AND MousePx < ButtonX2 AND MousePy > flatButtonY1 AND MousePy < (flatButtonY1+ButtonWidth);
CursorInShortButton = MousePx > ButtonX1 AND MousePx < ButtonX2 AND MousePy > shortButtonY1 AND MousePy < (shortButtonY1+ButtonWidth);

if ( LButtonTrigger )
{
	switch(Nz(kStaticVarGet("zState")))
	{
		case 1: // FLAT
			if ( CursorInArmButton ) kStaticVarSet("zState",0);
			if ( CursorInLongButton ) kStaticVarSet("zState",2);
			if ( CursorInShortButton ) kStaticVarSet("zState",3);
		break;
		case 2: // LONG
			if ( CursorInArmButton ) kStaticVarSet("zState",0);
			if ( CursorInFlatButton ) kStaticVarSet("zState",1);
			if ( CursorInShortButton ) kStaticVarSet("zState",3);
		break;
		case 3: // SHORT
			if ( CursorInArmButton ) kStaticVarSet("zState",0);
			if ( CursorInLongButton ) kStaticVarSet("zState",2);
			if ( CursorInFlatButton ) kStaticVarSet("zState",1);
		break;
		default: // DISARMED
			if ( CursorInArmButton ) kStaticVarSet("zState",1);
	}
	//Say("Apoon maalamaal ray, koi na fikar apni");
}

SetChartBkColor(colorLightGrey);

switch(Nz(kStaticVarGet("zState")))
{
		case 1: // FLAT
			armButtonLabel = "DISARM";
			armButtonBackColor = colorRed;
			longButtonBackColor = colorWhite;
			longButtonTextColor = colorLightGrey;
			flatButtonBackColor = colorYellow;
			flatButtonTextColor = colorBlack;
			shortButtonBackColor = colorWhite;
			shortButtonTextColor = colorLightGrey;
			SetChartBkGradientFill(colorBlack,colorBlack);			
		break;
		case 2: // LONG
			armButtonLabel = "DISARM";
			armButtonBackColor = colorRed;
			longButtonBackColor = colorYellow;
			longButtonTextColor = colorBlack;
			flatButtonBackColor = colorWhite;
			flatButtonTextColor = colorLightGrey;
			shortButtonBackColor = colorWhite;
			shortButtonTextColor = colorLightGrey;
			SetChartBkGradientFill(colorDarkBlue,colorDarkGreen);
		break;
		case 3: // SHORT
			armButtonLabel = "DISARM";
			armButtonBackColor = colorRed;
			longButtonBackColor = colorWhite;
			longButtonTextColor = colorLightGrey;
			flatButtonBackColor = colorWhite;
			flatButtonTextColor = colorLightGrey;
			shortButtonBackColor = colorYellow;
			shortButtonTextColor = colorBlack;
			SetChartBkGradientFill(colorDarkRed,colorDarkYellow);
		break;
		default: //DISARMED
			armButtonLabel = "ARM";
			armButtonBackColor = colorWhite;
			armButtonTextColor = colorLightGrey;
			SetChartBkGradientFill(colorWhite,colorWhite);
}

DrawButton( armButtonLabel, ButtonX1, armButtonY1, ButtonX2, armButtonY1+ButtonHeight, armButtonBackColor, armButtonTextColor );

if (Nz(kStaticVarGet("zState"))) {
	DrawButton( longButtonLabel, ButtonX1, longButtonY1, ButtonX2, longButtonY1+ButtonHeight, longButtonBackColor, longButtonTextColor );
	DrawButton( flatButtonLabel, ButtonX1, flatButtonY1, ButtonX2, flatButtonY1+ButtonHeight, flatButtonBackColor, flatButtonTextColor );
	DrawButton( shortButtonLabel, ButtonX1, shortButtonY1, ButtonX2, shortButtonY1+ButtonHeight, shortButtonBackColor, shortButtonTextColor );
}

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
zColor = IIf(C>O,colorGreen,IIf(C<O,colorOrange,colorLightGrey));
SetBarFillColor(zColor);
Plot( C, "Close", zColor, styleNoTitle | ParamStyle("Style") | GetPriceStyle() | styleNoLabel); 
_SECTION_END();
 
#6
TRY THIS


_SECTION_BEGIN("MANUAL AUTO TRADING");

// Base point - Left Up Corner
X0 = Param ("X - Left Up Corner", 800, 1, 1000, 10);
Y0 = Param ("Y - Right Up Corner", -110, -130, 350, 10);

// --- Button pressed
LBClick = GetCursorMouseButtons() == 9; // Click
MouseX = Nz(GetCursorXPosition(1)); //
MouseY = Nz(GetCursorYPosition(1)); //

// --- Button Draw
procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
GfxSetOverlayMode(0);
GfxSelectFont("Verdana", 13, 700);
GfxSetBkMode(1);
GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);
}
GfxSetTextColor(colorWhite);


// Button Sell Market
DrawBut ("SELL", X0, Y0+130, X0+70, Y0+170, colorRed, colorRed);
CursorInSMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+130 AND MouseY <= Y0+180;
SMKTPressed =CursorInSMKTBut AND LBClick ;
if ( SMKTPressed )
{
StaticVarSet ("SMKT", 1);
StaticVarSet ("BMKT", 0);
}

// Button Buy Market
DrawBut ("BUY", X0, Y0+200, X0+70, Y0+240, colorLime, colorLime);
CursorInBMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+190 AND MouseY <= Y0+240;
BMKTPressed = CursorInBMKTBut AND LBClick;
if ( BMKTPressed )
{
StaticVarSet ("SMKT", 0);
StaticVarSet ("BMKT", 1);
}

if(StaticVarGet("SMKT")==1) {DrawBut("", X0+80, Y0+130, X0+100, Y0+170, colorRed, colorRed); }// SMKT
if(StaticVarGet("BMKT")==1) {DrawBut("", X0+80, Y0+200, X0+100, Y0+240, colorLime, colorLime); }// BMKT
_SECTION_END();
 
#8
Me in need of help too

Trying to create buy sell auto analyser to help me.....I tend to forget the parameters I have in my trading system....:D
Following is the basic afl I am looking for.....I can modify it later according to my needs.....I am stuck at this point:confused:
Any help forthcoming .....Thanx in advance.......

X= (O+H+L+C)/4;
Y= EMA(X,13);
Z= EMA(X,34);

UPTREND= (Y>Z);
DOWNTREND= (Y<Z);

BUY= (Y>Z) AND CROSS(Y,Z);
SELL= (Y<Z) AND CROSS(Z,Y);




I ALREADY HAVE ONE GFX WINDOW PLOTTED AS BELOW:
GfxRoundRect( x+45, y+17, x-3, y-2, 0, 0 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 8, 700, False );
GfxSetTextColor( colorBlack );
GfxTextOut( ""+SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );




I NEED TO PLOT ONE MORE GFX SPACE ALONGSIDE THE ABOVE SPACE WITH OUTPUT AS:

BKCOLOR AS BRIGHTGREEN IF UPTREND, PINK IF DOWNTREND
TEXTOUT AS "BUY" IF BUY, "SELL" IF SELL
TEXT COLOR AS GREEN IF BUY, RED IF SELL
 
#9
Me in need of help too.....something more

How can I change the location and size of the gfx space......I mean which values in the afl need to be changed ......:)
 

augubhai

Well-Known Member
#10
Re: Me in need of help too.....something more

How can I change the location and size of the gfx space......I mean which values in the afl need to be changed ......:)
Not sure if i understood ur requirement clearly, but....

have a look at amibroker documentation
http://www.amibroker.com/guide/afl/gfxroundrect.html

the first 4 parameters in GfxRoundRect() set the location and size... just change the value and see.

For GfxTextOut(), the last 2 parameters define the location
 

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?