[Chia sẻ] Combo Bảng giá theo ngành + Top CP + DM theo dõi + Bắn Tele cảnh báo giá + Click đổi chart

Thảo luận trong 'Bàn luận về Amibroker, Metastock, Metatrader 4' bắt đầu bởi nguyenjoe, 9/7/23.

Lượt xem : 5,024

  1. nguyenjoe

    nguyenjoe Well-Known Member

    Tham gia ngày:
    18/7/21
    Bài viết:
    93
    Đã được thích:
    166
    Giới tính:
    Nam
    Hello các bác,

    Tiếp tục update chức năng cho code Bảng giá mini kèm chức năng click đổi chart đã post ở bài trước. Lần này mình chia sẻ thêm một vài thay đổi update cho phiên bản cũ và thêm chức năng quan trọng là bắn telegram cho danh mục theo dõi.

    Do combo code này khá nhiều chức năng nên mình sẽ cần thời gian để viết hướng dẫn sử dụng chi tiết trước. Tạm post bài để thông báo và dành chỗ, các bài hướng dẫn sẽ được viết ở post tiếp theo bên dưới.

    Các chức năng chính:
    1. Bảng giá
    - Bảng giá mini hiển thị theo ngành
    - Tự động lọc và đẩy mã theo ngành vào các watchlist
    - Sắp xếp tự động theo thứ tự tăng giá giảm dần trong phiên

    upload_2023-7-9_22-19-31.png
    2. Danh mục
    - Nhập danh mục đầu tư bằng tay các giá trị Mã CP, giá mua, Cutloss, Target để theo dõi biến động. Tự động bắn Telegram cảnh báo khi giá chạm cutloss hoặc target
    - Nhập danh mục theo dõi bằng tay giá trị Mã CP và điểm pivot. Tự động bắn Telegram cảnh báo khi giá vượt điểm pivot
    - Hiển thị đường line các giá trị cutloss, target, pivot trên biểu đồ để dễ quan sát trực quan

    upload_2023-7-9_22-19-54.png
    upload_2023-7-9_22-20-20.png

    3. Top CP
    - Hiển thị tự động 6 Top cổ phiếu theo thứ tự thời gian. Có thể điều chỉnh được thời gian lọc trong parameter.
    upload_2023-7-9_22-20-40.png

    Hầu hết các code này mình tự làm phục vụ nhu cầu cá nhân để tự đầu tư và chia sẻ lại sau khi hoàn thành mà thôi nên sẽ ko tránh được ko phù hợp với nhu cầu từng người. Tuy nhiên mình cũng ko có nhiều thời gian để chỉnh sửa nên nhiều bác nhắn tin thì mình cũng ko trả lời hết được mong các bác thông cảm.

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    Một số code khác mà minh đã chia sẻ lưu lại đây để dễ tìm ////
    ///////////////////////////////////////////////////////////////////////////////////////////////////

    Cách hiển thị tên của watchlist trong explorer và trên Chart

    Thống kê số lượng mã nằm trên/dưới MA20 và cách ứng dụng

    Elder Chart: Xác định vùng nào nên tham gia

    Code RSLine cho từng mã cổ phiếu.

    Gửi tín hiệu từ Amibroker lên telegram

    Code đưa toàn bộ list vừa lọc filter sang watchlist

    [Chia sẻ] Code tự động đánh dấu pivot đỉnh đáy như MarketSmith của IBD

    [Chia sẻ] Code Volume theo phong cách Dan Zanger và Pivot Pocket Volume

    [Chia sẻ] Tặng code xem bảng giá mini + Top CP, click để thay đổi mã trực tiếp trên Chart


    Ngoài ra mình cũng có 1 room chat Telegram hỗ trợ nhau để viết code Amibroker nhanh hơn. Sắp tới mình đang chuẩn bị triển khai thêm chương trình đào tạo viết code amibroker. Bạn nào muốn giao lưu về viết code hoặc muốn học thì tham gia room nhé. Khi nào mở lớp mình sẽ thông báo trên room này.

    Link group Telegram: https://t.me/joinchat/eOv7MEmjN-I2NTA9


    Cuối cùng, sau đây là đoạn code để sử dụng :

    Phiên bản Amibroker 6.3
    Mã:
    //MaCP,Gia mua,Stoploss,Target|MaCP,Gia mua,Stoploss,Target|...
    Myasset = ParamStr("My Asset","DXG,15.2,14.25,17.2|PVT,22.8,23.05,26.28|KSB,28.05,30.05,32.7|GEX,19.8,18.5,23.4|PDR,17,16.45,20.64");
    //MaCP, pivot|MaCP, pivot|...
    Mywl = ParamStr("My watchlist","BAF,24.5|PLX,41.1|SBT,15.91|TCD,8.89");
    
    asset_count = StrCount(Myasset, "|")+1;
    wl_count = StrCount(Mywl, "|")+1;
    for ( i = 0; i< asset_count; i++ )
    {
        list = StrExtract( Myasset, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        Giamua = StrExtract( list, 1, ',' ) ;
        Stoploss = StrExtract( list, 2, ',' ) ;
        Target = StrExtract( list, 3, ',' ) ;
     
        SetForeign(symbol);
        fC = LastValue(close);
        rfc = ROC(fc,1);
        RestorePriceArrays();
        PnL = (fc - StrToNum(giamua))/StrToNum(giamua)*100;
     
        Cutloss = fc < StrToNum(Stoploss);
        takeprofit = fc > StrToNum(Target);
        if(Name()== symbol)
        {
            line_sl = LineArray(BarCount-10,StrToNum(stoploss),BarCount,StrToNum(stoploss),1);
            line_target = LineArray(BarCount-10,StrToNum(Target),BarCount,StrToNum(Target),1);
            Plot(line_sl,"stoploss",colorRed,styleThick+styleDashed,Null,Null,5);
            Plot(line_target,"Target",colorgreen,styleThick+styleDashed,Null,Null,5);
     
     
            if  (Status("action") == actionExplore )
        {
            // Clear the static vars from last run
        //StaticVarRemove( "luotsong*" );
             
        Date_time =  DateTime();
        Message1 = "Exit "+symbol +" "+ WriteVal(PnL,4.2)+"%" +"| Gia hien tai: "+fc+ "| Stoploss: "+ Stoploss;
        Message2 = "Take profit "+symbol +" "+ WriteVal(PnL,4.2)+"%" +"| Gia hien tai: "+fc+ "| Target: "+target ;
    
        TelegramAPI_ID2 = "xxxxxxxxxxxxxx"; //Get the Bot API key via BotFather in Telgram
        TelgramCHAT_ID2 = "xxxxxxxxxx"; //Channel ID example : @marketcalls_in
    
        Luotsong = StaticVarGetText ("luotsong" +  symbol);
        if(Luotsong != DateTimeToStr(Date_time[BarCount-1],1) AND Cutloss  )
        {
            TelegramAlertsBuy = InternetOpenURL("https://api.telegram.org/bot"+TelegramAPI_ID2+"/sendMessage?chat_id="+TelgramCHAT_ID2+"&text= "+Message1 );
            InternetClose(TelegramAlertsBUY);
            StaticVarSetText("luotsong" + symbol, DateTimeToStr(Date_time[BarCount-1],1), True);
        }
        else if(Luotsong != DateTimeToStr(Date_time[BarCount-1],1) AND takeprofit  )
        {
            TelegramAlertsBuy = InternetOpenURL("https://api.telegram.org/bot"+TelegramAPI_ID2+"/sendMessage?chat_id="+TelgramCHAT_ID2+"&text= "+Message2 );
            InternetClose(TelegramAlertsBUY);
            StaticVarSetText("luotsong" + symbol, DateTimeToStr(Date_time[BarCount-1],1), True);
        }
    }
        }
     
                         
    }
    
    
    for ( i = 0; i< wl_count; i++ )
    {
        list = StrExtract( Mywl, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        pivot = StrExtract( list, 1, ',' ) ;
     
        SetForeign(symbol);
        fC = LastValue(close);
        rfc = ROC(fc,1);
        RestorePriceArrays();
        breakout = fc > StrToNum(pivot);
        if(Name()== symbol)
        {
            line_pivot = LineArray(BarCount-10,StrToNum(pivot),BarCount,StrToNum(pivot),1);
            Plot(line_pivot,"pivot",colorGold,styleThick+styleDashed,Null,Null,5);
     
            if  (Status("action") == actionExplore )
        {
            // Clear the static vars from last run
        //StaticVarRemove( "luotsong*" );
             
        Date_time =  DateTime();
        Message1 = "Buy "+symbol +" | Gia hien tai: "+fc+" ("+  WriteVal(rfc,4.2)+"%)"+" | Pivot: "+ pivot;
    
        TelegramAPI_ID2 = "xxxxxxxxxxx"; //Get the Bot API key via BotFather in Telgram
        TelgramCHAT_ID2 = "xxxxxxxxxxx"; //Channel ID example : @marketcalls_in
    
        Luotsong = StaticVarGetText ("luotsong" +  symbol);
        if(Luotsong != DateTimeToStr(Date_time[BarCount-1],1) AND breakout  )
        {
            TelegramAlertsBuy = InternetOpenURL("https://api.telegram.org/bot"+TelegramAPI_ID2+"/sendMessage?chat_id="+TelgramCHAT_ID2+"&text= "+Message1 );
            InternetClose(TelegramAlertsBUY);
            StaticVarSetText("luotsong" + symbol, DateTimeToStr(Date_time[BarCount-1],1), True);
        }
     
        }
        }
     
                         
    }
    
    bi = BarIndex();
    fbr = Status("firstbarinrange");
    explore = Status("action") == actionExplore;
    fvb = IIf(explore, LastValue(ValueWhen(fbr,bi)), Status("firstvisiblebar"));
    
    GfxSetOverlayMode( 0 );
    
    // formatted text output sample via low-level gfxfunctions
    
    CellHeight = Param("Cell Height",28,0,100,1);
    CellWidth = Param("Cell Width",128,0,200,1);
    start_x = Param("Vi tri Table X",0,0,2000,1);
    start_y = Param("Vi tri Table Y",30,0,500,1);
    BtnOffsetXY = 1;
    x1= start_x;
    y1= start_y;
    y2=y1 + CellHeight;
    x2 = x1 + CellWidth;
    col = Param("col",4,1,10,1);
    
    function PointInside(x0, y0, x, y, width, height) {
        global _x0, _y0;
        x = x+_x0; y = y+_y0;
        x0 = x0+_x0; y0 = y0+_y0;
        return ((x0 >= x) && (y0 >= y) && (x0 <= (x+width)) && (y0 <= (y+height)));
    }
    _cursorMouseButtons = GetCursorMouseButtons();
    DT_CENTER = 1; DT_VCENTER = 4 | 32;
    
    function LeftClickInside(x, y, width, height) {
        global _cursorMouseButtons, _x0, _y0;
        local px, py, res;
     
        // x = x+_x0; y = y+_y0;
        res = False;
        if (_cursorMouseButtons & 8) { // click
            px = GetCursorXPosition(1);
            py = GetCursorYPosition(1);
            res = PointInside(px, py, x, y, width, height);
        }
        return res;
    }
    
    global IDset;
    if( typeof( IDset ) == "undefined" ) IDset = 0;
    
    function GuiButtonTrigger( ButtonName, x, y, width, Height ) {
        /// @link http://forum.amibroker.com/t/guibuttons-for-everyone/1716/4
        /// by beaver & fxshrat
        /// version 1.1
     
        //_TRACEF( "IDset before: %g", IDset );
        GuiButton( ButtonName, ++IDset, x, y, width, height, 1 );
        //_TRACEF( "IDset after: %g", IDset );
     
        id = GuiGetEvent( 0, 0 );// receiving button id
        event = GuiGetEvent( 0, 1 );// receiving notifyflag
        clickevent = event == 1;
        ButtonClicked = id == IDset && clickevent;
     
        return ButtonClicked;
    }
    
    
    click = GetCursorMouseButtons() == 9;
    Px = GetCursorXPosition( 1 );
    Py = GetCursorYPosition( 1 );
    
    GfxSetBkMode( 1 );
    
    
    
    procedure SetOrigin(x0, y0) {
        global _x0, _y0;
        _x0 = x0; _y0 = y0;
    }
    procedure GfxSetColors(fgColor, bgColor) {
        GfxSetTextColor(fgColor); GfxSetBkColor(bgColor);
        GfxSelectPen(fgColor); GfxSelectSolidBrush(bgColor);
    }
    
    function GfxGetState(id) {
        return Nz(StaticVarGet("GfxState"+id+GetChartID()), 0);
    }
    procedure GfxSetState(id, val) {
        StaticVarSet("GfxState"+id+GetChartID(), val);
    }
    procedure GfxLabel(text, x, y, width, height, format) {
        GfxSelectFont( "Arial", CellHeight/3.2, 600 );
        GfxSetTextColor(colorYellow);
        GfxDrawText( text, x, y, x+width, y+height, format | DT_VCENTER );
    }
    
    function GfxHTabs(id, headers, headheight, x, y, width, height, colorfg, colorbg) {
        local px,choice,na,i,G,header,w, wi, prevwi;
     
        choice = GfxGetState(id);
        GfxSetColors(colorfg, colorbg);
     
        for(G = 0; (header = StrExtract(headers,G)) != ""; ++G) {};
        w = width/G; wi = x; prevwi = x;
        if (LeftClickInside(x,y,width,headheight)) {
            px = GetCursorXPosition( 1 );
            // choice = floor((px - x)/w);
            // wi = x; prevwi = x;
            for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
                wi = wi + (width+5)/(StrCount(headers, ",")+1);
                if ((px > prevwi) && (px < wi))  { choice = i; break; }
            }
            GfxSetState(id, choice); // StaticVarSet(na, choice);
        }
    
        GfxSetBkMode(1);
        // Draw Zone & Tabs
        wi = x; prevwi = x;
        for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
            wi = wi + (width+5)/(StrCount(headers, ",")+1);;
            //GfxSelectPen(colorLightYellow,2);
            // GfxSelectSolidBrush(colorbg);
            GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5);
            if (i != choice) {
             
                GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5);
                GfxSelectSolidBrush( colorbg );
            } else {
                wic = wi; prevwic = prevwi;
            }
            GfxSelectFont( "Arial", CellHeight/2.9, 600 );
            GfxDrawText(header, prevwi, y, wi, y+headheight+5, 1|4|32);
            prevwi = wi;
        }
    
        return choice;
    }
    
    
    
    ////////////////////////////////////////////////////
    // HEADER
    //////////////////////////////////////////////////
    //Datetime
    
    GfxSetZOrder(2);
    GfxSelectFont( "Arial",CellHeight/3 );
    GfxSelectSolidBrush(  colorDarkGreen);
    GfxRoundRect(x1, y1-3, x1 + CellWidth*col+3, y1 + CellHeight*2+3,15,15);
    GfxSetTextColor(colorYellow);
    GfxSetBkMode(1);//set transparent mode
    dt = SelectedValue(DateTime());
    
    GfxDrawText( "Created by Nguyen Joe\nContact: 0979019012" ,x1+BtnOffsetXY, y1, x1 + CellWidth*2+10,y1 + CellHeight*2, 1 );
    
    index_fc = Foreign("Vnindex","close");
    index_rfc = WriteVal(ROC(index_fc,1),5.2);
    index_chg = index_fc - Ref(index_fc,-1);
    colorindex = IIf(index_fc>Ref(index_fc,-1),colorbrightGreen,IIf(index_fc == Ref(index_fc,-1),colorGold,colorRed));
    
    GfxSetTextColor(colorindex[BarCount-1]);
    GfxSelectFont("arial",CellHeight/3,500);
    GfxDrawText( " VNINDEX " +index_fc+"\n"+ DateTimeToStr( dt[BarCount-1],1 )+" "+index_rfc+"%"  ,x1+CellWidth*2+10, y1, x1 + CellWidth*col-50,y1 + CellHeight*2, 1 );
    
        if ( px > x1+CellWidth*2+10 AND px<x1 + CellWidth*3 AND py> y1+5 AND py <y1 + CellHeight*2 AND Click )    {
            AB = CreateObject( "Broker.Application" );
            doc = AB.ActiveDocument;
            doc.Name = "Vnindex" ;
        }
    
    // ON OFF BUTTON
    
    id = GuiGetEvent( 0, 0 ); event = GuiGetEvent( 0, 1 );
    MyChartID = GetChartID();
    ToggleButton = Nz( StaticVarGet( "ToggleButton" + MyChartID ));
    
    GuiButtonTrigger( "Off", x1+CellWidth*col-45, y1+CellHeight/2, 40, 30 );
    GuiSetColors(IDset,IDset,2,colorWhite, colorGreen, colorYellow, colorWhite, colorGreen, colorYellow, colorGold, colorDarkTeal, colorYellow );
    
    ////////////////////////////////////////////////////
    //DRAWING TABLE OF BUTTONS
    //////////////////////////////////////////////////
    GfxSelectFont( "Arial",CellHeight/3.2 );
    
    VN30=ParamStr("VN30","ACB,BID,BVH,CTG,FPT,GAS,GVR,HDB,HPG,KDH,MBB,MSN,MWG,NVL,PDR,PLX,PNJ,POW,SAB,SSI,STB,TCB,TPB,VCB,VHM,VIC,VJC,VNM,VPB,VRE");
    
    NGANHANG= CategoryGetSymbols( categoryWatchlist, 1 );
    SymCount1 = StrCount( NGANHANG, "," ) + 1;
    row1 = ceil(SymCount1/col);
    py1 = y1+CellHeight*4+5;
    
    CHUNGKHOAN= CategoryGetSymbols( categoryWatchlist, 2 );
    SymCount2 = StrCount( CHUNGKHOAN, "," ) + 1;
    row2 = ceil(SymCount2/col);
    py2 = py1 + CellHeight+ CellHeight*row1;
    
    BATDONGSAN= CategoryGetSymbols( categoryWatchlist, 3 );
    SymCount3 = StrCount( BATDONGSAN, "," ) + 1;
    row3 = ceil(SymCount3/col);
    py3 = py2 + CellHeight+ CellHeight*row2;
    
    XD_VLXD = CategoryGetSymbols( categoryWatchlist, 4 );
    SymCount4 = StrCount( XD_VLXD, "," ) + 1;
    row4 = ceil(SymCount4/col);
    py4 = py3 + CellHeight+ CellHeight*row3;
    
    HANGHOA = CategoryGetSymbols( categoryWatchlist, 5);
    SymCount5 = StrCount( HANGHOA, "," ) + 1;
    row5 = ceil(SymCount5/col);
    py5 = py4 + CellHeight+ CellHeight*row4;
    
    BLECONGNGHE = CategoryGetSymbols( categoryWatchlist, 6);
    SymCount6 = StrCount( BLECONGNGHE, "," ) + 1;
    row6 = ceil(SymCount6/col);
    py6 = py5 + CellHeight+ CellHeight*row5;
    
    DIEN_DK = CategoryGetSymbols( categoryWatchlist, 7);
    SymCount7 = StrCount( DIEN_DK, "," ) + 1;
    row7 = ceil(SymCount7/col);
    py7 = py6 + CellHeight+ CellHeight*row6;
    
    TIEUDUNG = CategoryGetSymbols( categoryWatchlist, 8);
    SymCount8 = StrCount( TIEUDUNG, "," ) + 1;
    row8 = ceil(SymCount8/col);
    py8= py7 + CellHeight+ CellHeight*row7;
    
    VANTAI = CategoryGetSymbols( categoryWatchlist, 9);
    SymCount9 = StrCount( VANTAI, "," ) + 1;
    row9 = ceil(SymCount9/col);
    py9 = py8 + CellHeight+ CellHeight*row8;
    
    KHAC= CategoryGetSymbols( categoryWatchlist, 10);
    SymCount10 = StrCount( KHAC, "," ) + 1;
    row10 = ceil(SymCount10/col);
    py10 = py9 + CellHeight+ CellHeight*row9;
    py11 = py10 + CellHeight+ CellHeight*row10;
    
    row_num = row1 + row2+ row3+ row4+ row5 + row6+ row7+ row8 + row9 + row10 ;
    //Stockprice Dashboard
    color = Null;
    //GfxFillSolidRect( x1, y1, x1+CellWidth*col, y1+CellHeight*row, colorGrey40 );
    function SymPicker(tickerlist,x1, y1,CellHeight,CellWidth,col)
    {
    GfxSelectPen( colorGrey40 );
    
    sym_num = StrCount(tickerlist, ",")+1;
    mat = Matrix(sym_num, 2);
    rownum = MxGetSize(mat, 0);
    last_bar = BarCount-1;
    
        for ( i = 0; i < sym_num; i++ )
        {
         
        Ticker = StrExtract( tickerlist, i, ',' );
        SetForeign(Ticker);
        fC = close;
        RestorePriceArrays();
        idx = Max(Min(NullCount(fc),last_bar), fvb);
         
            if (! IsNull(fc[ idx ])) {
                relP = ROC(fc,1);
                mat[i][0] = LastValue( relP );
                mat[i][1] = i;      
                }
        }
        mat = MxSortRows(mat, False, 0);
        for ( i = 0; i < rownum; i++ )
        {
            val = mat[i][0];    n = mat[i][1];
            if (! IsNull(val))
        {
            Ticker = StrExtract(tickerlist, n);
            if (val[i] >= 6.7)
            color = ColorRGB(255,128,255);
            else if (val[i] >= 3 AND val[i]< 6.7)
            color = ColorRGB(0,255,0);
            else if (val[i] >= 1 AND val[i]< 3)
            color = ColorRGB(102,225,102);
                else if (val[i] > 0 AND val[i]< 1)
                color = ColorRGB(178,256,102);
                    else if (val[i] == 0 )
                    color = ColorRGB(255,255,128);
                        else if (val[i] < 0 AND val[i] >= -1)
                        color = ColorRGB(255,204,153);
                            else if (val[i] < -1 AND val[i] >= -3)
                            color = ColorRGB(255,128,0);
                                else if (val[i] < -3 AND val[i] >= -6.7)
                                color = ColorRGB(255,51,51);
                                    else ColorRGB(0,255,255);
         
            GfxSelectSolidBrush(  color);
         
            GfxSelectFont( "Arial",CellHeight/3.2 );
            GfxSelectPen(colorWhite);
            GfxRoundRect( x1, y1, x1+CellWidth, y1+CellHeight , 20, 20 ) ;
            GfxSetTextColor(colorBlack);
            GfxTextOut( Ticker + WriteVal(val,5.1)+"%", x1+10, y1+3 );
         
            if ( px > x1 AND px<x1+CellWidth AND py> y1 AND py < y1+CellHeight AND Click )    {
            AB = CreateObject( "Broker.Application" );
            doc = AB.ActiveDocument;
            doc.Name = Ticker;
         
         
            }
         
            if( x1 + CellWidth >= start_x + CellWidth*col )
            {
                y1 += CellHeight ;
                x1 = start_x ;
            }
                else x1 += CellWidth ;
            }    
        }
    
    }
    
    function toplist(TickerList,topn,period,text,_x0,_y0,CellWidth,CellHeight)
    {
            GfxSelectSolidBrush(colorDarkGreen);
            GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col/3+5, _y0+CellHeight*(topn+2)+10,15,15);
            GfxLabel(text,_x0, _y0+10, CellWidth*col/3,CellHeight,1);
             
            sym_num = StrCount(tickerlist, ",")+1;
         
            mat = Matrix(sym_num, 2);
            rownum = MxGetSize(mat, 0);
            last_bar = BarCount-1;
            for ( i = 0; i< sym_num; i++ )
            {
            symbol = StrExtract( tickerlist, i, ',' );
            SetForeign(symbol);
            fc = Close;
            RestorePriceArrays();
            idx = Max(Min(NullCount(fc),last_bar), fvb);
            if (! IsNull(fc[ idx ])) {
                relP = ROC(fc,period);
                mat[i][0] = LastValue( relP );
                mat[i][1] = i;      
                }
            }
            mat = MxSortRows(mat, False, 0);
            for ( i = 0; i < topn AND i < sym_num; i++ ) {
            val = mat[i][0];    n = mat[i][1];
            if (! IsNull(val))
                {
                    if (val[i] >= 35)
                    color = ColorRGB(255,128,255);
                        else if (val[i] >= 20 AND val[i]< 35)
                        color = ColorRGB(0,255,0);
                            else if (val[i] >= 5 AND val[i]< 20)
                            color = ColorRGB(102,225,102);
                                else if (val[i] > 0 AND val[i]< 5)
                                color = ColorRGB(178,256,102);
                                    else if (val[i] == 0 )
                                    color = ColorRGB(255,255,128);
                                        else if (val[i] < 0 AND val[i] >= -5)
                                        color = ColorRGB(255,204,153);
                                            else if (val[i] < -5 AND val[i] >= -20)
                                            color = ColorRGB(255,128,0);
                                                else if (val[i] < -20 AND val[i] >= -35)
                                                color = ColorRGB(255,51,51);
                                                    else ColorRGB(0,255,255);
                 
                symbol = StrExtract(tickerlist, n);
                ////////////
                textname=symbol;
                //mauneno=ColorBlend( colorLavender, colorLavender, 0 );
                GfxSelectFont( "Arial", CellHeight/3.2, 500 );
                GfxSetTextColor( colorGold);
                GfxDrawText("Ticker     % ",_x0 +10 , _y0 + cellHeight+5, _x0+cellWidth*col/3, _y0+2*cellHeight+5, 0);
                GfxSelectSolidBrush(color);
                GfxRoundRect(_x0,_y0 + (i+2) * cellHeight+3,_x0+cellWidth*col/3, (i+3) * cellHeight+_y0 +3,15,15);
                if ( px > _x0 AND px<_x0+cellWidth*col/3 AND py> _y0 + (i+2) * cellHeight+3 AND py < (i+3) * cellHeight+_y0 +3 AND Click )    {
                AB = CreateObject( "Broker.Application" );
                doc = AB.ActiveDocument;
                doc.Name = symbol;
                }
                GfxSetTextColor( colorBlack);
                GfxDrawText(textname,_x0 +10 , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth, (i+3) * cellHeight+_y0 +5, 0);
             
                //GfxDrawText(textgia,_x0 ,_y0 + (i+2) * cellHeight +  5, _x0 +  cellWidth*col/3, (i+3) * cellHeight+_y0 +5 , 1);
             
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",val),_x0 ,_y0 + (i+2) * cellHeight +  5, _x0 +  cellWidth*col/3-10, (i+3) * cellHeight+_y0 +5 , 2);
         
             
                }
            }
         
         
    }
    
    
    function DMDT(TickerList,text,_x0,_y0,CellWidth,CellHeight)
    {
        GfxSelectSolidBrush(colorDarkGreen);
        sym_num = StrCount(tickerlist, "|")+1;
        GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col+5, _y0+CellHeight*(sym_num+2)+10,15,15);
        GfxLabel(text,_x0, _y0+10, CellWidth*col,CellHeight,1);
         
        for ( i = 0; i< sym_num; i++ )
        {
        list = StrExtract( Myasset, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        Giamua = StrExtract( list, 1, ',' ) ;
        Stoploss = StrExtract( list, 2, ',' ) ;
        Target = StrExtract( list, 3, ',' ) ;
     
        SetForeign(symbol);
        fC = close;
        rfc = ROC(fc,1);
        RestorePriceArrays();
        fC1 = LastValue(fC);
        rfc1 = LastValue(rfc);
        PnL = (fC1 - StrToNum(giamua))/StrToNum(giamua)*100;
     
        Cutloss = fC1 < StrToNum(Stoploss);
        takeprofit = fC1 > StrToNum(Target);
     
        if (fC1 < StrToNum(Stoploss))
            color = colorRed;
            else if (fC1 >= StrToNum(Stoploss) AND fC1 <= StrToNum(giamua))
                color = colorOrange;
                else if (fC1 <= StrToNum(Target) AND  fC1 > StrToNum(giamua))
                    color = colorGreen;
                        else if (fC1 > StrToNum(Target) )
                            color = ColorRGB(249,4,249);
         
                textname=symbol;
                textgia=WriteIf(fC1<10,"0"+WriteVal(fC1,1.2),WriteVal(fC1,1.2));
                //mauneno=ColorBlend( colorLavender, colorLavender, 0 );
                GfxSelectFont( "Arial", CellHeight/3.2, 500 );
                GfxSetTextColor( colorGold);
                GfxDrawText("Ticker  Gia Mua   Stoploss   Price   Target   PnL",_x0 +8 , _y0 + cellHeight+5, _x0+cellWidth*col, _y0+2*cellHeight+5, 0);
                GfxSelectSolidBrush(color);
                GfxRoundRect(_x0,_y0 + (i+2) * cellHeight+3,_x0+cellWidth*col, (i+3) * cellHeight+_y0 +3,15,15);
                if ( px > _x0 AND px<_x0+cellWidth*col AND py> _y0 + (i+2) * cellHeight+3 AND py < (i+3) * cellHeight+_y0 +3 AND Click )    {
                AB = CreateObject( "Broker.Application" );
                doc = AB.ActiveDocument;
                doc.Name = symbol;
                }
                GfxSetTextColor( colorBlack);
                GfxDrawText(textname,_x0   , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/6, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(giamua,_x0 +cellWidth*col/6 , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/3, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(stoploss,_x0 +cellWidth*col/3  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/2, (i+3) * cellHeight+_y0 +5, 1);
    
                GfxDrawText(textgia,_x0 +cellWidth*col/2 ,_y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/3*2, (i+3) * cellHeight+_y0 +5 , 1);
                GfxDrawText(target,_x0 +cellWidth*col/3*2  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/6*5, (i+3) * cellHeight+_y0 +5, 1);
             
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",Pnl),_x0 +cellWidth*col/6*5 ,_y0 + (i+2) * cellHeight +  5, _x0 + cellWidth*col, (i+3) * cellHeight+_y0 +5 ,2);
         
         
        }
    }
    
    function watchlist(TickerList,text,_x0,_y0,CellWidth,CellHeight)
    {
        GfxSelectSolidBrush(colorDarkGreen);
        sym_num = StrCount(tickerlist, "|")+1;
        GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col+5, _y0+CellHeight*(sym_num+2)+10,15,15);
        GfxLabel(text,_x0, _y0+10, CellWidth*col,CellHeight,1);
        for ( i = 0; i< wl_count; i++ )
        {
        list = StrExtract( Mywl, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        pivot = StrExtract( list, 1, ',' ) ;
     
        SetForeign(symbol);
        fC = close;
        rfc = ROC(fc,1);
        GTGD = V*C;
        DBKL = V/MA(V,50)*100 ;
        RestorePriceArrays();
     
     
        RestorePriceArrays();
        fC1 = LastValue(fC);
        rfc1 = LastValue(rfc);
     
        breakout = fC1 > StrToNum(pivot);
         
        if (breakout)
                color = colorGreen;
            else color = colorGold;
         
                textname=symbol;
                textgia=WriteIf(fC1<10,"0"+WriteVal(fC1,1.2),WriteVal(fC1,1.2));
                //mauneno=ColorBlend( colorLavender, colorLavender, 0 );
                GfxSelectFont( "Arial", CellHeight/3.2, 500 );
                GfxSetTextColor( colorGold);
                GfxDrawText("Ticker    Gia      %       GTGD         %DBKL   Pivot",_x0 +8 , _y0 + cellHeight+5, _x0+cellWidth*col, _y0+2*cellHeight+5, 0);
                GfxSelectSolidBrush(color);
                GfxRoundRect(_x0,_y0 + (i+2) * cellHeight+3,_x0+cellWidth*col, (i+3) * cellHeight+_y0 +3,15,15);
                if ( px > _x0 AND px<_x0+cellWidth*col AND py> _y0 + (i+2) * cellHeight+3 AND py < (i+3) * cellHeight+_y0 +3 AND Click )    {
                AB = CreateObject( "Broker.Application" );
                doc = AB.ActiveDocument;
                doc.Name = symbol;
                }
                GfxSetTextColor( colorBlack);
                GfxDrawText(textname,_x0   , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/6, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(textgia,_x0 +cellWidth*col/6-30 , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/3, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",rfc1),_x0 +cellWidth*col/6 ,_y0 + (i+2) * cellHeight +  5, _x0 + cellWidth*col/2, (i+3) * cellHeight+_y0 +5 ,1);
                GfxDrawText(numtostr(GTGD,4.0),_x0 +cellWidth*col/2-30  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/3*2+10, (i+3) * cellHeight+_y0 +5, 1);
    
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",DBKL),_x0 +cellWidth*col/3*2-20 ,_y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/6*5+20    , (i+3) * cellHeight+_y0 +5 , 1);
                GfxDrawText(pivot,_x0 +cellWidth*col/6*5  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col-10, (i+3) * cellHeight+_y0 +5, 2);
         
        }
    }
    procedure GfxHT(x,y) {
        SetOrigin(x1,y1+CellHeight*3);
        G = GfxHTabs("HTab1", "BANG GIA,DANH MUC,TOP CP", 30, _x0, _y0-CellHeight+4, CellWidth*col, CellHeight, colorWhite, colorGrey40);
        Nday1  = Param("list 1 period",1,1,5,1);
        Nday2  = Param("list 2 period",5,1,10,1);
        Nday3  = Param("list 3 period",10,1,21,1);
        Nday4  = Param("list 4 period",21,1,65,1);
        Nday5  = Param("list 5 period",65,1,120,1);
        Nday6  = Param("list 6 period",120,1,250,1);
        topn1 = Param("Top 1",15,5,20,1); //Lay Top 15
        topn2 = Param("Top 2",15,5,20,1); //Lay Top 15
        topn3 = Param("Top 3",15,5,20,1); //Lay Top 15
        chooselist = ParamList("Pick list","listnum,list default",0);
        listnum = Param("list Num",0,0,63,1);
        switch(G)
        {
    
            case 0:
             
                GfxSelectSolidBrush(colorDarkGreen);
                GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col+5, _y0+CellHeight*(row_num+11)+10,15,15);
                GfxSetTextColor(colorYellow);
                GfxLabel(" NGAN HANG",_x0, _y0+12, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 1 ), x1, py1+5,CellHeight,CellWidth,col);
             
                GfxLabel(" CHUNG KHOAN",_x0, py1+row1*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 2 ), x1, py2+5,CellHeight,CellWidth,col);
             
                GfxLabel(" BAT DONG SAN",_x0, py2+row2*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 3 ), _x0,py3+5,CellHeight,CellWidth,col);
             
                GfxLabel(" XD- VLXD",_x0, py3+row3*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 4 ), _x0, py4+5,CellHeight,CellWidth,col);
             
                GfxLabel(" HANG HOA",_x0, py4+row4*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 5 ), _x0, py5+5,CellHeight,CellWidth,col);
             
                GfxLabel(" BAN LE - CONG NGHE",_x0, py5+row5*CellHeight+7,CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 6 ), _x0, py6+5,CellHeight,CellWidth,col);
             
                GfxLabel(" DIEN - DAU KHI",_x0, py6+row6*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 7 ), _x0, py7+5,CellHeight,CellWidth,col);
             
                GfxLabel(" TIEU DUNG",_x0, py7+row7*CellHeight+7,CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 8 ), _x0, py8+5,CellHeight,CellWidth,col);
             
                GfxLabel(" CANG-VAN TAI",_x0, py8+row8*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 9 ), _x0, py9+5,CellHeight,CellWidth,col);
             
                GfxLabel(" NHOM NGANH KHAC",_x0, py9+row9*CellHeight+7,  CellWidth*col,CellHeight,4);
                SymPicker( CategoryGetSymbols( categoryWatchlist, 10 ), _x0, py10+5,CellHeight,CellWidth,col);
             
             
             
            break;
            //////////
            case 1:
         
                DMDT(Myasset," DANH MUC DAU TU",_x0,_y0,CellWidth,CellHeight);
                watchlist(mywl,"DANH MUC THEO DOI",_x0,_y0+CellHeight*asset_count+2*CellHeight,CellWidth,CellHeight);
            break;
            ///////////
            case 2:
            GfxSelectSolidBrush(colorDarkGreen);
         
            switch (chooselist)
            {
            case "listnum":
            TickerList = CategoryGetSymbols( categoryWatchlist, listnum );//chon watchlist number
            break;
         
            case "list default":
            TickerList    = NGANHANG + CHUNGKHOAN + BATDONGSAN + BDSKCN + XD_VLXD + HANGHOA + BLECONGNGHE + THUCPHAMXK + DMTS + DIEN_DK + CANGVANTAI; //chon watchlist
            break;
            }
         
            toplist(TickerList,topn1,Nday1," TOP " +Nday1+" NGAY",_x0,_y0,CellWidth,CellHeight);
         
            toplist(TickerList,topn1,Nday2," TOP " +Nday2+" NGAY",_x0+CellWidth*col/3,_y0,CellWidth,CellHeight);
         
            toplist(TickerList,topn1,Nday3," TOP " +Nday3+" NGAY",_x0+CellWidth*col/3*2,_y0,CellWidth,CellHeight);
         
            toplist(TickerList,topn2,Nday4," TOP " +Nday4+" NGAY",_x0,_y0+CellHeight*(topn1+2),CellWidth,CellHeight);
            toplist(TickerList,topn2,Nday5," TOP " +Nday5+" NGAY",_x0+CellWidth*col/3,_y0+CellHeight*(topn1+2),CellWidth,CellHeight);
         
            toplist(TickerList,topn2,Nday6," TOP " +Nday6+" NGAY",_x0+CellWidth*col/3*2,_y0+CellHeight*(topn1+2),CellWidth,CellHeight);
                 
         
    
        }
    }
     
    
    if( id == IDset AND event == 1 )  // If ToggleButton is clicked
    {
        if( ToggleButton ) StaticVarSet( "ToggleButton" + MyChartID, ToggleButton = 0, 0 );
        else  StaticVarSet( "ToggleButton" + MyChartID, ToggleButton = 1, 0 );
    }
    
    if( ToggleButton )
    {
     
        GuiSetText( "On", IDset );
        GfxHT(x1,y1+CellHeight*3);
    }
    
    else
    {
    GuiSetText( "Off", IDset );
    GuiSetColors(IDset,IDset,1,colorWhite, colorRed, colorYellow, colorWhite, colorGreen, colorYellow, colorGold, colorDarkTeal, colorYellow );
    }
    
    _SECTION_BEGIN("Pivot high low");
    
    procedure alternate_proc( pk, tr, sumpk, sumtr )
    {
        global pkg;
        global trg;
    
        pkg = pk;
        trg = tr;
        idxpk = 0;
        idxtr = 0;
        flgtr = 0;
        flgpk = 0;
    
        for( i = 1; i < BarCount; i++ )
        {
            if( pk[i] AND sumpk[i] == 1 AND !tr[i] AND flgpk == 0 )
            {
                idxpk = i;
                flgtr = 0;
            }
            else
                if( ( pk[i] AND sumpk[i] > 1 AND !tr[i] ) OR( pk[i] AND flgpk == 1 ) )
                {
                    if( H[i] > H[idxpk] )
                    {
                        pkg[idxpk] = 0;
                        idxpk = i;
                        flgpk = 0;
                    }
                    else
                        if( H[i] <= H[idxpk] )
                        {
                            pkg[i] = 0;
                            flgpk = 0;
                        }
                }
                else
                    if( tr[i] AND sumtr[i] == 1 AND !pk[i] AND flgtr == 0 )
                    {
                        idxtr = i;
                        flgpk = 0;
                    }
                    else
                        if( ( tr[i] AND sumtr[i] > 1 AND !pk[i] ) OR( tr[i] AND flgtr == 1 ) )
                        {
                            if( L[i] < L[idxtr] )
                            {
                                trg[idxtr] = 0;
                                idxtr = i;
                                flgtr = 0;
                            }
                            else
                                if( L[i] >= L[idxtr] )
                                {
                                    trg[i] = 0;
                                    flgtr = 0;
                                }
                        }
                        else
                            if( pk[i] AND tr[i] )
                            {
                                if( sumpk[i - 1] > sumtr[i - 1] )
                                {
                                    pkg[i] = 0;
                                    flgtr = 1;
                                    idxtr = i;
                                }
                                else
                                    if( sumtr[i - 1] > sumpk[i - 1] )
                                    {
                                        trg[i] = 0;
                                        flgpk = 1;
                                        idxpk = i;
                                    }
                            }
        }
    }
    
    // Fractal Pivots
    x = bi = BarIndex();
    fvb = FirstVisibleValue( bi );
    lvb = LastVisibleValue( bi );
    
    rightstrength = Param( "Right Strength", 9, 2, 50, 1 );
    leftstrength = Param( "Left Strength", 9, 2, 50, 1 );
    leftstrength = rightstrength;
    
    pk = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
    tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
    
    sumpk = Sum( pk, BarsSince( tr ) );
    sumtr = Sum( tr, BarsSince( pk ) );
    alternate_proc( pk, tr, sumpk, sumtr );
    pk = pkg;
    tr = trg;
    
    for( i = 0; i < 3; i++ )
    {
        VarSet( "px" + i, ValueWhen( pk, bi, i ) );
        VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
        VarSet( "ph" + i, ValueWhen( pk, H, i ) );
        VarSet( "tl" + i, ValueWhen( tr, L, i ) );
    }
    
    ll = tr AND tl1 < tl2;
    hl = tr AND tl1 > tl2;
    hh = pk AND ph1 > ph2;
    lh = pk AND ph1 < ph2;
    dt = pk AND ph1 == ph2;
    db = tr AND tl1 == tl2;
    
    
    clrpk = colorblack;
    clrtr = colorblack;
    
    for( i = lvb; i > fvb; i-- )
    {
        // troughs
        if( ll[i] )
        {
            str = "" + WriteVal(L[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, L[i], clrtr, colorDefault, -30 );
        }
    
        if( hl[i] )
        {
            str = "" + WriteVal(L[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, L[i], clrtr, colorDefault, -30 );
        }
    
        if( db[i] )
        {
            str = "DB";
            PlotTextSetFont( str, "Arial", 8, i, L[i], clrtr, colorDefault, -30 );
        }
    
        //peaks
        if( hh[i] )
        {
            str = ""+WriteVal(H[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, H[i], clrpk, colorDefault, 20 );
        }
    
        if( lh[i] )
        {
            str = "" +WriteVal(H[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, H[i], clrpk, colorDefault, 20 );
        }
    
        if( dt[i] )
        {
            str = "DT";
            PlotTextSetFont( str, "Arial", 8, i, H[i], clrpk, colorDefault, 20 );
        }
    }
    
    GraphXSpace = 8;
    
    
    
    //Trailing stop
    
    TrendUp=TrendDown=Null;
    trend[0]=1;
    changeOfTrend=0;
    up_threshold = abs(ph1 - tl1)*0.127+ph1;
    dn_threshold = tl1 - abs(ph1 - tl1)*0.127;
    for (i = 1; i <BarCount-1; i++) {
          TrendUp[i] = Null;
          TrendDown[i] = Null;
     
          trend[i]=1;
     
       
          if (Close[i]>up_threshold[i-1]) {
            trend[i]=1;
            if (trend[i-1] == -1) changeOfTrend = 1;
         
          }
          else if (Close[i]<dn_threshold[i-1]) {
            trend[i]=-1;
            if (trend[i-1] == 1) changeOfTrend = 1;
          }
          else if (trend[i-1]==1) {
            trend[i]=1;
            changeOfTrend = 0;  
          }
          else if (trend[i-1]==-1) {
            trend[i]=-1;
            changeOfTrend = 0;
          }
    
     
       
          if (trend[i]>0 && dn_threshold[i]<dn_threshold[i-1]){
            dn_threshold[i]=dn_threshold[i-1];
          }
       
          if (trend[i]<0 && up_threshold[i]>up_threshold[i-1])
            { up_threshold[i]=up_threshold[i-1];
          }
       
     
          if (trend[i]==1) {
            TrendUp[i]=dn_threshold[i];
         
          }
          else if (trend[i]==-1) {
            TrendDown[i]=up_threshold[i];
       
          }
      }
    
    Trailingstop = ParamToggle("Trailingstop","Yes|No");
    if(Trailingstop)
    {
    Plot(TrendUp,"",colorBlack,styleThick);
    Plot(TrendDown,"",colorBlack,styleThick);
    Buy = trend==1;
    Sell=trend==-1;
    
    Buy=ExRem(Buy,Sell);
    Sell=ExRem(Sell,Buy);
    Short=Sell;
    Cover=Buy;
    
    
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                  
    PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
    PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
    PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                  
    PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
    }
    
    
    _SECTION_END();
    _SECTION_BEGIN("Volume");
    
    //Volume
    
    hhvv = HighestVisibleValue( V );
    minv = -hhvv/50;
    Vdn=IIf(C<Ref(C,-1),V,0);
    Vup=IIf(C>Ref(C,-1),V,0);
    hvup10=HHV(vup,10);
    hv10=HHV(Vdn,10);
    V50=MA(V,50);
    Volratio = V/V50*100;
    upday = C>Ref(C,-1);
    colorPricechg = IIf(upday,colorGreen,colorred);
    TypeofVol  = ParamList("Type of Volume","Zanger volume ratio,pivot pocket volume,standard",0);
    switch(TypeofVol)
    {
        case "Zanger volume ratio":
       color = IIf( Volratio <= 60, colorGrey40, IIf(Volratio > 60 AND Volratio <= 80, colorGold, IIf(Volratio>80 AND Volratio <= 110 AND upday , colorGreen     , IIf(Volratio>80 AND Volratio <= 110 AND NOT upday , colororange , IIf(Volratio > 110 AND Volratio  <= 200 AND upday, colorBrightGreen,  IIf(Volratio > 110 AND Volratio <= 200 AND NOT upday , colorRed, IIf(Volratio > 200 AND upday, ColorRGB(249,4,249), ColorRGB(0,253,251))))))))    ;
     
     
        break;
        case "pivot pocket volume":
        color=IIf( C > Ref(C,-1) AND V<hv10, ParamColor("Volume up", colorGreen ), IIf(C>Ref(C,-1) AND V>hv10,ParamColor("Pivot Pocket", colorBrightGreen)  ,IIf(C<Ref(C,-1) AND V>hvup10,ParamColor("Max Volumn down",ColorRGB(0,253,251)),ParamColor("Volume down",colorred))));
     
        break;
       
     
        case "standard":
        color = IIf(C>= Ref(C,-1),ParamColor("Volume up", colorGreen ),ParamColor("Volume down",colorred));
        break;
    }
    SetBarFillColor(color);
    Plot(V,_DEFAULT_NAME(),ParamColor("color Volume",colorWhite),styleArea|styleOwnScale|styleNoLabel, minv, hhvv*9);
    CHANGE=((C - Ref(C,-1))/Ref(C,-1))*100;
    Plot(V50, "Vol TB 50 Day", colorBlue, styleLine|styleOwnScale|styleNoLabel, minv, hhvv*9, 0, 10);
    
    _SECTION_END();
    _SECTION_BEGIN("Price Chart");
    
    ema13 = eMA (C,13);
    Plot(ema13,"EMA13",colorGold,styleLine+styleThick+styleNoLabel+styleNoTitle);
    r1 = 12;
    r2 = 26;
    r3 = 9;
     
    hist = MACD(12,26) - Signal(12,26,9);
     
    buyhist = hist > Ref(hist,-1);
    sellhist = hist < Ref(hist,-1);
    stay = hist == Ref(hist,-1);
     
    buyema = ema13  > Ref(ema13 ,-1);
    sellema =ema13  < Ref(ema13 ,-1);
     
     
    allowbuy = buyhist AND buyema;
    notallowbuy = sellhist AND sellema;
    
    
    //ICHIMOKU SYSTEM - 3 KIJUN
    
    TenkanSenPeriods = Param("Tenkan Sen Periods", 9, 1, 200, 1);
    KijunSenPeriods = Param("Kijun Sen Periods", 17, 1, 200, 1);
    SenkouSpanBPeriods = Param("Senkou Span B Periods", 26, 1, 200, 1);
    
    kijun = ( HHV( H, KijunSenPeriods ) + LLV( L, KijunSenPeriods) )/2;
    tekan = ( HHV( H, TenkanSenPeriods ) + LLV( L, TenkanSenPeriods ) )/2;
    Lagging = Ref( C, -26 );
    Span1 = (( tekan + kijun )/2);
    Span2 = (HHV( H, SenkouSpanBPeriods) + LLV(L, SenkouSpanBPeriods))/2;
    
    KJ5 = ( HHV( H, 5 ) + LLV( L, 5) )/2;
    KJ13 = ( HHV( H, 13 ) + LLV( L, 13) )/2;
    KJ26 = ( HHV( H, 26 ) + LLV( L, 26) )/2;
    KJ65 = ( HHV( H, 65 ) + LLV( L, 65) )/2;
    KJ130 = ( HHV( H, 130 ) + LLV( L, 130) )/2;
    
    H130=HHV(H,130);
    H65=HHV(H,65);
    H26=HHV(H,26);
    H13=HHV(H,13);
    H5=HHV(H,5);
    
    
    TypeofPrice  = ParamList("Type of Price","Candle Stick,Bar Chart,Elder chart,ichi",0);
    switch(TypeofPrice)
    {
       case "Bar Chart":
            BarColor=IIf(C>Ref(C,-1),colorrgb(46,82,173),colorrgb(238,82,160));
            PlotOHLC( Close,  High,  Low,  Close, "", BarColor, styleBar+styleThick,minv,hhvv*9,0,0,2);
       GraphXSpace = 15;
          break;
       
       
       case "Candle Stick":
            upcolor=ParamColor("Up color ",colorGreen);
            downcolor=ParamColor("Down color ",colorRed);
            barcolor=ParamColor("Bar color ",colorBlack);
            SetBarFillColor(IIf(C>O,upcolor,downcolor));
            PlotOHLC( Open, High, Low, Close, " " , barcolor, styleCandle  +styleNoTitle,minv,hhvv*9);
       GraphXSpace = 15;
            break;
        case "Elder chart":
        thiscolor = IIf(allowbuy, colorGreen, IIf (notallowbuy, colorRed, IIf (stay,colorGreen,colorGold)));
           PlotOHLC( O, H, L, C, "", ThisColor, styleBar+styleThick,minv,hhvv*9,0,0,2);
       GraphXSpace = 15;
            break;
        case "ichi":
        upcolor=ParamColor("Up color ",colorGreen);
        downcolor=ParamColor("Down color ",colorRed);
        barcolor=ParamColor("Bar color ",colorBlack);
        SetBarFillColor(IIf(C>O,upcolor,downcolor));
        PlotOHLC( Open, High, Low, Close, " " , barcolor, styleCandle  +styleNoTitle,minv,hhvv*9);
        Plot(Span1,"span A",colorGreen,styleNoLabel,0,0,26);
        Plot(Span2,"span B",colorRed,styleNoLabel,0,0,26);
        //SetBarFillColor(IIf(Span1>Span2,colorLime,colorOrange));
        PlotOHLC(Span1,Span2,Span1,Span2,"",IIf(Span1>Span2,colorGreen,colorRed),styleBarNoTicks|styleNoLabel,0,0,26);
        Plot(KJ26,"KJ 26",colorBlack,  styleThick,Null,Null,0,1);
        Plot(KJ65,"KJ 65",colorBlack, styleThick + styleDashed,Null,Null,0,1);
        Plot(KJ130,"KJ 130",colorBlack, styleThick + styleDots,Null,Null,0,1);
    
    }
    _SECTION_END();
    
    _SECTION_BEGIN("MA");
    
    p1 = Param("Short MA",25,5,200,1);
    p2 = Param("mid MA",50,20,200,1);
    p3 = Param("Long MA",200,50,200,1);
    EMA_onoff  = ParamToggle("EMA","Yes|No",1);
    if(EMA_onoff)
    {
     
        Plot(EMA(C,p1),"EMA "+p1,colorRed,styleThick);
        Plot(EMA(C,p2),"EMA "+ p2,colorBlue,styleDashed + styleThick);
        Plot(EMA(C,p3),"EMA "+ p3,colorViolet,styleDashed + styleThick);
    
    }
    _SECTION_END();
    
    
    
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title =  Name() + " - "+ StrFormat(" {{DATE}} ")+" - "+ " O " + EncodeColor(colorGold)+ O + EncodeColor(colorGrey40)+ " ,H "+ EncodeColor(colorViolet)+H + EncodeColor(colorGrey40)+" ,L "+EncodeColor(colorRed)+L + EncodeColor(colorGrey40)+" ,C "+ EncodeColor(colorGreen)+C+" "+EncodeColor( SelectedValue(colorPricechg)) + WriteVal(C-Ref(C,-1),1.2) +EncodeColor( SelectedValue(colorPricechg)) + " ("+ WriteVal( ROC( C, 1),1.1)+"%) "+ EncodeColor(colorGrey40)+  " ,V " + EncodeColor( SelectedValue(color)) + WriteVal(V,1.0) + EncodeColor(SelectedValue(color))+  " (" +WriteVal(Volratio,1.2) +"%)"+ EncodeColor(colorGrey40)+  " ,GTGD TB 50 day " + EncodeColor( SelectedValue(color)) + WriteVal(mA(V,50)*C,1.0) );
    
    Phiên bản Amibroker 6.2

    Mã:
    //MaCP,Gia mua,Stoploss,Target|MaCP,Gia mua,Stoploss,Target|...
    Myasset = ParamStr("My Asset","DXG,15.2,14.25,17.2|PVT,22.8,23.05,26.28|KSB,28.05,30.05,32.7|GEX,19.8,18.5,23.4|PDR,17,16.45,20.64");
    //MaCP, pivot|MaCP, pivot|...
    Mywl = ParamStr("My watchlist","BAF,24.5|DRH,4.95|PLX,41.1");
    
    asset_count = StrCount(Myasset, "|")+1;
    wl_count = StrCount(Mywl, "|")+1;
    for ( i = 0; i< asset_count; i++ )
    {
        list = StrExtract( Myasset, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        Giamua = StrExtract( list, 1, ',' ) ;
        Stoploss = StrExtract( list, 2, ',' ) ;
        Target = StrExtract( list, 3, ',' ) ;
       
        SetForeign(symbol);
        fC = LastValue(close);
        rfc = ROC(fc,1);
        RestorePriceArrays();
        PnL = (fc - StrToNum(giamua))/StrToNum(giamua)*100;
       
        Cutloss = fc < StrToNum(Stoploss);
        takeprofit = fc > StrToNum(Target);
        if(Name()== symbol)
        {
            line_sl = LineArray(BarCount-10,StrToNum(stoploss),BarCount,StrToNum(stoploss),1);
            line_target = LineArray(BarCount-10,StrToNum(Target),BarCount,StrToNum(Target),1);
            Plot(line_sl,"stoploss",colorRed,styleThick+styleDashed,Null,Null,5);
            Plot(line_target,"Target",colorgreen,styleThick+styleDashed,Null,Null,5);
       
       
            if  (Status("action") == actionExplore )
        {  
            // Clear the static vars from last run
        //StaticVarRemove( "luotsong*" );
               
        Date_time =  DateTime();
        Message1 = "Exit "+symbol +" "+ WriteVal(PnL,4.2)+"%" +"| Gia hien tai: "+fc+ "| Stoploss: "+ Stoploss;
        Message2 = "Take profit "+symbol +" "+ WriteVal(PnL,4.2)+"%" +"| Gia hien tai: "+fc+ "| Target: "+target ;
    
        TelegramAPI_ID2 = "xxxxxxxxxxxxx"; //Get the Bot API key via BotFather in Telgram
        TelgramCHAT_ID2 = "@xxxxxxxxx"; //Channel ID example : @marketcalls_in
    
        Luotsong = StaticVarGetText ("luotsong" +  symbol);
        if(Luotsong != DateTimeToStr(Date_time[BarCount-1],1) AND Cutloss  )
        {
            TelegramAlertsBuy = InternetOpenURL("https://api.telegram.org/bot"+TelegramAPI_ID2+"/sendMessage?chat_id="+TelgramCHAT_ID2+"&text= "+Message1 );
            InternetClose(TelegramAlertsBUY);
            StaticVarSetText("luotsong" + symbol, DateTimeToStr(Date_time[BarCount-1],1), True);
        }
        else if(Luotsong != DateTimeToStr(Date_time[BarCount-1],1) AND takeprofit  )
        {
            TelegramAlertsBuy = InternetOpenURL("https://api.telegram.org/bot"+TelegramAPI_ID2+"/sendMessage?chat_id="+TelgramCHAT_ID2+"&text= "+Message2 );
            InternetClose(TelegramAlertsBUY);
            StaticVarSetText("luotsong" + symbol, DateTimeToStr(Date_time[BarCount-1],1), True);
        }
    }  
        }
       
                           
    }
    
    
    for ( i = 0; i< wl_count; i++ )
    {
        list = StrExtract( Mywl, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        pivot = StrExtract( list, 1, ',' ) ;
       
        SetForeign(symbol);
        fC = LastValue(close);
        rfc = ROC(fc,1);
        RestorePriceArrays();
        breakout = fc > StrToNum(pivot);
        if(Name()== symbol)
        {
            line_pivot = LineArray(BarCount-10,StrToNum(pivot),BarCount,StrToNum(pivot),1);
            Plot(line_pivot,"pivot",colorGold,styleThick+styleDashed,Null,Null,5);
       
            if  (Status("action") == actionExplore )
        {  
            // Clear the static vars from last run
        //StaticVarRemove( "luotsong*" );
               
        Date_time =  DateTime();
        Message1 = "Buy "+symbol +" | Gia hien tai: "+fc+" ("+  WriteVal(rfc,4.2)+"%)"+" | Pivot: "+ pivot;
    
        TelegramAPI_ID2 = "xxxxxxxxxxxxxx"; //Get the Bot API key via BotFather in Telgram
        TelgramCHAT_ID2 = "@xxxxxxxxxxxxx"; //Channel ID example : @marketcalls_in
    
        Luotsong = StaticVarGetText ("luotsong" +  symbol);
        if(Luotsong != DateTimeToStr(Date_time[BarCount-1],1) AND breakout  )
        {
            TelegramAlertsBuy = InternetOpenURL("https://api.telegram.org/bot"+TelegramAPI_ID2+"/sendMessage?chat_id="+TelgramCHAT_ID2+"&text= "+Message1 );
            InternetClose(TelegramAlertsBUY);
            StaticVarSetText("luotsong" + symbol, DateTimeToStr(Date_time[BarCount-1],1), True);
        }
       
        }  
        }
       
                           
    }
    bi = BarIndex();
    fbr = Status("firstbarinrange");
    explore = Status("action") == actionExplore;
    fvb = IIf(explore, LastValue(ValueWhen(fbr,bi)), Status("firstvisiblebar"));
    
    
    Version( 5.04 ); //requires 5.04 or higher
    
    GfxSetOverlayMode( 0 );
    // formatted text output sample via low-level gfxfunctions
    
    CellHeight = Param("Cell Height",30,0,100,1);
    CellWidth = Param("Cell Width",135,0,200,1);
    start_x = Param("Vi tri Table X",0,0,2000,1);
    start_y = Param("Vi tri Table Y",30,0,500,1);
    BtnOffsetXY = 1;
    x1= start_x;
    y1= start_y;
    y2=y1 + CellHeight;
    x2 = x1 + CellWidth;
    col = Param("col",4,1,10,1);
    
    function PointInside(x0, y0, x, y, width, height) {
        global _x0, _y0;
        x = x+_x0; y = y+_y0;
        x0 = x0+_x0; y0 = y0+_y0;
        return ((x0 >= x) && (y0 >= y) && (x0 <= (x+width)) && (y0 <= (y+height)));
    }
    _cursorMouseButtons = GetCursorMouseButtons();
    DT_CENTER = 1; DT_VCENTER = 4 | 32;
    
    function LeftClickInside(x, y, width, height) {
        global _cursorMouseButtons, _x0, _y0;
        local px, py, res;
       
        // x = x+_x0; y = y+_y0;
        res = False;
        if (_cursorMouseButtons & 8) { // click
            px = GetCursorXPosition(1);
            py = GetCursorYPosition(1);
            res = PointInside(px, py, x, y, width, height);
        }
        return res;
    }
    
    
    
    click = GetCursorMouseButtons() == 9;
    Px = GetCursorXPosition( 1 );
    Py = GetCursorYPosition( 1 );
    
    GfxSetBkMode( 1 );
    
    
    
    procedure SetOrigin(x0, y0) {
        global _x0, _y0;
        _x0 = x0; _y0 = y0;
    }
    procedure GfxSetColors(fgColor, bgColor) {
        GfxSetTextColor(fgColor); GfxSetBkColor(bgColor);
        GfxSelectPen(fgColor); GfxSelectSolidBrush(bgColor);
    }
    
    function GfxGetState(id) {
        return Nz(StaticVarGet("GfxState"+id+GetChartID()), 0);
    }
    procedure GfxSetState(id, val) {
        StaticVarSet("GfxState"+id+GetChartID(), val);
    }
    procedure GfxLabel(text, x, y, width, height, format) {
        GfxSelectFont( "Arial", CellHeight/3.2, 600 );
        GfxSetTextColor(colorYellow);
        GfxDrawText( text, x, y, x+width, y+height, format | DT_VCENTER );
    }
    
    function GfxHTabs(id, headers, headheight, x, y, width, height, colorfg, colorbg) {
        local px,choice,na,i,G,header,w, wi, prevwi;
       
        choice = GfxGetState(id);
        GfxSetColors(colorfg, colorbg);
       
        for(G = 0; (header = StrExtract(headers,G)) != ""; ++G) {};
        w = width/G; wi = x; prevwi = x;
        if (LeftClickInside(x,y,width,headheight)) {
            px = GetCursorXPosition( 1 );
            // choice = floor((px - x)/w);
            // wi = x; prevwi = x;
            for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
                wi = wi + (width+5)/(StrCount(headers, ",")+1);
                if ((px > prevwi) && (px < wi))  { choice = i; break; }
            }
            GfxSetState(id, choice); // StaticVarSet(na, choice);
        }
    
        GfxSetBkMode(1);
        // Draw Zone & Tabs
        wi = x; prevwi = x;
        for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
            wi = wi + (width+5)/(StrCount(headers, ",")+1);;
            //GfxSelectPen(colorLightYellow,2);
            // GfxSelectSolidBrush(colorbg);
            GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5);
            if (i != choice) {
               
                GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5);
                GfxSelectSolidBrush( colorbg );
            } else {
                wic = wi; prevwic = prevwi;
            }
            GfxSelectFont( "Arial", CellHeight/3.4, 600 );
            GfxDrawText(header, prevwi, y, wi, y+headheight+5, 1|4|32);
            prevwi = wi;
        }
    
        return choice;
    }
    
    
    ////////////////////////////////////////////////////
    // HEADER
    //////////////////////////////////////////////////
    
       
    GfxSelectFont( "Arial",CellHeight/3 );
    GfxSelectSolidBrush(  colorDarkGreen);
    GfxRoundRect(x1, y1-3, x1 + CellWidth*col+3, y1 + CellHeight*2+3,15,15);
    GfxSetTextColor(colorYellow);
    GfxSetBkMode(1);//set transparent mode
    dt = SelectedValue(DateTime());
    
    GfxDrawText( "Created by Nguyen Joe\nContact: 0979019012" ,x1+BtnOffsetXY, y1, x1 + CellWidth*2+10,y1 + CellHeight*2, 1 );
    
    index_fc = Foreign("Vnindex","close");
    index_rfc = WriteVal(ROC(index_fc,1),5.2);
    index_chg = index_fc - Ref(index_fc,-1);
    colorindex = IIf(index_fc>Ref(index_fc,-1),colorbrightGreen,IIf(index_fc == Ref(index_fc,-1),colorGold,colorRed));
    
    GfxSetTextColor(colorindex[BarCount-1]);
    GfxSelectFont("arial",CellHeight/3,500);
    GfxDrawText( " VNINDEX " +index_fc+"\n"+ DateTimeToStr( dt[BarCount-1],1 )+" "+index_rfc+"%"  ,x1+CellWidth*2+10, y1, x1 + CellWidth*col-50,y1 + CellHeight*2, 1 );
    
        if ( px > x1+CellWidth*2+10 AND px<x1 + CellWidth*3 AND py> y1+5 AND py <y1 + CellHeight*2 AND Click )    {
            AB = CreateObject( "Broker.Application" );
            doc = AB.ActiveDocument;
            doc.Name = "Vnindex" ;
        }
    
    // ON OFF BUTTON
    
    GfxSelectSolidBrush(colorWhite);
    GfxCircle(x1+CellWidth*col-25, y1 + CellHeight,20);
    GfxSelectSolidBrush(colorRed);
    GfxCircle(x1+CellWidth*col-25, y1 + CellHeight,15);
    GfxSelectFont("arial",CellHeight/5,600);
    //GfxRoundRect(x1+CellWidth*col-45, y1 + CellHeight-20, x1+CellWidth*col-5, y1 + CellHeight +20,15,15);
    OnoffLogic = Nz( StaticVarGet( "ClickToggle", False ) );
    ClickArea     = px >= x1+CellWidth*col-45 AND px <= x1+CellWidth*col-5 AND py >= y1 + CellHeight-20 AND py <= y1 + CellHeight +20;
    FirstClick     = NOT OnoffLogic AND ClickArea AND click;
    NextClick     = OnoffLogic AND ClickArea AND click;
    ////////////////////////////////////////////////////
    //DRAWING TABLE OF BUTTONS
    //////////////////////////////////////////////////
    GfxSelectFont( "Arial",CellHeight/3.2 );
    
    
    VN30=ParamStr("VN30","ACB,BID,BVH,CTG,FPT,GAS,GVR,HDB,HPG,KDH,MBB,MSN,MWG,NVL,PDR,PLX,PNJ,POW,SAB,SSI,STB,TCB,TPB,VCB,VHM,VIC,VJC,VNM,VPB,VRE");
    
    NGANHANG=ParamStr("NGAN HANG","SHB,HDB,MBB,TPB,ACB,MSB,VIB,CTG,LPB,BID,EIB,SSB,STB,TCB,VCB,VPB");
    SymCount1 = StrCount( NGANHANG, "," ) + 1;
    row1 = ceil(SymCount1/col);
    py1 = y1+CellHeight*4+5;
    
    CHUNGKHOAN=ParamStr("CHUNG KHOAN","SHS,ORS,BSI,FTS,HCM,CTS,MBS,APS,APG,SBS,SSI,VCI,VIX,VND");
    SymCount2 = StrCount( CHUNGKHOAN, "," ) + 1;
    row2 = ceil(SymCount2/col);
    py2 = py1 + CellHeight+ CellHeight*row1;
    
    BATDONGSAN=ParamStr("BAT DONG SAN","NLG,DIG,PDR,NVL,KDH,FIR,VHM,CEO,HDC,HPX,HQC,HPX,IDJ,IJC,KHG,SCR,DXG,KOS,DRH,TCH,LDG,VIC,VPI");
    SymCount3 = StrCount( BATDONGSAN, "," ) + 1;
    row3 = ceil(SymCount3/col);
    py3 = py2 + CellHeight+ CellHeight*row2;
    
    BDSKCN=ParamStr("BDS-KCN","KBC,PHR,SZC,GVR,IDC,VGC");
    SymCount4 = StrCount( BDSKCN, "," ) + 1;
    row4 = ceil(SymCount4/col);
    py4 = py3 + CellHeight+ CellHeight*row3;
    
    XD_VLXD=ParamStr("XD_VLXD","CTD,C4G,CII,BCG,HBC,VPG,HUT,L14,LCG,HHV,FCN,BCC,DPG,VCG");
    SymCount5 = StrCount( XD_VLXD, "," ) + 1;
    row5 = ceil(SymCount5/col);
    py5 = py4 + CellHeight+ CellHeight*row4;
    
    HANGHOA=ParamStr("HANG HOA","HT1,PLC,KSB,NKG,HPG,HSG,PTB,DPM,DCM,DGC,AAA");
    SymCount6 = StrCount( HANGHOA, "," ) + 1;
    row6 = ceil(SymCount6/col);
    py6 = py5 + CellHeight+ CellHeight*row5;
    
    BLECONGNGHE=ParamStr("CONG NGHE - BAN LE","PET,MWG,FRT,DGW,VRE,PNJ");
    SymCount7 = StrCount( BLECONGNGHE, "," ) + 1;
    row7 = ceil(SymCount7/col);
    py7 = py6 + CellHeight+ CellHeight*row6;
    
    THUCPHAMXK=ParamStr("THUC PHAM-XK","PAN,DBC,KDC,TAR,HAG,HNG,MSN,BAF,SBT,VNM,SAB");
    SymCount8 = StrCount( THUCPHAMXK, "," ) + 1;
    row8 = ceil(SymCount8/col);
    py8= py7 + CellHeight+ CellHeight*row7;
    
    DMTS=ParamStr("DET MAY THUY SAN","TNG,GIL,TCM,ANV,VHC,IDI,ASM");
    SymCount9 = StrCount( DMTS, "," ) + 1;
    row9 = ceil(SymCount9/col);
    py9 = py8 + CellHeight+ CellHeight*row8;
    
    DIEN_DK=ParamStr("DIEN_DAU KHI","BSR,PLX,PVS,PVD,PVC,GAS,GEX,REE,POW,NT2,GEG,PC1");
    SymCount10 = StrCount( DIEN_DK, "," ) + 1;
    row10 = ceil(SymCount10/col);
    py10 = py9 + CellHeight+ CellHeight*row9;
    
    CANGVANTAI=ParamStr("CANG-VAN TAI","HAH,VTP,GMD,PVT");
    SymCount11 = StrCount( CANGVANTAI, "," ) + 1;
    row11 = ceil(SymCount11/col);
    py11 = py10 + CellHeight+ CellHeight*row10;
    
    row_num = row1 + row2+ row3+ row4+ row5 + row6+ row7+ row8 + row9 + row10+ row11 ;
    //Stockprice Dashboard
    
    //GfxFillSolidRect( x1, y1, x1+CellWidth*col, y1+CellHeight*row, colorGrey40 );
    function SymPicker(tickerlist,x1, y1,CellHeight,CellWidth,col)
    {
    GfxSelectPen( colorGrey40 );
    color = Null;
    sym_num = StrCount(tickerlist, ",")+1;
    mat = Matrix(sym_num, 2);
    rownum = MxGetSize(mat, 0);
    last_bar = BarCount-1;
    
        for ( i = 0; i < sym_num; i++ )
        {
           
        Ticker = StrExtract( tickerlist, i, ',' );
        fC = Foreign( Ticker, "C" );
        idx = Max(Min(NullCount(fc),last_bar), fvb);
           
            if (! IsNull(fc[ idx ])) {
                relP = ROC(fc,1);
                mat[i][0] = LastValue( relP );
                mat[i][1] = i;        
                }
        }
        mat = MxSortRows(mat, False, 0);
        for ( i = 0; i < rownum; i++ )
        {
            val = mat[i][0];    n = mat[i][1];
            if (! IsNull(val))
        {  
            Ticker = StrExtract(tickerlist, n);
            if (val[i] >= 6.7)
            color = ColorRGB(255,128,255);
            else if (val[i] >= 3 AND val[i]< 6.7)
            color = ColorRGB(0,255,0);
            else if (val[i] >= 1 AND val[i]< 3)
            color = ColorRGB(102,225,102);
                else if (val[i] > 0 AND val[i]< 1)
                color = ColorRGB(178,256,102);
                    else if (val[i] == 0 )
                    color = ColorRGB(255,255,128);
                        else if (val[i] < 0 AND val[i] >= -1)
                        color = ColorRGB(255,204,153);
                            else if (val[i] < -1 AND val[i] >= -3)
                            color = ColorRGB(255,128,0);
                                else if (val[i] < -3 AND val[i] >= -6.7)
                                color = ColorRGB(255,51,51);
                                    else ColorRGB(0,255,255);
           
            GfxSelectSolidBrush(  color);
            GfxSelectFont( "Arial",CellHeight/3.2 );
            GfxRoundRect( x1, y1, x1+CellWidth, y1+CellHeight , 15, 15 ) ;  
            GfxSetTextColor(colorBlack);
            GfxTextOut( Ticker + WriteVal(val,5.1)+"%", x1+10, y1+3 );
           
            if ( px > x1 AND px<x1+CellWidth AND py> y1 AND py < y1+CellHeight AND Click )    {
            AB = CreateObject( "Broker.Application" );
            doc = AB.ActiveDocument;
            doc.Name = Ticker;
            }
           
            if( x1 + CellWidth >= start_x + CellWidth*col )
            {
                y1 += CellHeight ;
                x1 = start_x ;
            }
                else x1 += CellWidth ;
            }      
        }
    
    }
    
    function toplist(TickerList,topn,period,text,_x0,_y0,CellWidth,CellHeight)
    {
            GfxSelectSolidBrush(colorDarkGreen);
            GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col/3+5, _y0+CellHeight*(topn+2)+10,15,15);
            GfxLabel(text,_x0, _y0+10, CellWidth*col/3,CellHeight,1);
               
            sym_num = StrCount(tickerlist, ",")+1;
           
            mat = Matrix(sym_num, 2);
            rownum = MxGetSize(mat, 0);
            last_bar = BarCount-1;
            for ( i = 0; i< sym_num; i++ )
            {
            symbol = StrExtract( tickerlist, i, ',' );
            SetForeign(symbol);
            fc = Close;
            RestorePriceArrays();
            idx = Max(Min(NullCount(fc),last_bar), fvb);
            if (! IsNull(fc[ idx ])) {
                relP = ROC(fc,period);
                mat[i][0] = LastValue( relP );
                mat[i][1] = i;        
                }
            }
            mat = MxSortRows(mat, False, 0);
            for ( i = 0; i < topn AND i < sym_num; i++ ) {
            val = mat[i][0];    n = mat[i][1];
            if (! IsNull(val))
                {
                    if (val[i] >= 35)
                    color = ColorRGB(255,128,255);
                        else if (val[i] >= 20 AND val[i]< 35)
                        color = ColorRGB(0,255,0);
                            else if (val[i] >= 5 AND val[i]< 20)
                            color = ColorRGB(102,225,102);
                                else if (val[i] > 0 AND val[i]< 5)
                                color = ColorRGB(178,256,102);
                                    else if (val[i] == 0 )
                                    color = ColorRGB(255,255,128);
                                        else if (val[i] < 0 AND val[i] >= -5)
                                        color = ColorRGB(255,204,153);
                                            else if (val[i] < -5 AND val[i] >= -20)
                                            color = ColorRGB(255,128,0);
                                                else if (val[i] < -20 AND val[i] >= -35)
                                                color = ColorRGB(255,51,51);
                                                    else ColorRGB(0,255,255);
                   
                symbol = StrExtract(tickerlist, n);
                ////////////
                textname=symbol;
                //mauneno=ColorBlend( colorLavender, colorLavender, 0 );
                GfxSelectFont( "Arial", CellHeight/3.2, 500 );
                GfxSetTextColor( colorGold);
                GfxDrawText("Ticker     % ",_x0 +10 , _y0 + cellHeight+5, _x0+cellWidth*col/3, _y0+2*cellHeight+5, 0);
                GfxSelectSolidBrush(color);
                GfxRoundRect(_x0,_y0 + (i+2) * cellHeight+3,_x0+cellWidth*col/3, (i+3) * cellHeight+_y0 +3,15,15);
                if ( px > _x0 AND px<_x0+cellWidth*col/3 AND py> _y0 + (i+2) * cellHeight+3 AND py < (i+3) * cellHeight+_y0 +3 AND Click )    {
                AB = CreateObject( "Broker.Application" );
                doc = AB.ActiveDocument;
                doc.Name = symbol;
                }
                GfxSetTextColor( colorBlack);
                GfxDrawText(textname,_x0 +10 , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth, (i+3) * cellHeight+_y0 +5, 0);
               
                //GfxDrawText(textgia,_x0 ,_y0 + (i+2) * cellHeight +  5, _x0 +  cellWidth*col/3, (i+3) * cellHeight+_y0 +5 , 1);
               
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",val),_x0 ,_y0 + (i+2) * cellHeight +  5, _x0 +  cellWidth*col/3-10, (i+3) * cellHeight+_y0 +5 , 2);
           
               
                }
            }
           
           
    }
    function DMDT(TickerList,text,_x0,_y0,CellWidth,CellHeight)
    {
        GfxSelectSolidBrush(colorDarkGreen);
        sym_num = StrCount(tickerlist, "|")+1;
        GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col+5, _y0+CellHeight*(sym_num+2)+10,15,15);
        GfxLabel(text,_x0, _y0+10, CellWidth*col,CellHeight,1);
           
        for ( i = 0; i< sym_num; i++ )
        {
        list = StrExtract( Myasset, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        Giamua = StrExtract( list, 1, ',' ) ;
        Stoploss = StrExtract( list, 2, ',' ) ;
        Target = StrExtract( list, 3, ',' ) ;
       
        SetForeign(symbol);
        fC = close;
        rfc = ROC(fc,1);
        RestorePriceArrays();
        fC1 = LastValue(fC);
        rfc1 = LastValue(rfc);
        PnL = (fC1 - StrToNum(giamua))/StrToNum(giamua)*100;
       
        Cutloss = fC1 < StrToNum(Stoploss);
        takeprofit = fC1 > StrToNum(Target);
       
        if (fC1 < StrToNum(Stoploss))
            color = colorRed;
            else if (fC1 >= StrToNum(Stoploss) AND fC1 <= StrToNum(giamua))
                color = colorOrange;
                else if (fC1 <= StrToNum(Target) AND  fC1 > StrToNum(giamua))
                    color = colorGreen;
                        else if (fC1 > StrToNum(Target) )
                            color = ColorRGB(249,4,249);
           
                textname=symbol;
                textgia=WriteIf(fC1<10,"0"+WriteVal(fC1,1.2),WriteVal(fC1,1.2));  
                //mauneno=ColorBlend( colorLavender, colorLavender, 0 );
                GfxSelectFont( "Arial", CellHeight/3.2, 500 );
                GfxSetTextColor( colorGold);
                GfxDrawText("Ticker  Gia Mua   Stoploss   Price   Target   PnL",_x0 +8 , _y0 + cellHeight+5, _x0+cellWidth*col, _y0+2*cellHeight+5, 0);
                GfxSelectSolidBrush(color);
                GfxRoundRect(_x0,_y0 + (i+2) * cellHeight+3,_x0+cellWidth*col, (i+3) * cellHeight+_y0 +3,15,15);
                if ( px > _x0 AND px<_x0+cellWidth*col AND py> _y0 + (i+2) * cellHeight+3 AND py < (i+3) * cellHeight+_y0 +3 AND Click )    {
                AB = CreateObject( "Broker.Application" );
                doc = AB.ActiveDocument;
                doc.Name = symbol;
                }
                GfxSetTextColor( colorBlack);
                GfxDrawText(textname,_x0   , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/6, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(giamua,_x0 +cellWidth*col/6 , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/3, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(stoploss,_x0 +cellWidth*col/3  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/2, (i+3) * cellHeight+_y0 +5, 1);
    
                GfxDrawText(textgia,_x0 +cellWidth*col/2 ,_y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/3*2, (i+3) * cellHeight+_y0 +5 , 1);
                GfxDrawText(target,_x0 +cellWidth*col/3*2  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/6*5, (i+3) * cellHeight+_y0 +5, 1);
               
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",Pnl),_x0 +cellWidth*col/6*5 ,_y0 + (i+2) * cellHeight +  5, _x0 + cellWidth*col, (i+3) * cellHeight+_y0 +5 ,2);
           
           
        }
    }
    
    function watchlist(TickerList,text,_x0,_y0,CellWidth,CellHeight)
    {
        GfxSelectSolidBrush(colorDarkGreen);
        sym_num = StrCount(tickerlist, "|")+1;
        GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col+5, _y0+CellHeight*(sym_num+2)+10,15,15);
        GfxLabel(text,_x0, _y0+10, CellWidth*col,CellHeight,1);
        for ( i = 0; i< wl_count; i++ )
        {  
        list = StrExtract( Mywl, i, '|' );
    
        symbol = StrExtract( list, 0, ',' ) ;
        pivot = StrExtract( list, 1, ',' ) ;
       
        SetForeign(symbol);
        fC = close;
        rfc = ROC(fc,1);
        GTGD = V*C;
        DBKL = V/MA(V,50)*100 ;
        RestorePriceArrays();
       
       
        RestorePriceArrays();
        fC1 = LastValue(fC);
        rfc1 = LastValue(rfc);
       
        breakout = fC1 > StrToNum(pivot);
           
        if (breakout)
                color = colorGreen;
            else color = colorGold;
           
                textname=symbol;
                textgia=WriteIf(fC1<10,"0"+WriteVal(fC1,1.2),WriteVal(fC1,1.2));  
                //mauneno=ColorBlend( colorLavender, colorLavender, 0 );
                GfxSelectFont( "Arial", CellHeight/3.2, 500 );
                GfxSetTextColor( colorGold);
                GfxDrawText("Ticker    Gia      %       GTGD         %DBKL   Pivot",_x0 +8 , _y0 + cellHeight+5, _x0+cellWidth*col, _y0+2*cellHeight+5, 0);
                GfxSelectSolidBrush(color);
                GfxRoundRect(_x0,_y0 + (i+2) * cellHeight+3,_x0+cellWidth*col, (i+3) * cellHeight+_y0 +3,15,15);
                if ( px > _x0 AND px<_x0+cellWidth*col AND py> _y0 + (i+2) * cellHeight+3 AND py < (i+3) * cellHeight+_y0 +3 AND Click )    {
                AB = CreateObject( "Broker.Application" );
                doc = AB.ActiveDocument;
                doc.Name = symbol;
                }
                GfxSetTextColor( colorBlack);
                GfxDrawText(textname,_x0   , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/6, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(textgia,_x0 +cellWidth*col/6-30 , _y0 + (i+2) * cellHeight +  5, _x0+cellWidth*col/3, (i+3) * cellHeight+_y0 +5, 1);
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",rfc1),_x0 +cellWidth*col/6 ,_y0 + (i+2) * cellHeight +  5, _x0 + cellWidth*col/2, (i+3) * cellHeight+_y0 +5 ,1);
                GfxDrawText(numtostr(GTGD,4.0),_x0 +cellWidth*col/2-30  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/3*2+10, (i+3) * cellHeight+_y0 +5, 1);
    
                GfxDrawText(StrFormat( "%s  %.1f%%", "    ",DBKL),_x0 +cellWidth*col/3*2-20 ,_y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col/6*5+20    , (i+3) * cellHeight+_y0 +5 , 1);
                GfxDrawText(pivot,_x0 +cellWidth*col/6*5  , _y0 + (i+2) * cellHeight +  5, _x0 +cellWidth*col-10, (i+3) * cellHeight+_y0 +5, 2);
           
        }
    }
    procedure GfxHT(x,y) {
        SetOrigin(x1,y1+CellHeight*3);
        G = GfxHTabs("HTab1", "BANG GIA,DANH MUC,TOP CP", 30, _x0, _y0-CellHeight+4, CellWidth*col, CellHeight, colorWhite, colorGrey40);
        Nday1  = Param("list 1 period",1,1,5,1);
        Nday2  = Param("list 2 period",5,1,10,1);
        Nday3  = Param("list 3 period",10,1,21,1);
        Nday4  = Param("list 4 period",21,1,65,1);
        Nday5  = Param("list 5 period",65,1,120,1);
        Nday6  = Param("list 6 period",120,1,250,1);
        topn1 = Param("Top 1",15,5,20,1); //Lay Top 15
        topn2 = Param("Top 2",15,5,20,1); //Lay Top 15
        topn3 = Param("Top 3",15,5,20,1); //Lay Top 15
        chooselist = ParamList("Pick list","listnum,list default",0);
        listnum = Param("list Num",0,0,63,1);
        switch(G)
        {
    
            case 0:
               
                GfxSelectSolidBrush(colorDarkGreen);
                GfxRoundRect(_x0, _y0+10, _x0 + CellWidth*col+5, _y0+CellHeight*(row_num+11)+10,15,15);
                GfxSetTextColor(colorYellow);
                GfxLabel(" NGAN HANG",_x0, _y0+12, CellWidth*col,CellHeight,4);
                SymPicker( NGANHANG, x1, py1+5,CellHeight,CellWidth,col);
                GfxLabel(" CHUNG KHOAN",_x0, py1+row1*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CHUNGKHOAN, x1, py2+5,CellHeight,CellWidth,col);
                GfxLabel(" BAT DONG SAN",_x0, py2+row2*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( BATDONGSAN, _x0,py3+5,CellHeight,CellWidth,col);
                GfxLabel(" KHU CONG NGHIEP",_x0, py3+row3*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( BDSKCN, _x0, py4+5,CellHeight,CellWidth,col);
                GfxLabel(" XAY DUNG",_x0, py4+row4*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( XD_VLXD, _x0, py5+5,CellHeight,CellWidth,col);
                GfxLabel(" VLXD-HANG HOA",_x0, py5+row5*CellHeight+7,CellWidth*col,CellHeight,4);
                SymPicker( HANGHOA, _x0, py6+5,CellHeight,CellWidth,col);
                GfxLabel(" BAN LE-CONG NGHE",_x0, py6+row6*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( BLECONGNGHE, _x0, py7+5,CellHeight,CellWidth,col);
                GfxLabel(" THUC PHAM",_x0, py7+row7*CellHeight+7,CellWidth*col,CellHeight,4);
                SymPicker( THUCPHAMXK, _x0, py8+5,CellHeight,CellWidth,col);
                GfxLabel(" DET MAY THUY SAN",_x0, py8+row8*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( DMTS, _x0, py9+5,CellHeight,CellWidth,col);
                GfxLabel(" NANG LUONG-DAU KHI",_x0, py9+row9*CellHeight+7,  CellWidth*col,CellHeight,4);
                SymPicker( DIEN_DK, _x0, py10+5,CellHeight,CellWidth,col);
                GfxLabel(" CANG-VAN TAI",_x0, py10+row10*CellHeight+7, CellWidth*col,CellHeight,4);
                SymPicker( CANGVANTAI, _x0, py11+5,CellHeight,CellWidth,col);
               
            break;
            //////////
            case 1:
           
                DMDT(Myasset," DANH MUC DAU TU",_x0,_y0,CellWidth,CellHeight);
                watchlist(mywl,"DANH MUC THEO DOI",_x0,_y0+CellHeight*asset_count+2*CellHeight,CellWidth,CellHeight);
            break;
            ///////////  
            case 2:  
            GfxSelectSolidBrush(colorDarkGreen);
           
            switch (chooselist)
            {
            case "listnum":
            TickerList = CategoryGetSymbols( categoryWatchlist, listnum );//chon watchlist number
            break;
           
            case "list default":
            TickerList    = NGANHANG + CHUNGKHOAN + BATDONGSAN + BDSKCN + XD_VLXD + HANGHOA + BLECONGNGHE + THUCPHAMXK + DMTS + DIEN_DK + CANGVANTAI; //chon watchlist
            break;
            }
           
            toplist(TickerList,topn1,Nday1," TOP " +Nday1+" NGAY",_x0,_y0,CellWidth,CellHeight);
           
            toplist(TickerList,topn1,Nday2," TOP " +Nday2+" NGAY",_x0+CellWidth*col/3,_y0,CellWidth,CellHeight);
           
            toplist(TickerList,topn1,Nday3," TOP " +Nday3+" NGAY",_x0+CellWidth*col/3*2,_y0,CellWidth,CellHeight);
           
            toplist(TickerList,topn2,Nday4," TOP " +Nday4+" NGAY",_x0,_y0+CellHeight*(topn1+2),CellWidth,CellHeight);
            toplist(TickerList,topn2,Nday5," TOP " +Nday5+" NGAY",_x0+CellWidth*col/3,_y0+CellHeight*(topn1+2),CellWidth,CellHeight);
           
            toplist(TickerList,topn2,Nday6," TOP " +Nday6+" NGAY",_x0+CellWidth*col/3*2,_y0+CellHeight*(topn1+2),CellWidth,CellHeight);
                   
           
    
        }
    }
     
    if (FirstClick)
        {
        StaticVarSet( "ClickToggle",  True);
        }
       
    if (NextClick)
        {
        StaticVarSet( "ClickToggle", False);
        }
       
    if(StaticVarGet("ClickToggle")==True)
        {
        GfxSelectSolidBrush(colorGreen);
        GfxCircle(x1+CellWidth*col-25, y1 + CellHeight,15);
        GfxHT(x1,y1+CellHeight*3);
        }
       
    
    
    
    
    _SECTION_BEGIN("Pivot high low");
    
    procedure alternate_proc( pk, tr, sumpk, sumtr )
    {
        global pkg;
        global trg;
    
        pkg = pk;
        trg = tr;
        idxpk = 0;
        idxtr = 0;
        flgtr = 0;
        flgpk = 0;
    
        for( i = 1; i < BarCount; i++ )
        {
            if( pk[i] AND sumpk[i] == 1 AND !tr[i] AND flgpk == 0 )
            {
                idxpk = i;
                flgtr = 0;
            }
            else
                if( ( pk[i] AND sumpk[i] > 1 AND !tr[i] ) OR( pk[i] AND flgpk == 1 ) )
                {
                    if( H[i] > H[idxpk] )
                    {
                        pkg[idxpk] = 0;
                        idxpk = i;
                        flgpk = 0;
                    }
                    else
                        if( H[i] <= H[idxpk] )
                        {
                            pkg[i] = 0;
                            flgpk = 0;
                        }
                }
                else
                    if( tr[i] AND sumtr[i] == 1 AND !pk[i] AND flgtr == 0 )
                    {
                        idxtr = i;
                        flgpk = 0;
                    }
                    else
                        if( ( tr[i] AND sumtr[i] > 1 AND !pk[i] ) OR( tr[i] AND flgtr == 1 ) )
                        {
                            if( L[i] < L[idxtr] )
                            {
                                trg[idxtr] = 0;
                                idxtr = i;
                                flgtr = 0;
                            }
                            else
                                if( L[i] >= L[idxtr] )
                                {
                                    trg[i] = 0;
                                    flgtr = 0;
                                }
                        }
                        else
                            if( pk[i] AND tr[i] )
                            {
                                if( sumpk[i - 1] > sumtr[i - 1] )
                                {
                                    pkg[i] = 0;
                                    flgtr = 1;
                                    idxtr = i;
                                }
                                else
                                    if( sumtr[i - 1] > sumpk[i - 1] )
                                    {
                                        trg[i] = 0;
                                        flgpk = 1;
                                        idxpk = i;
                                    }
                            }
        }
    }
    
    // Fractal Pivots
    x = bi = BarIndex();
    fvb = FirstVisibleValue( bi );
    lvb = LastVisibleValue( bi );
    
    rightstrength = Param( "Right Strength", 9, 2, 50, 1 );
    leftstrength = Param( "Left Strength", 9, 2, 50, 1 );
    leftstrength = rightstrength;
    
    pk = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
    tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
    
    sumpk = Sum( pk, BarsSince( tr ) );
    sumtr = Sum( tr, BarsSince( pk ) );
    alternate_proc( pk, tr, sumpk, sumtr );
    pk = pkg;
    tr = trg;
    
    for( i = 0; i < 3; i++ )
    {
        VarSet( "px" + i, ValueWhen( pk, bi, i ) );
        VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
        VarSet( "ph" + i, ValueWhen( pk, H, i ) );
        VarSet( "tl" + i, ValueWhen( tr, L, i ) );
    }
    
    ll = tr AND tl1 < tl2;
    hl = tr AND tl1 > tl2;
    hh = pk AND ph1 > ph2;
    lh = pk AND ph1 < ph2;
    dt = pk AND ph1 == ph2;
    db = tr AND tl1 == tl2;
    
    
    clrpk = colorblack;
    clrtr = colorblack;
    
    for( i = lvb; i > fvb; i-- )
    {
        // troughs
        if( ll[i] )
        {
            str = "" + WriteVal(L[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, L[i], clrtr, colorDefault, -30 );
        }
    
        if( hl[i] )
        {
            str = "" + WriteVal(L[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, L[i], clrtr, colorDefault, -30 );
        }
    
        if( db[i] )
        {
            str = "DB";
            PlotTextSetFont( str, "Arial", 8, i, L[i], clrtr, colorDefault, -30 );
        }
    
        //peaks
        if( hh[i] )
        {
            str = ""+WriteVal(H[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, H[i], clrpk, colorDefault, 20 );
        }
    
        if( lh[i] )
        {
            str = "" +WriteVal(H[i],8.2);
            PlotTextSetFont( str, "Arial", 8, i, H[i], clrpk, colorDefault, 20 );
        }
    
        if( dt[i] )
        {
            str = "DT";
            PlotTextSetFont( str, "Arial", 8, i, H[i], clrpk, colorDefault, 20 );
        }
    }
    
    GraphXSpace = 8;
    
    
    
    //Trailing stop
    
    TrendUp=TrendDown=Null;
    trend[0]=1;
    changeOfTrend=0;
    up_threshold = abs(ph1 - tl1)*0.127+ph1;
    dn_threshold = tl1 - abs(ph1 - tl1)*0.127;
    for (i = 1; i <BarCount-1; i++) {
          TrendUp[i] = Null;
          TrendDown[i] = Null;
       
          trend[i]=1;
     
         
          if (Close[i]>up_threshold[i-1]) {
            trend[i]=1;
            if (trend[i-1] == -1) changeOfTrend = 1;
           
          }
          else if (Close[i]<dn_threshold[i-1]) {
            trend[i]=-1;
            if (trend[i-1] == 1) changeOfTrend = 1;
          }
          else if (trend[i-1]==1) {
            trend[i]=1;
            changeOfTrend = 0;    
          }
          else if (trend[i-1]==-1) {
            trend[i]=-1;
            changeOfTrend = 0;
          }
    
     
         
          if (trend[i]>0 && dn_threshold[i]<dn_threshold[i-1]){
            dn_threshold[i]=dn_threshold[i-1];
          }
         
          if (trend[i]<0 && up_threshold[i]>up_threshold[i-1])
            { up_threshold[i]=up_threshold[i-1];
          }
         
       
          if (trend[i]==1) {
            TrendUp[i]=dn_threshold[i];
           
          }
          else if (trend[i]==-1) {
            TrendDown[i]=up_threshold[i];
         
          }
      }
    
    Trailingstop = ParamToggle("Trailingstop","Yes|No");
    if(Trailingstop)
    {
    Plot(TrendUp,"",colorBlack,styleThick);
    Plot(TrendDown,"",colorBlack,styleThick);
    Buy = trend==1;
    Sell=trend==-1;
    
    Buy=ExRem(Buy,Sell);
    Sell=ExRem(Sell,Buy);
    Short=Sell;
    Cover=Buy;
    
    
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                    
    PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
    PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
    PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                    
    PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
    }
    
    
    _SECTION_END();
    _SECTION_BEGIN("Volume");
    
    //Volume
    
    hhvv = HighestVisibleValue( V );
    minv = -hhvv/50;
    Vdn=IIf(C<Ref(C,-1),V,0);
    Vup=IIf(C>Ref(C,-1),V,0);
    hvup10=HHV(vup,10);
    hv10=HHV(Vdn,10);
    V50=MA(V,50);
    Volratio = V/V50*100;
    upday = C>Ref(C,-1);
    colorPricechg = IIf(upday,colorGreen,colorred);
    TypeofVol  = ParamList("Type of Volume","Zanger volume ratio,pivot pocket volume,standard",0);
    switch(TypeofVol)
    {
        case "Zanger volume ratio":
       color = IIf( Volratio <= 60, colorGrey40, IIf(Volratio > 60 AND Volratio <= 80, colorGold, IIf(Volratio>80 AND Volratio <= 110 AND upday , colorGreen     , IIf(Volratio>80 AND Volratio <= 110 AND NOT upday , colororange , IIf(Volratio > 110 AND Volratio  <= 200 AND upday, colorBrightGreen,  IIf(Volratio > 110 AND Volratio <= 200 AND NOT upday , colorRed, IIf(Volratio > 200 AND upday, ColorRGB(249,4,249), ColorRGB(0,253,251))))))))    ;
     
     
        break;
        case "pivot pocket volume":
        color=IIf( C > Ref(C,-1) AND V<hv10, ParamColor("Volume up", colorGreen ), IIf(C>Ref(C,-1) AND V>hv10,ParamColor("Pivot Pocket", colorBrightGreen)  ,IIf(C<Ref(C,-1) AND V>hvup10,ParamColor("Max Volumn down",ColorRGB(0,253,251)),ParamColor("Volume down",colorred))));
       
        break;
         
     
        case "standard":
        color = IIf(C>= Ref(C,-1),ParamColor("Volume up", colorGreen ),ParamColor("Volume down",colorred));
        break;
    }
    SetBarFillColor(color);
    Plot(V,_DEFAULT_NAME(),ParamColor("color Volume",colorWhite),styleArea|styleOwnScale|styleNoLabel, minv, hhvv*9);
    CHANGE=((C - Ref(C,-1))/Ref(C,-1))*100;
    Plot(V50, "Vol TB 50 Day", colorBlue, styleLine|styleOwnScale|styleNoLabel, minv, hhvv*9, 0, 10, 2);
    
    _SECTION_END();
    _SECTION_BEGIN("Price Chart");
    
    ema13 = eMA (C,13);
    Plot(ema13,"EMA13",colorGold,styleLine+styleThick+styleNoLabel+styleNoTitle);
    r1 = 12;
    r2 = 26;
    r3 = 9;
     
    hist = MACD(12,26) - Signal(12,26,9);
     
    buyhist = hist > Ref(hist,-1);
    sellhist = hist < Ref(hist,-1);
    stay = hist == Ref(hist,-1);
     
    buyema = ema13  > Ref(ema13 ,-1);
    sellema =ema13  < Ref(ema13 ,-1);
     
     
    allowbuy = buyhist AND buyema;
    notallowbuy = sellhist AND sellema;
    
    TypeofPrice  = ParamList("Type of Price","Candle Stick,Bar Chart,Elder chart",0);
    switch(TypeofPrice)
    {
       case "Bar Chart":
            BarColor=IIf(C>Ref(C,-1),colorrgb(46,82,173),colorrgb(238,82,160));
            PlotOHLC( Close,  High,  Low,  Close, "", BarColor, styleBar+styleThick,minv,hhvv*9,0,0,2);
       GraphXSpace = 15;
          break;
         
         
       case "Candle Stick":
            upcolor=ParamColor("Up color ",colorGreen);
            downcolor=ParamColor("Down color ",colorRed);
            barcolor=ParamColor("Bar color ",colorBlack);
            SetBarFillColor(IIf(C>O,upcolor,downcolor));
            PlotOHLC( Open, High, Low, Close, " " , barcolor, styleCandle  +styleNoTitle,minv,hhvv*9);
       GraphXSpace = 15;
            break;
        case "Elder chart":
        thiscolor = IIf(allowbuy, colorGreen, IIf (notallowbuy, colorRed, IIf (stay,colorGreen,colorGold)));
           PlotOHLC( O, H, L, C, "", ThisColor, styleBar+styleThick,minv,hhvv*9,0,0,2);
       GraphXSpace = 15;
    
    }
    _SECTION_END();
    
    _SECTION_BEGIN("MA");
    
    p1 = Param("Short MA",20,5,200,1);
    p2 = Param("Long MA",50,5,200,1);
    
    TypeofMA  = ParamList("Type of MA","EMA,SMA",0);
    switch(TypeofMA)
    {
        case "EMA":
    
        Plot(EMA(C,p1),"EMA "+p1,colorBlack,styleThick);
        Plot(EMA(C,p2),"EMA "+ p2,colorBlack,styleDashed + styleThick);
        break;
        case "SMA":
        Plot(MA(C,p1),"SMA "+p1,colorBlack,styleThick);
        Plot(MA(C,p2),"SMA "+ p2,colorBlack,styleDashed + styleThick);
    }  
    _SECTION_END();
    
    
    
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title =  Name() + " - "+ StrFormat(" {{DATE}} ")+" - "+ " O " + EncodeColor(colorGold)+ O + EncodeColor(colorGrey40)+ " ,H "+ EncodeColor(colorViolet)+H + EncodeColor(colorGrey40)+" ,L "+EncodeColor(colorRed)+L + EncodeColor(colorGrey40)+" ,C "+ EncodeColor(colorGreen)+C+" "+EncodeColor( SelectedValue(colorPricechg)) + WriteVal(C-Ref(C,-1),1.2) +EncodeColor( SelectedValue(colorPricechg)) + " ("+ WriteVal( ROC( C, 1),1.1)+"%) "+ EncodeColor(colorGrey40)+  " ,V " + EncodeColor( SelectedValue(color)) + WriteVal(V,1.0) + EncodeColor(SelectedValue(color))+  " (" +WriteVal(Volratio,1.2) +"%)"+ EncodeColor(colorGrey40)+  " ,GTGD TB 50 day " + EncodeColor( SelectedValue(color)) + WriteVal(mA(V,50)*C,1.0) );
    
    GraphLabelDecimals = 2;
    
    
     
    Chỉnh sửa cuối: 10/7/23
  2. Đang tải...

    Bài viết tương tự Diễn đàn Date
    [Chia sẻ] Tính năng Chart in Chart: Xem chart Tuần, Tháng nổi ngay trong Chart Daily Bàn luận về Amibroker, Metastock, Metatrader 4 8/8/23
    [Chia sẻ] Tặng code xem bảng giá mini + Top CP, click để thay đổi mã trực tiếp trên Chart. Bàn luận về Amibroker, Metastock, Metatrader 4 2/5/23
    [Chia sẻ] Code Volume theo phong cách Dan Zanger và Pivot Pocket Volume Bàn luận về Amibroker, Metastock, Metatrader 4 29/3/23
    [Chia sẻ] Code tự động đánh dấu pivot đỉnh đáy như MarketSmith của IBD Bàn luận về Amibroker, Metastock, Metatrader 4 25/3/23

  3. nguyenjoe

    nguyenjoe Well-Known Member

    Tham gia ngày:
    18/7/21
    Bài viết:
    93
    Đã được thích:
    166
    Giới tính:
    Nam
    Hướng dẫn sử dụng:

    1. Bảng giá
    Bác nào chưa rành cách chỉnh sửa code hoặc thông thạo Amibroker nên dùng phiên bản Amibroker 6.2 nhé. Phiên bản này bảng giá vẫn để kiểu cũ là list danh sách mặc định nhập tay từ trước.

    Phiên bản 6.3:
    Bảng giá nâng cấp tự động lấy watchlist trong amibroker để thuận tiện sử dụng các bộ lọc tự động điền vào danh sách thay vì chỉnh sửa tay. Tuy nhiên vẫn có thể thêm bằng tay vào watchlist

    Hướng dẫn thêm danh sách tự động vào watchlist:
    Cách 1: Sử dụng code sau để tự động đẩy các mã theo ngành vào từng watchlist

    Mã:
    dkvol = V>100000 AND C*MA(V,50)>20000000 ;
    Filter= dkvol  ;
    _SECTION_END();
    listnum0 = 0;
    listnum1 = 1;
    listnum2 = 2;
    listnum3 = 3;
    listnum4 = 4;
    listnum5 = 5;
    listnum6 = 6;
    listnum7 = 7;
    listnum8 = 8;
    listnum9 = 9;
    listnum10 = 10;
    
    // erase the watchlist when we process very first symbol
    
    if( Status("action") == actionExplore )
    {
    if ( Status( "stocknum" ) == 0 )
    {
        // retrieve watchlist members
        list0 = CategoryGetSymbols( categoryWatchlist, listnum0 );
        list1 = CategoryGetSymbols( categoryWatchlist, listnum1 );
        list2 = CategoryGetSymbols( categoryWatchlist, listnum2 );
        list3 = CategoryGetSymbols( categoryWatchlist, listnum3 );
        list4 = CategoryGetSymbols( categoryWatchlist, listnum4 );
        list5 = CategoryGetSymbols( categoryWatchlist, listnum5 );
        list6 = CategoryGetSymbols( categoryWatchlist, listnum6 );
        list7 = CategoryGetSymbols( categoryWatchlist, listnum7 );
        list8 = CategoryGetSymbols( categoryWatchlist, listnum8 );
        list9 = CategoryGetSymbols( categoryWatchlist, listnum9 );
        list10 = CategoryGetSymbols( categoryWatchlist, listnum10 );
     
        // iterate through the list and remove tickers
        for ( i = 0; ( sym = StrExtract( list0, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum0 );
        }
        for ( i = 0; ( sym = StrExtract( list1, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum1 );
        }
        for ( i = 0; ( sym = StrExtract( list2, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum2 );
        }
        for ( i = 0; ( sym = StrExtract( list3, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum3 );
        }
        for ( i = 0; ( sym = StrExtract( list4, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum4 );
        }
        for ( i = 0; ( sym = StrExtract( list5, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum5 );
        }
        for ( i = 0; ( sym = StrExtract( list6, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum6 );
        }
        for ( i = 0; ( sym = StrExtract( list7, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum7 );
        }
         for ( i = 0; ( sym = StrExtract( list8, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum8 );
        }
        for ( i = 0; ( sym = StrExtract( list9, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum9 );
        }
        for ( i = 0; ( sym = StrExtract( list10, i ) ) != ""; i++ )
        {
            CategoryRemoveSymbol( sym, categoryWatchlist, listnum10 );
        }
    }
    
    // check how many times Filter variable was true in the tested range
    // if non-zero value detected, add current symbol to a watchlist
    if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) )  )
        {
            CategoryAddSymbol( "", categoryWatchlist, listnum0 );
     
            if ( StrFind(IndustryID(1) , "Ngan hang"))
            CategoryAddSymbol( "", categoryWatchlist, listnum1 );
         
            else if ( StrFind(IndustryID(1) , "Cong ty Chung khoan"))
                CategoryAddSymbol( "", categoryWatchlist, listnum2 );
         
            else if ( StrFind(IndustryID(1) , "Dau tu bat dong san va dich vu"))
                CategoryAddSymbol( "", categoryWatchlist, listnum3 );
         
            else if (StrFind (IndustryID(1) , "Xay dung va vat lieu xay dung"))
                CategoryAddSymbol( "", categoryWatchlist, listnum4 );
         
            else if(StrFind(IndustryID(1) , "Hoa chat") OR StrFind(IndustryID(1) , "Khai khoang")  OR StrFind(IndustryID(1) , "Kim loai cong nghiep") OR StrFind(IndustryID(1) , "Lam nghiep va giay"))
                CategoryAddSymbol( "", categoryWatchlist, listnum5 );
         
            else if( StrFind(IndustryID(1) , "Ban le chung") OR StrFind(IndustryID(1) , "Cong nghe phan cung va thiet bi")  OR StrFind(IndustryID(1) , "Phan mem va dich vu dien toan") )
                CategoryAddSymbol( "", categoryWatchlist, listnum6 );
         
            else if(StrFind(IndustryID(1) , "Nang luong thay the") OR StrFind(IndustryID(1) , "Thiet bi")  OR StrFind(IndustryID(1) , "San xuat dau khi") OR StrFind(IndustryID(1) , "Dien"))
                CategoryAddSymbol( "", categoryWatchlist, listnum7 );
         
            else if( StrFind(IndustryID(1) , "San xuat thuc pham") OR StrFind(IndustryID(1) , "Do dung ca nhan")  OR StrFind(IndustryID(1) , "Hang gia dung") OR StrFind(IndustryID(1) , "Oto va linh kien oto"))
                CategoryAddSymbol( "", categoryWatchlist, listnum8 );
         
            else if (StrFind (IndustryID(1) , "Van tai"))
                CategoryAddSymbol( "", categoryWatchlist, listnum9 );
         
            else
            CategoryAddSymbol( "", categoryWatchlist, listnum10 );
        }
    }
    Bác nào biết đọc code thì code này lọc thanh khoản trên 20 tỷ và đẩy các mã có tên mã ngành cụ thể vào các watchlist số 0 1 2 3 ...10. Mặc định mình làm theo tên do fireant cung cấp, nên nếu bác nào thấy ko ổn vì dùng data của bên khác dữ liệu không giống bị lỗi thì tạm dùng bản 6.2.

    Cách 2:

    Tự nhập tay bằng cách chuột phải vào watchlist và chọn Type-in symbols. Các mã cách nhau bởi dấu phẩy. Có thể copy list cũ của bản 6.2 cũng được nhé nhưng cần sửa tên tiêu đề một chút. Tránh rườm rà không biết sửa thì các bác dùng luôn bản 6.2

    2. Danh Mục
    Cấu trúc tham số của Danh Mục Đầu Tư là: Mã CP,Giá mua,Stoploss,Target|Mã CP,Giá mua,Stoploss,Target|Mã CP,Giá mua,Stoploss,Target|...

    Cấu trúc tham số của Danh Mục Theo dõi đơn giản hơn chỉ gồm: Mã CP,Pivot|Mã CP,Pivot|Mã CP,Pivot|...

    Các giá trị này phải nhập tay để xác định giá chặn để cảnh báo bắn tín hiệu Telegram. Phần tín hiệu Telegram thì các bác tham khảo lại bài cách tạo Bot và lấy ID Channel + lấy API

    https://kakata.vn/gui-tin-hieu-tu-amibroker-len-telegram.t4105.html

    Để chạy tự động thì dùng chức năng Explore và cài đặt auto-repeat
    Update: Nếu thay đổi danh mục hoặc các mức giá cài đặt thì cần reset lại parameter trong màn hình Explore để nó cập nhập mã và giá nhé các bác

    3. Top cổ phiếu có thể thay đổi chu kỳ lọc trong parameter mục list 1,2,3...period (mặc định 1, 5, 10, 21, 65, 120 ngày) và số lượng mã Top 1, top 2 (mặc định 15)
     
    Chỉnh sửa cuối: 12/7/23
    sumay2023 and luisnguyen09 like this.
  4. luisnguyen09

    luisnguyen09 Well-Known Member

    Tham gia ngày:
    13/8/22
    Bài viết:
    48
    Đã được thích:
    13
    Giới tính:
    Nam
    Thanks bác nhé, bản 6.3 mình click vào top cp danh mục ko dc mặc dù dùng ami 6.3, lại p chuyển lại bản 6.2
     
  5. nguyenjoe

    nguyenjoe Well-Known Member

    Tham gia ngày:
    18/7/21
    Bài viết:
    93
    Đã được thích:
    166
    Giới tính:
    Nam
    Thật ra dùng 6.2 cũng được rồi không khác mấy đâu bác
     
  6. A Hướng

    A Hướng Member

    Tham gia ngày:
    30/6/22
    Bài viết:
    18
    Đã được thích:
    9
    Giới tính:
    Nam
    Không dùng nhưng cũng đăng nhập cảm ơn bạn
     
    Hungtqhp thích bài này.
  7. minhputincic

    minhputincic Active Member

    Tham gia ngày:
    19/10/21
    Bài viết:
    29
    Đã được thích:
    11
    Giới tính:
    Nam
    Rất hay, dùng để tham thảo nhanh trước khi mua bán, tk bạn!
     
    Hungtqhp thích bài này.
  8. nghiktb

    nghiktb Member

    Tham gia ngày:
    23/9/21
    Bài viết:
    7
    Đã được thích:
    1
    Giới tính:
    Nam
    Phần bảng giá của mình hiển thị chỉ được 3 ngành là Ngân hàng, chứng khoán và BDS thôi bạn, bạn chỉ cho mình có cách nào hiển thị hết được ko. Cảm ơn bạn!
     
  9. nghiktb

    nghiktb Member

    Tham gia ngày:
    23/9/21
    Bài viết:
    7
    Đã được thích:
    1
    Giới tính:
    Nam
    Ah mình làm dc mà nó ko có thanh cuộn nên hiện nhiều dòng thì chữ nó bé xíu
     
  10. sunsun

    sunsun New Member

    Tham gia ngày:
    3/9/21
    Bài viết:
    1
    Đã được thích:
    0
    Giới tính:
    Nam
    upload_2023-7-16_22-36-23.png

    Khi mình click vào từng mã thì nó báo lỗi như trên. Nhờ bạn chỉ giúp ạ. Cảm ơn bạn
     
  11. nguyenjoe

    nguyenjoe Well-Known Member

    Tham gia ngày:
    18/7/21
    Bài viết:
    93
    Đã được thích:
    166
    Giới tính:
    Nam
    upload_2023-7-18_22-47-21.png
    vào parameter chỉnh chiều cao và độ rộng cho phù hợp nhé bạn
     
    Đoàn Phú Hải thích bài này.
  12. tumap

    tumap Member

    Tham gia ngày:
    10/10/21
    Bài viết:
    5
    Đã được thích:
    2
    Giới tính:
    Nam
    upload_2023-11-13_15-27-35.png
    e quét thì bị lỗi như trên bác ơi
    upload_2023-11-13_15-28-35.png
     
  13. Hungtqhp

    Hungtqhp Well-Known Member

    Tham gia ngày:
    17/8/21
    Bài viết:
    127
    Đã được thích:
    43
    Giới tính:
    Nam
    Cảm ơn bạn.
     
  14. Nguyns

    Nguyns Member

    Tham gia ngày:
    21/6/23
    Bài viết:
    20
    Đã được thích:
    0
    Giới tính:
    Nam
    Cám ơn bạn Nguyễn Dâu.
     
  15. dungcv

    dungcv Member

    Tham gia ngày:
    16/11/23
    Bài viết:
    12
    Đã được thích:
    0
    Giới tính:
    Nam
    like
     

Lượt bình luận : 13

Chia sẻ trang này