• Australian (ASX) Stock Market Forum

Hello and welcome to Aussie Stock Forums!

To gain full access you must register. Registration is free and takes only a few seconds to complete.

Already a member? Log in here.

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

Discussion in 'Software and Data' started by BomKem, Jun 21, 2020.

  1. BomKem

    BomKem

    Posts:
    2
    Likes Received:
    2
    Joined:
    Jun 21, 2020
    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==================
     
  2. Trav.

    Trav.

    Posts:
    886
    Likes Received:
    1,297
    Joined:
    Nov 27, 2017
    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.pngupload_2020-6-21_19-20-41.png

    Cheers
     
  3. BomKem

    BomKem

    Posts:
    2
    Likes Received:
    2
    Joined:
    Jun 21, 2020
    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
     
    Skate and rnr like this.
Loading...

Share This Page