• Breaking News

    Thursday, 19 March 2015

    Sử dụng Intraday Fibonacii Trend Break System (amibroker code)

    amibroker code : Sử dụng Intraday Fibonacii Trend Break Systemtrong phân tích kỹ thuật
               Intraday Fibonacii Trend là một chỉ báo kỹ thuật dựa trên đáy và đỉnh đôi được nối với nhau tạo thành hình phễu và sử dụng Heikin Ashi để xác nhận giá. 

            - Chép code sau ( Để tiện theo dõi bài viết mình để code này trong khung cuối bài ) .

            - Copy và dán vào Formular editor và lưu lại - Chương trình sẽ lưu theo mặc định : Program files\Amibroker\formulas\Intraday Fibonacii Trend Break System ( AFL).

    http://www.v2htrader.com/search/label/amibroker%20code



     Code sử dụng :

    Intraday Fibonacii Trend Break System for Amibroker (AFL)

    --------------------------------------------------------------------------------------------------------------------------
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275

    /**
    *
    Author : Nishant Kulkarni (nishantndk@yahoo.com)
    Intraday Fibonacii Trend Break System. This system is based on the double bottom and double top detection technique and fibonacii internal external by David K.
    A line joining two tops when connected together and another line joining bottom line is connected together and when both line extended forms a funnel and
    a break outside gives very strong break out.
    It is recomended to have Heikin Ashi plot bellow main price plot as confirmation. Big heikin ashi candles confirm price movement.
    Note: Use 1 Hour interval for more stable results.
    Disclaimer – Trade with caution. Author does not take any responsibility. The system is to guide traders and does not
    guaranty any performance. The system is used in Indian market condition. For other markets, may need to be altered slightly. However I am personally using this system and booking profit, hence contributing
    this formula for community as give back.
    The system also makes use of Fibonacci Internal and External Retracements formula by David K.
    Visit : http://www.myinvestmentmanager.com  for investment tips in Indian market.
    */
    _SECTION_BEGIN("INIT");
        SetChartOptions(0,chartShowArrows|chartShowDates);
        fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
        tchoice=Param("Title Selection ",2,1,2,1);
        PlotCandle = ParamToggle("Plot Nifty Candle", "No,Yes", 0);
    _SECTION_END();
    _SECTION_BEGIN("Price");
        _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));  
        Plot( C, _DEFAULT_NAME(), colorBlack , styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
    _SECTION_END();
    _SECTION_BEGIN("Index_Compare");
        IndexName = ParamList("IndexName ","^NSEI|^NSEBANK|^CNXIT|",0);
        PlotForeign(IndexName,_DEFAULT_NAME(),colorBrightGreen , styleNoTitle | styleOwnScale | styleLine | styleThick );
    _SECTION_END();
    _SECTION_BEGIN("BBands");
        P = ParamField("Price field",-1);
        Periods = Param("Periods", 15, 2, 100, 1 );
        Width = Param("Width", 2, 0, 10, 0.05 );
        Color = ParamColor("Color", colorLightGrey );
        Style = ParamStyle("Style", styleNoRescale | styleNoTitle | styleNoLabel | styleThick);
        BBTop = BBandTop( P, Periods, Width );
        BBBot = BBandBot( P, Periods, Width );
        BBMiddle = BBBot + ((BBTop-BBBot)/2);
        Plot(BBTop , "BBTop" + _PARAM_VALUES(), Color, Style );
        Plot(BBBot, "BBBot" + _PARAM_VALUES(), Color, Style );
        Plot(BBMiddle , "BBMiddle" + _PARAM_VALUES(), Color, Style );
         
    _SECTION_END();
    _SECTION_BEGIN("Fib Retracements");
        fibs = ParamToggle("Plot Fibs","Off|On",1);
        pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
        HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
        pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
        LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
        Back = Param ("Extend Left = 2",1,1,500,1);
        Fwd  = Param("Plot Forward", 0, 0, 500, 1);
        text = ParamToggle("Plot Text","Off|On",1);
        hts  = Param ("Text Shift", -33.5,-50,50,0.10);
        style =ParamStyle("Line Style",styleLine,styleNoLabel);
        x = BarIndex();
        pRp  = PeakBars( H, pctH, 1) == 0;
        yRp0 = LastValue(ValueWhen( pRp, H, HiLB));
        xRp0 = LastValue(ValueWhen( pRp, x, HiLB));
        pSp  = TroughBars( L, pctL, 1) == 0;
        ySp0 = LastValue(ValueWhen( pSp, L, LoLB));
        xSp0 = LastValue(ValueWhen( pSp, x, LoLB));
        Delta = yRp0 - ySp0;
        function fib(ret) {
            retval = (Delta * ret);
            Fibval = IIf(ret < 1.0
            AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
            AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
            AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
            AND xSp0 > xRp0, ySp0 + retval, Null))));
            return FibVal;
        }
        x0 = Min(xSp0,xRp0)-Back;
        x1 = (BarCount -1);
        //////////////////////////////////////////////////////////////////
        r236 = fib(0.236);  r236I = LastValue (r236,1);
        r382 = fib(0.382);  r382I = LastValue (r382,1);
        r050 = fib(0.50);       r050I = LastValue (r050,1);
        r618 = fib(0.618);  r618I = LastValue (r618,1);
        r786 = fib(0.786);  r786I = LastValue (r786,1);
        e127 = fib(1.27);       e127I = LastValue (e127,1);
        e162 = fib(1.62);       e162I = LastValue (e162,1);
        e200 = fib(2.00);       e200I = LastValue (e200,1);
        e262 = fib(2.62);       e262I = LastValue (e262,1);
        e424 = fib(4.24);       e424I = LastValue (e424,1);
        //////////////////////////////////////////////////////////////////
        p00 = IIf(xSp0 > xRp0,ySp0,yRp0);    p00I = LastValue (p00,1);
        p100 = IIf(xSp0 < xRp0,ySp0,yRp0);   p100I = LastValue (p100,1);
        color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
        color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
        //////////////////////////////////////////////////////////////////
        numbars = LastValue(Cum(Status("barvisible")));
        fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
        //////////////////////////////////////////////////////////////////
        if(fibs==1) {
            Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,styleThick | styleNoRescale | styleNoLabel | styleNoTitle,Null, Null,Fwd);
            Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27, styleThick | styleNoRescale | styleNoLabel | styleNoTitle,Null, Null,Fwd);     
            Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
            Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);      
        }
        //////////////////////////////////////////////////////////////////
        if(text==1) {
            PlotText(" 0% = " + WriteVal(p00,fraction),     LastValue(BarIndex())-(numbars/hts), p00I  + 0.05, color00);
            PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, colorBlack);
            PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, colorBlack);
            PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, colorBlack);
            PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, colorBlack);
            PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, colorBlack);
            PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
            PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, colorBlack);
            PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, colorBlack);
            PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, colorBlack);
            PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, colorBlack);
            PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, colorBlack);
        }
    _SECTION_END();
    _SECTION_BEGIN("Pivot");
        YH = TimeFrameGetPrice("H", inDaily, -1);       // yesterdays high
        YL = TimeFrameGetPrice("L", inDaily, -1);       //              low
        YC = TimeFrameGetPrice("C", inDaily, -1);       //              close
        YO = TimeFrameGetPrice("O", inDaily);           // current day open
        //Normal Pivot
        PP = (YH + YL + YC) / 3;
        R1 = (2 * PP) - YL;
        R2 = PP + (YH - YL);
        R3 = YH + 2*(PP-YL);
        S1 = (2 * PP) - YH;
        S2 = PP - (YH - YL);
        S3 = YL - 2*(YH - PP) ;
         
    _SECTION_END();
    _SECTION_BEGIN("TITLE");
        //////////////////////////////////////////////////////////////////
        if (tchoice==1 )    {
            _N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} -   {{INTERVAL}}      {{DATE}}    Open:  %g,    High:  %g,     Low:  %g,     Close:  %g     {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1   ) ) ));
        }
        //////////////////////////////////////////////////////////////////WriteVal(HC ,fraction)
        if (tchoice==2 ) {
            Title = EncodeColor(colorBlack)+ Date() + "   Close = " + EncodeColor(colorRed) +Close +
            EncodeColor(colorBlack) + "     Open = " + EncodeColor(colorBlack) + O +
            EncodeColor(colorBlack) + "     High = " + EncodeColor(5) + H +
            EncodeColor(colorBlack) + "      Low = " + EncodeColor(colorRed) + L +
            EncodeColor(colorBlack) + "     Volume = " + EncodeColor(colorBlack) + V + "\n\n"+
            EncodeColor(colorBlack) + "Pivot Point= " + EncodeColor(colorBlack) + PP +
            EncodeColor(colorBlack) + "     Day's Open= " + EncodeColor(colorBlack) + YO +
            EncodeColor(colorBlack) + "     Nifty = " + EncodeColor(colorBlack) + Foreign("^NSEI","C") +"\n\n"+
            EncodeColor(colorRed) + "R1= " + EncodeColor(colorBlack) + R1 +
            EncodeColor(colorRed) + "  R2= " + EncodeColor(colorBlack) + R2 +
            EncodeColor(colorRed) + "  R3= " + EncodeColor(colorBlack) + R3 +"\n"+
            EncodeColor(colorGreen) + "S1= " + EncodeColor(colorBlack) + S1 +
            EncodeColor(colorGreen) + "  S2= " + EncodeColor(colorBlack) + S2 +
            EncodeColor(colorGreen) + "  S3= " + EncodeColor(colorBlack) + S3 +"\n"+
            EncodeColor( colorBlack) +"_______________"+"\n"+
            EncodeColor( colorBlack)  + "424%   =  "    +   EncodeColor(25)+ e424 + " " +"\n"+
            EncodeColor( colorBlack)  + "262%   =  "    +   EncodeColor(47)+ e262 + " " +"\n"+
            EncodeColor( colorBlack)  + "200%   =  "    +   EncodeColor(47)+ e200 + " " +"\n"+
            EncodeColor( colorBlack)  + "162%   =  "    +   EncodeColor(47)+ e162 + " " +"\n"+
            EncodeColor( colorBlack)  + "127%   =  "    +   EncodeColor(47)+ e127 + " " +"\n"+
            EncodeColor( colorRed) + "Res    =  "   +   EncodeColor(32)+ p100 + " "+"\n"+
            EncodeColor( colorBlack)  + "78%   =  " +   EncodeColor(42)+ r786 + " " +"\n"+
            EncodeColor( colorBlack)  + "62%   =  " +   EncodeColor(43)+ r618 + " "+"\n"+
            EncodeColor( colorBlack)  + "50%   =  " +   EncodeColor(41)+ r050 + " "+"\n"+
            EncodeColor( colorBlack)  + "38%   =  " +   EncodeColor(44)+ r382 + " "+"\n"+
            EncodeColor( colorBlack)  + "23%   =  " +   EncodeColor(45)+ r236+ " " +"\n"+
            EncodeColor( colorGreen) + "Sup   =   " +   EncodeColor(34)+ p00 + " " ;
        }
    _SECTION_END();
    _SECTION_BEGIN("Up Trend Line");
        UTValue1=LastValue(Trough(L,1,2)); 
        UTValue2=ySp0;
        UTBar1=BarCount - 1 - LastValue(TroughBars(L,1,2));
        price_utbar1=Close[UTBar1];
        UTBar2=xSp0;
        price_utbar2=Close[UTBar2];
        UpTrendLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 1 );
        UTLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 0 );
        Plot( UpTrendLine , _DEFAULT_NAME(), colorGreen,styleDots | styleNoTitle | styleNoLabel);
        Plot( UTLine , _DEFAULT_NAME(), colorGreen,styleDots | styleNoTitle | styleNoLabel);
    _SECTION_END();
    _SECTION_BEGIN("Down Trend Line");
        DTValue1=LastValue(Peak(H,1,2));
        DTValue2=yRp0;
        DTBar1=BarCount - 1 - LastValue(PeakBars(H,1,2));  
        price_dtbar1=Close[DTBar1];
        DTBar2=xRp0;
        price_dtbar2=Close[DTBar2];
        DownTrendLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 1 );
        DTLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 0 );
        Plot( DownTrendLine ,_DEFAULT_NAME(), colorRed,styleDots | styleNoTitle | styleNoLabel);
        Plot( DTLine ,_DEFAULT_NAME(), colorRed,styleDots | styleNoTitle | styleNoLabel);
        PlotOHLC( DownTrendLine , DownTrendLine , UpTrendLine , UpTrendLine , "", colorYellow, styleCloud | styleNoRescale);   
         
        DTLine = LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back);
        UTLine = LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back);
         
         
        CBuy = Cross(C,DownTrendLine );
        CSell = Cross(UpTrendLine ,C);
        baratcbuy = LastValue(ValueWhen(CBuy,BarIndex())); 
        baratcsell = LastValue(ValueWhen(CSell,BarIndex()));
        CBuy = CBuy AND BarIndex() == baratcbuy ;
        CSell = CSell AND BarIndex() == baratcsell ;
        PlotShapes(shapeUpTriangle* CBuy ,colorBlue,O,L);
        PlotShapes(shapeDownTriangle* CSell ,colorRed,O,H);
        CBuy1 = Cross(C,DTLine );
        CSell1 = Cross(UTLine ,C);
         
        baratcbuy1 = LastValue(ValueWhen(CBuy1,BarIndex()));   
        baratcsell1 = LastValue(ValueWhen(CSell1,BarIndex()));
        CBuy1 = CBuy1 AND BarIndex() == baratcbuy1 ;
        CSell1 = CSell1 AND BarIndex() == baratcsell1 ;
        PlotShapes(shapeHollowUpTriangle* CBuy1 ,colorBlue,O,L-1);
        PlotShapes(shapeHollowDownTriangle* CSell1 ,colorRed,O,H-1);
    _SECTION_END();
    _SECTION_BEGIN("Auto");
        ScanLookBack = Param("Scan Lookback", 1, 1, 25 );
        Buy  = ( CBuy OR CBuy1) AND  ( (BarCount - baratcBuy )<=ScanLookBack  OR (BarCount - baratcbuy1 )<=ScanLookBack);
        Sell = ( CSell OR CSell1) AND  ( (BarCount - baratcsell )<=ScanLookBack  OR (BarCount - baratcsell1 )<=ScanLookBack ) ;
        price = C[BarCount-1];
        AlertIf(Buy,"","Buy @"+C+"  Price @ Trigger="+price,1);
        AlertIf(Sell,"","Sell @"+C+"  Price @ Trigger="+price,2);
        Filter =  Buy OR Sell ;
        Var = WriteIf(Buy,"BUY",WriteIf(Sell,"SELL",""));
        AddTextColumn( Var , "Buy/Sell", 1.2 , colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));   
        AddColumn(price ,"Price",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
        AddColumn(C ,"Price @ Trigger",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
        stoploss = IIf(Buy, (price  * (1-0.01)) , IIf(Sell, (price  * (1+0.01)),0));
        target1per = IIf(Buy, (price  * (1+0.01)) , IIf(Sell, (price  * (1-0.01)),0));
        target15per = IIf(Buy, (price  * (1+0.015)) , IIf(Sell, (price * (1-0.015)),0));
        target2per = IIf(Buy, (price  * (1+0.02)) , IIf(Sell, (price  * (1-0.02)),0));
         
        AddColumn(stoploss ,"Stop Loss",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
        AddColumn(target1per ,"1% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
        AddColumn(target15per ,"1.5% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
        AddColumn(target2per ,"2% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
        AddColumn(V ,"Volume",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
         
    _SECTION_END();
    GraphXSpace = 10 ;

    No comments:

    Tin chứng khoán

    Tìm hiểu Quỹ đầu tư