• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Tìm hiểu thêm.

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

traders

Administrator
Thành viên BQT
Tham gia ngày
29/4/17
Bài viết
224
Thích
3
Điểm
18
Website
traders.vn
#1
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.amibroker.com/library/detail.php?id=1084

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();

GraphXSpa
 
Top