trendline-amibroker.txt
Short Description
Amibroker afl for trendline. Auto trendline...
Description
_SECTION_BEGIN("Price"); _SECTION_BEGIN("Price"); SetChartOptions(0,chartShowArrows|chartShowDates); _N(Title = StrFormat("{{NAME}} StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Cl ose %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedVa lue( ROC( C, 1 )) )); SMA = MA(34,500); trendup = IIf(CCI(50) > 50 AND RSI(14) > 50, colorBlue, colorDarkGreen); trendcolor = IIf( CCI(50) < 50 AND RSI(14) < 50, colorRed, trendup); Plot( C, "Close", trendcolor, styleCandle | styleThick ); if( ParamToggle("Tooltip shows", "All Values | Only Prices" ) ) { ToolTip=StrFormat("Open: ToolTip=StrFormat("Ope n: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+Nu mToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ))); } _SECTION_END(); SetChartBkColor(ParamColor("Panel SetChartBkColor(ParamC olor("Panel color ",colorBlack)); PlotOHLC( Open, High, Low, Close, "", colorWhite, styleCandle| styleThick ); _SECTION_BEGIN("Price"); _SECTION_BEGIN("Price" ); SetChartOptions(0,chartShowArrows|chartShowDates); _N(Title = StrFormat("{{NAME}} StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Cl ose %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )); Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle( "Style") | GetPriceStyle() ); _SECTION_END(); _SECTION_BEGIN("TREND"); _SECTION_BEGIN("TREND" ); SetBarsRequired(100000,0); GraphXSpace = 15; ea = TEMA(C,7); eb = TEMA(C,16); SetBarFillColor( IIf( ea > eb, colorGreen, colorRed ) ); Plot( C, "Price", IIf( ea > eb, colorGreen, colorRed ), styleCandle ); Buy = ea > eb AND TimeNum() > 085000 AND TimeNum() < 125000; Sell = eb > ea OR TimeNum() > 125000; Short = 0; Cover = 0; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); Short = ExRem(Short,Cover); Cover = ExRem(Cover,Short); SetTradeDelays(0,0,0,0); _N(Title = StrFormat("{{NAME}} StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Cl ose %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )); Factor=Param("Factor",4,1,10,1); Pd=Param("ATR Periods",15,1,1000,1); Up=(H+L)/2+(Factor*ATR(Pd)); Dn=(H+L)/2-(Factor*ATR(Pd)); iATR=ATR(Pd); TrendUp=TrendDown=Null; trend[0]=1; changeOfTrend=0; flag=flagh=0; for (i = 1; i Up[i-1]) { trend[i]=1; if (trend[i-1] == -1) changeOfTrend = 1; }
else if (Close[i]0 && trend[i-1]0 && Dn[i]1;i--) { if(Buy[i] == 1) { entry = C[i]; sig = "BUY"; sl = TrendSL[i]; tar1 = entry + (entry * .0050); tar2 = entry + (entry * .0092); tar3 = entry + (entry * .0179); bars = i; i = 0; } if(Sell[i] == 1) { sig = "SELL"; entry = C[i]; sl = TrendSL[i]; tar1 = entry - (entry * .0050); tar2 = entry - (entry * .0112); tar3 = entry - (entry * .0212); bars = i; i = 0; } } Offset = -20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1)); sl = ssl[BarCount-1]; Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleLin e, Null, Null, Offset); //Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleD ots, Null, Null, Offset); //Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleD ots, Null, Null, Offset); //Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|s tyleLine, Null, Null, Offset); //Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLi ne|styleLine, Null, Null, Offset);
for (i=bars; i Open, Close, Open); // Top of open/close array bi = BarIndex(); startIx = BeginValue(bi) - bi[0]; endIx = EndValue(bi) - bi[0]; if (endIx < startIx) endIx = startIx; GP_changeAtr = 1+5*(ATR(3)/Close); eend = EMA(Close, endEma*GP_changeAtr[endIx]); // EMA period for end direction lrs = LinRegSlope(eend, 2); isUp = lrs[endIx] >= 0; // Slope of EMA on last day fit = GP_DrawTrendLines(Bottom, Top, lineCnt, endIx, startIx, tchg, oshoot, clos eOver, 0, isUp, Prefs(24)); for (i = 0; i < startIx; i++) { GP_tlineUp1[i] = -1e10; GP_tlineUp2[i] = -1e10; GP_tlineDown1[i] = -1e10; GP_tlineDown2[i] = -1e10; GP_closeAbove[i] = 0; } for (i = endIx+1; i < BarCount; i++) { GP_tlineUp1[i] = -1e10; GP_tlineUp2[i] = -1e10; GP_tlineDown1[i] = -1e10; GP_tlineDown2[i] = -1e10; GP_closeAbove[i] = 0; } Plot(GP_tlineUp1, "", colorDarkBlue, styleLine|styleThick); Plot(GP_tlineUp2, "", colorDarkBlue, styleLine|styleThick); Plot(GP_tlineDown1, "", colorDarkRed, styleLine|styleThick); Plot(GP_tlineDown2, "", colorDarkRed, styleLine|styleThick); _SECTION_BEGIN("INIT"); SetChartOptions(0,chartShowArrows|chartShowDates); ScanLookBack = Param("Scan Lookback", 2, 1, 25 ); fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2); _SECTION_END(); _SECTION_BEGIN("Price"); SetChartOptions(0,chartShowArrows|chartShowDates); _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("Up Trend Line"); UTValue1=LastValue(Trough(L,0.5,2)); UTValue2=LastValue(Trough(L,0.5,1)); UTBar1=BarCount - 1 - LastValue(TroughBars(L,0.5 ,2)); UTBar2=BarCount - 1 - LastValue(TroughBars(L,0.5 ,1)); UpTrendLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 1 ); UTLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 0 ); Plot( UpTrendLine , _DEFAULT_NAME(), colorGreen,styleLine | styleNoTitle | styleNoLabel); Plot( UTLine , _DEFAULT_NAME(), colorGreen,styleLine | styleNoTitle | styleNoLabel); _SECTION_END(); _SECTION_BEGIN("Down Trend Line"); DTValue1=LastValue(Peak(H,0.5 ,2)); DTValue2=LastValue(Peak(H,0.5 ,1)); DTBar1=BarCount - 1 - LastValue(PeakBars(H,0.5 ,2));
DTBar2=BarCount - 1 - LastValue(PeakBars(H,0.5 ,1)); DownTrendLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 1 ); DTLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 0 ); Plot( DownTrendLine ,_DEFAULT_NAME(), colorRed,styleLine | styleNoTitle | styleNoLabel); Plot( DTLine ,_DEFAULT_NAME(), colorRed,styleLine | styleNoTitle | styleNoLabel); PlotText("PV = " + WriteVal(DTValue2 ,fraction), LastValue(BarIndex())+2, (DTValue2 ), colorRed); PlotText("TV = " + WriteVal(UTValue2,fraction), LastValue(BarIndex())+2, UTValue2, colorGreen); PlotOHLC( UpTrendLine , UpTrendLine , DownTrendLine , DownTrendLine , "", ColorBlend( colorGreen, colorLightYellow, 0.9 ), styleCloud | styleNoRescale); Plot(LineArray( DTBar2, DTValue2, BarCount,DTValue2, 0 ),"",colorRed); Plot(LineArray( UTBar2, UTValue2, BarCount,UTValue2, 0 ),"",colorGreen); _SECTION_END(); _SECTION_BEGIN("Pivot"); YH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high YL = TimeFrameGetPrice("L", inDaily, -1); // low YC = TimeFrameGetPrice("C", inDaily, -1); // close TO = 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"); _SECTION_END(); _SECTION_BEGIN("Target"); CBuy = Cross(C,DownTrendLine); CSell = Cross(UpTrendLine ,C); baratbuy = ValueWhen(CBuy ,BarIndex()) ; baratsell = ValueWhen(CSell ,BarIndex()) ; _SECTION_END(); _SECTION_BEGIN("Pivot"); YH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high YL = TimeFrameGetPrice("L", inDaily, -1); // low YC = TimeFrameGetPrice("C", inDaily, -1); // close TO = 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"); Title = EncodeColor(colorWhite)+ Date() + " Close = " + EncodeColor(colorRed) +Close + EncodeColor(colorWhite) + " Open = " + EncodeColor(colorRed) + O +
EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H + EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L + EncodeColor(colorWhite) + " Volume = " + EncodeColor(colorRed) + V + "\n\n"+ EncodeColor(colorWhite) + "Pivot Point= " + EncodeColor(colorBlue) + PP + EncodeColor(colorWhite) + " Day's Open= " + EncodeColor(colorBlue) + TO +"\n\n"+ EncodeColor(colorGreen) + "If days open is greater than Pivot Point, market is i n uptrend AND \n"+EncodeColor(colorRed)+"if days Open is less than PivotPoint, m arket is in downtrend" +"\n\n"+ EncodeColor(colorRed) + "R1= " + EncodeColor(colorBlue) + R1 + EncodeColor(colorRed) + " R2= " + EncodeColor(colorBlue) + R2 + EncodeColor(colorRed) + " R3= " + EncodeColor(colorBlue) + R3 +"\n"+ EncodeColor(colorGreen) + "S1= " + EncodeColor(colorBlue) + S1 + EncodeColor(colorGreen) + " S2= " + EncodeColor(colorBlue) + S2 + EncodeColor(colorGreen) + " S3= " + EncodeColor(colorBlue) + S3 +"\n"+ EncodeColor( colorWhite) +"____ _____ _______ _______ _______"+"\n"; _SECTION_END(); _SECTION_BEGIN("Target"); CBuy = Cross(C,DownTrendLine); CSell = Cross(UpTrendLine ,C); baratbuy = ValueWhen(CBuy ,BarIndex()) ; baratsell = ValueWhen(CSell ,BarIndex()) ; _SECTION_END(); _SECTION_BEGIN("Auto"); Buy = ( CBuy ) AND ( (BarCount - baratbuy )
View more...
Comments