Australian (ASX) Stock Market Forum

Amibroker AFL colors the Price (red or green) depends on yesterday Price

Joined
21 June 2020
Posts
2
Reactions
2
Hello,
I tried to use the If....else...statement to for the DD variable in the below code to change of current price to either red or green depends on its current value to yesterday closing price. However, it have no luck so far. The below is a piece of code that I tried to work on.

Will you please take a look at it and provide me some guidance or hints to accomplish what I want to do?

Thanks in advance.
BK
//===============AFL Code==================

_SECTION_BEGIN("Magnified Market Price");
x=Status("pxchartright");
y=Status("pxcharttop");
x1=Status("pxcharleft");
FS=Param("Font Size",35,11,100,1);
GfxSelectFont("Times New Roman", 34, 700, italic = True, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorCustom9) );
Hor=Param("Horizontal Position",234,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut(""+C,x-110 , y-15 );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 14, 700, italic =True, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorCustom9) );
GfxTextOut(""+DD+" ("+xx+"%)", x-110, y+40 );
GfxSelectFont("arial", 18 );
_SECTION_END();

//===============End Code==================
 
Welcome to ASF @BomKem

Interesting problem you have and I have googled a solution for you.

https://www.traderji.com/community/threads/ab-gfxsettextcolor-help-please.22494/

The user KelvinHand provided some code which I have borrowed 6 lines and butchered up to help find a solution for you

Code:
//===============AFL Code==================

_SECTION_BEGIN("Magnified Market Price");
x=Status("pxchartright");
y=Status("pxcharttop");
x1=Status("pxcharleft");
FS=Param("Font Size",35,11,100,1);
YC= TimeFrameGetPrice("C",inDaily,-1);
DD = Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 34, 700, italic = True, underline = False, True );
GfxSetBkMode( colorWhite );

//************ https://www.traderji.com/community/threads/ab-gfxsettextcolor-help-please.22494/
bi = BarIndex();
ii = SelectedValue( bi ) - bi[ 0 ];
iii = SelectedValue( bi ) - bi[ 1 ];
if (C[ii] >= C[iii])
GfxSetTextColor(colorbrightGreen);
else
GfxSetTextColor(colorRed);
//************

Hor=Param("Horizontal Position",234,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut(""+C,x-110 , y-15 );
GfxSelectFont("Times New Roman", 14, 700, italic =True, underline = False, True );
GfxSetBkMode( colorWhite );
GfxTextOut(""+DD+" ("+xx+"%)", x-110, y+40 );
GfxSelectFont("arial", 18 );
_SECTION_END();

//===============End Code==================

This should produce the following for you.

upload_2020-6-21_19-20-26.png upload_2020-6-21_19-20-41.png

Cheers
 
Hey Trav. (Hawks) - Very much appreciate your prompt response on the post. Your modified code (including KelvinHand lines of code) works like a charm. It actually accomplished what I wanted to show on the chart!.
Look back at the original code, to my understanding, the below function has to be removed in order to toggle the color change when if condition is met.

Code:
GfxSetTextColor(ParamColor("Color",colorCustom9) );

Again - thank you very much for your lending hands my man! Probably I will bug you again when time comes :)

Peace!
Bomkem
 
Top