harmonic pattern afl

Download Harmonic Pattern Afl

If you can't read please download the document

Upload: nettravellers

Post on 09-Dec-2015

113 views

Category:

Documents


37 download

DESCRIPTION

AFL for Harmonic Pattern

TRANSCRIPT

/* HARMONIC PATTERN DETECTION Automatic Detection of Harmonic Patterns - Gartley, Bat, Butterfly and Crab. Zig Zag is not used in this AFL. It is based on fractals Contact - [email protected] */ _SECTION_BEGIN("Price");SetChartOptions(0,chartShowArrows|chartShowDates);_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );_SECTION_END(); _SECTION_BEGIN("Gartley"); GBmin = Param("Swing B Min.",0.55,0.3,1,0.01);GBmax = Param("Swing B Max.",0.72,0.4,1,0.01);GCmin = Param("Swing C Min.",0.38,0.3,1.27,0.01);GCmax = Param("Swing C Max.",1.0,0.4,1.27,0.01);GDmin = Param("Swing D Min.(XA)",0.55,0.3,1,0.01);GDmax = Param("Swing D Max.(XA)",1.0,0.4,1.0,0.01); _SECTION_END(); _SECTION_BEGIN("Bat"); BatBmin = Param("Swing B Min.",0.38,0.3,1,0.01);BatBmax = Param("Swing B Max.",0.55,0.4,1,0.01);BatCmin = Param("Swing C Min.",0.38,0.3,1.62,0.01);BatCmax = Param("Swing C Max.",1.27,0.4,1.62,0.01);BatDmin = Param("Swing D Min.(XA)",0.5,0.3,1,0.01);BatDmax = Param("Swing D Max.(XA)",1.0,0.4,1.0,0.01); _SECTION_END(); _SECTION_BEGIN("Butterfly"); BtBmin = Param("Swing B Min.",0.55,0.3,1,0.01);BtBmax = Param("Swing B Max.",0.9,0.4,1,0.01);BtCmin = Param("Swing C Min.",0.38,0.3,1.62,0.01);BtCmax = Param("Swing C Max.",1.27,0.4,1.62,0.01);BtDmin = Param("Swing D Min.(XA)",1,1,1.8,0.01);BtDmax = Param("Swing D Max.(XA)",1.8,1,1.8,0.01); // Max XA of Butterfly = (1.0 - 1.618) _SECTION_END(); _SECTION_BEGIN("Crab"); CBmin = Param("Swing B Min.",0.38,0.3,1,0.01);CBmax = Param("Swing B Max.",0.65,0.4,1,0.01);CCmin = Param("Swing C Min.",0.38,0.3,1.62,0.01);CCmax = Param("Swing C Max.",1.270,0.4,1.62,0.01);CDmin = Param("Swing D Min.(XA)",1.25,1,1.8,0.01);CDmax = Param("Swing D Max.(XA)",1.8,1,2,0.01); _SECTION_END(); _SECTION_BEGIN("AB=CD"); abcd_Cmin = Param("Swing C Min.",0.3, 0.3 , 1, 0.01);abcd_Cmax = Param("Swing C Max.",0.8, 0.8 , 1, 0.01);abcd_Dmin = Param("Swing D Min.",1.2, 1, 2.7, 0.01);abcd_Dmax = Param("Swing D Max.",3.7, 1, 4, 0.01); _SECTION_END(); _SECTION_BEGIN("Patterns"); //strength = Param("Strength",5,2,15,1); // Best use: 3, 4, 5strength = Param("BARS of each LINE",5,2,15,1); // So luong bar cho moi duong XA, AB, BC,bu = ParamToggle("Bullish Pattern","Off|On",1); // So bar/lines se quyet dinh. mo^ hinh` duoc ve the' nao`be = ParamToggle("Bearish Pattern","Off|On",1); bi = Cum(1)-1; function GetTop(bars) // Lay' gia' tri cao nhat' = di?nh { Top = H == HHV(H,2*bars) AND Ref(HHV(H,bars),bars) < H; Top = Top AND LastValue(bi)-ValueWhen(Top,bi) > bars; return Top; } function GetValley(bars) // La'y gia tri thap' nhat' = day' { Valley = L == LLV(L,2*bars) AND Ref(LLV(L,bars),bars) > L; Valley = Valley AND LastValue(bi)-ValueWhen(Valley,bi) > bars; return Valley; } // Build fractals array P1 = GetTop(strength); // so' bar cho 1 duong` XA, AB, BC, CDV1 = GetValley(Strength); P1 = IIf(P1,IIf(ValueWhen(P1,bi,2) < ValueWhen(V1,bi),P1,IIf(ValueWhen(P1,H,2) > H,False,P1)),P1);P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);V1 = IIf(V1,IIf(ValueWhen(V1,bi,2) < ValueWhen(P1,bi),V1,IIf(ValueWhen(V1,L,2) bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) V1Bar1 AND V1Bar1 > P1Bar2 AND P1bar2 > V1Bar2) AND P1; // Peaks and troughs are in order myAX = P1H2-V1L2;myAB = P1H2-V1L1;myBC = P1H1-V1L1; myAB_AX = myAB/ myAX;myBC_AB = myBC/ myAB; BullGartley4 = PTvalid AND ( myAB_AX > GBmin ) AND ( myAB_AX < GBmax ) AND ( myBC_AB > GCMin ) AND ( myBC_AB < GCMax ); BullBat4 = PTvalid AND ( myAB_AX > BatBmin ) AND ( myAB_AX < BatBmax ) AND ( myBC_AB > BatCMin ) AND ( myBC_AB < BatCMax ); BullButterfly4 = PTvalid AND ( myAB_AX > BtBmin ) AND ( myAB_AX < BtBMax ) AND ( myBC_AB > BtCmin ) AND ( myBC_AB < BtCmin ); BullCrab4 = PTvalid AND ( myAB_AX > CBmin ) AND ( myAB_AX < CBmax ) AND ( myBC_AB > CCmin ) AND ( myBC_AB < CCmax ); BullABCD4 = PTvalid AND ( myBC_AB > abcd_Cmin) AND ( myBC_AB < abcd_Cmax ); strPattern = ""; //==================================================// BULLISH ABCD// Bullish pattern found. D retracement level is not evaluated//================================================== dHigh = HighestSince(BullABCD4,H); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince(BullABCD4,L); myC = ValueWhen(BullABCD4,P1H1); myB = ValueWhen(BullABCD4,V1L1); myA = ValueWhen(BullABCD4,P1H2); myX = ValueWhen(BullABCD4,V1L2); myCB = myC - myB; my_d_min = myCB * abcd_DMin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myCB * abcd_DMax ; my_Cd_min = myC - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Cd_max = myC - my_d_max; BullABCD = IIf( ( dLow < my_Cd_min ) AND ( dLow > my_Cd_max ) AND ( dHigh min my_d_max = myAX * GDMax; my_Ad_min = myA - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA - my_d_max; BullGartley = IIf( ( dLow < my_Ad_min ) AND ( dLow > my_Ad_max ) AND ( dHigh min my_d_max = myAX * BtDmax ; my_Ad_min = myA - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA - my_d_max; BullButterfly = IIf( ( dLow < my_Ad_min ) AND ( dLow > my_Ad_max ) AND ( dHigh Ref(res,-1),1,IIf(C(tsl) ,colorWhite, IIf(( tsl )>( C ), colorOrange,colorYellow)); _SECTION_END(); MAPeriod = Param("MA Period", 4, 1, 100);MAOpen = EMA(Open, MAPeriod);MAHigh = EMA(High, MAPeriod);MALow = EMA(Low, MAPeriod);MAClose = EMA(Close, MAPeriod); HaClose = (MAOpen + MAHigh + MALow + MAClose) / 4;HaOpen = AMA(Ref(HaClose, -1), 0.5); // for graph collapse//for(i = 0; i Ref(HaHigh,-1) AND Ref(HaHigh,1) < HaHigh;//PeakPKV0 = ValueWhen(PK,HaHigh,0);//PeakValue0PKV1 = ValueWhen(PK,HaHigh,1);//PeakValue1PKV2 = ValueWhen(PK,HaHigh,2);//PeakValue2MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeakMPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValueMPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDateSD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDatePlot(SD, "LastMinorResistance",colorRed,styleLine,styleThick); //PLOT THE SECOND LAST MAJOR PEAK RESISTANCE LINEMPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValueMPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDateSD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDatePlot(SD2, "LastMajorResistance",colorRed,styleLine);_SECTION_END(); _SECTION_BEGIN("Support");SP = Ref(HaLow,1) > HaLow AND HaLow < Ref(HaLow,-1);//PeakSPV0 = ValueWhen(SP,HaLow,0);//PeakValue0SPV1 = ValueWhen(SP,HaLow,1);//PeakValue1SPV2 = ValueWhen(SP,HaLow,2);//PeakValue2MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeakMSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));Plot(SD,"LastMinorSupport",colorGreen,styleLine,styleThick); MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));Plot(SD2,"LastMajorSupport",colorGreen,styleLine); _SECTION_END(); //ESSENTIAL TRADER TOOLS//// Compiled by K.Vidyasagar, [email protected] ////Previous Days HI LO // DayH = TimeFrameGetPrice("H", inDaily, -1); DayHI = LastValue (DayH,1);// yesterdays highDayL = TimeFrameGetPrice("L", inDaily, -1); DayLI = LastValue (DayL,1); // yesterdays lowDayC = TimeFrameGetPrice("C", inDaily, -1); // yesterdays closeDayO = TimeFrameGetPrice("O", inDaily); // current day openWeekH= TimeFrameGetPrice("H", inWeekly, 1); WeekHI = LastValue (WeekH,1); // One Week before highWeekL= TimeFrameGetPrice("L", inWeekly, 1); WeekLI = LastValue (WeekL,1); // One Week before lowMonthH= TimeFrameGetPrice("H", inMonthly, 1); MonthHI = LastValue (MonthH,1); // One Month before highMonthL= TimeFrameGetPrice("L", inMonthly, 1); MonthLI = LastValue (MonthL,1); // One Month before low numbars = LastValue(Cum(Status("barvisible")));hts = -33.5; YHL = ParamToggle("Yesterday HI LO","Hide|Show",1);if(YHL==1) { Plot(DayL,"YL",colorTurquoise,styleDashed|styleNoRescale|styleNoTitle); Plot(DayH,"YH",colorOrange,styleDashed|styleNoRescale|styleNoTitle); PlotText(" YstrdayH " , LastValue(BarIndex())-(numbars/Hts), DayHI, colorOrange); PlotText(" YstrdayL " , LastValue(BarIndex())-(numbars/Hts), DayLI, colorTurquoise);} TDBHL = ParamToggle("Week And Month HI LO","Hide|Show",1);if(TDBHL==1) { Plot(WeekL,"WeekL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(WeekH,"WeekH",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(MonthL,"MonthL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(MonthH,"MonthH",colorOrange,styleDots|styleNoLine|styleNoRescale|styleNoTitle); PlotText(" WeekH " , LastValue(BarIndex())-(numbars/Hts), WeekHI, colorOrange); PlotText(" WeekL " , LastValue(BarIndex())-(numbars/Hts), WeekLI, colorTurquoise); PlotText(" MonthH " , LastValue(BarIndex())-(numbars/Hts), MonthHI, colorOrange); PlotText(" MonthL " , LastValue(BarIndex())-(numbars/Hts), MonthLI, colorTurquoise);} // Pivot Levels //PP = (DayL + DayH + DayC)/3; PPI = LastValue (PP,1); // PivotR1 = (PP * 2) - DayL; R1I = LastValue (R1,1); // Resistance 1S1 = (PP * 2) - DayH; S1I = LastValue (S1,1); // Support 1R2 = PP + R1 - S1; R2I = LastValue (R2,1); // Resistance 2S2 = PP - R1 + S1; S2I = LastValue (S2,1); // Support 2R3 = PP + R2 - S1; R3I = LastValue (R3,1); // Resistance 3S3 = PP - R2 + S1; S3I = LastValue (S3,1); // Support 3 ppl = ParamToggle("Pivot Levels","Hide|Show",0);if(ppl==1) { Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle); PlotText(" Pivot ", LastValue(BarIndex())-(numbars/Hts), PPI, colorYellow); PlotText(" R1 " , LastValue(BarIndex())-(numbars/Hts), R1I, colorViolet); PlotText(" S1 " , LastValue(BarIndex())-(numbars/Hts), S1I, colorViolet); PlotText(" R2 " , LastValue(BarIndex())-(numbars/Hts), R2I, colorViolet); PlotText(" S2 " , LastValue(BarIndex())-(numbars/Hts), S2I, colorViolet); PlotText(" R3 " , LastValue(BarIndex())-(numbars/Hts), R3I, colorViolet); PlotText(" S3 " , LastValue(BarIndex())-(numbars/Hts), S3I, colorViolet);}// Camerilla Levels // rg = (DayH - DayL); H5=DayC+1.1*rg; H5I = LastValue (H5,1);H4=DayC+1.1*rg/2; H4I = LastValue (H4,1);H3=DayC+1.1*rg/4; H3I = LastValue (H3,1);H2=DayC+1.1*rg/6; H2I = LastValue (H2,1);H1=DayC+1.1*rg/12; H1I = LastValue (H1,1);L1=DayC-1.1*rg/12; L1I = LastValue (L1,1);L2=DayC-1.1*rg/6; L2I = LastValue (L2,1);L3=DayC-1.1*rg/4; L3I = LastValue (L3,1);L4=DayC-1.1*rg/2; L4I = LastValue (L4,1);L5=DayC-1.1*rg; L5I = LastValue (L5,1); pcl = ParamToggle("Camerilla Levels","Hide|Show",0);if(pcl==1) { Plot(H5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(H4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(H3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(H2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(H1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(L1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(L2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(L3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(L4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); Plot(L5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle); PlotText(" H5 = " , LastValue(BarIndex())-(numbars/Hts), H5I +0.05, colorRose); PlotText(" H4 = " , LastValue(BarIndex())-(numbars/Hts), H4I +0.05, colorRose); PlotText(" H3 = " , LastValue(BarIndex())-(numbars/Hts), H3I +0.05, colorRose); PlotText(" H2 = " , LastValue(BarIndex())-(numbars/Hts), H2I +0.05, colorRose); PlotText(" H1 = " , LastValue(BarIndex())-(numbars/Hts), H1I +0.05, colorRose); PlotText(" L1 = " , LastValue(BarIndex())-(numbars/Hts), L1I +0.05, colorRose); PlotText(" L2 = " , LastValue(BarIndex())-(numbars/Hts), L2I +0.05, colorRose); PlotText(" L3 = " , LastValue(BarIndex())-(numbars/Hts), L3I +0.05, colorRose); PlotText(" L4 = " , LastValue(BarIndex())-(numbars/Hts), L4I +0.05, colorRose); PlotText(" L5 = " , LastValue(BarIndex())-(numbars/Hts), L5I +0.05, colorRose);} // Current Days Hi Lo //THL = ParamToggle("Todays Hi Lo","Hide|Show",1);if(THL==1) { isRth = TimeNum() >= 084500 & TimeNum() = 084500 & TimeNum() = 94500 AND TimeNum() < 095959);//,BarIndex(),1); // AND DateNum()==LastValue(DateNum()); x0 = BarCount-LastValue(Bars); x1 = BarCount-1; DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0); DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0); DayHlineI = LastValue (DayHline,1); DayLlineI = LastValue (DayLline,1); Plot(DayHline,"DayH",colorGold,styleDashed|styleNoRescale|styleNoTitle); Plot(DayLline,"DayL",colorBlue,styleDashed|styleNoRescale|styleNoTitle); PlotText(" Day Hi " , LastValue(BarIndex())-(numbars/Hts), DayHlineI +0.05, colorYellow); PlotText(" Day Lo " , LastValue(BarIndex())-(numbars/Hts), DayLlineI +0.05, colorYellow); }_SECTION_BEGIN("Title"); DDayO = TimeFrameGetPrice("O", inDaily);DHiDay = TimeFrameGetPrice("H", inDaily);DLoDay = TimeFrameGetPrice("L", inDaily);prvC = TimeFrameGetPrice("C", inDaily, -1);//closeTitle =EncodeColor(colorYellow)+ Date()+EncodeColor(colorPink)+" "+Interval(format=2)+EncodeColor(colorOrange)+" "+Name()+EncodeColor(colorBrightGreen)+" Open:"+WriteVal(O,1.2)+EncodeColor(colorBrightGreen)+" High: "+WriteVal(H,1.2)+EncodeColor(colorWhite)+" Low: "+WriteVal(L,1.2)+EncodeColor(colorYellow)+" Close "+ WriteVal(C,1.2) + " ~ Prev Close : " + EncodeColor(colorYellow) + prvC +EncodeColor(colorGold)+"\n Day-Open : " +DDayO + " Day-High : " +DHiDay + " Day-Low : "+ DLoDay ; _SECTION_END(); _SECTION_BEGIN("Background"); tchoice=Param("Title Selection ",2,1,2,1); Plot(C, "", IIf(O>=C, colorWhite, colorBrightGreen), ParamStyle("Price Style",styleCandle,maskPrice)); ////////////////////////////////////////////////////////////////// _SECTION_BEGIN("Background text");SetChartBkColor(colorBlack);strWeekday = StrMid("---sunday---Monday--TuesdayWednesday-Thursday--Friday--Saturday", SelectedValue(DayOfWeek())*9,9);GraphXSpace=Param("GraphXSpace",0,-55,200,1);C13=Param("fonts",30,10,30,1 );C14=Param("left-right",2.1,1.0,5.0,0.1 );C15=Param("up-down",12,1,20,1 );Miny = Status("axisminy");Maxy = Status("axismaxy");lvb = Status("lastvisiblebar");fvb = Status("firstvisiblebar");pxwidth = Status("pxwidth");pxheight = Status("pxheight");GfxSetBkMode(transparent=1);GfxSetOverlayMode(1);GfxSelectFont("Candara", Status("pxheight")/C13 );GfxSetTextAlign( 6 );GfxSetTextColor( ColorRGB (217,217,213));GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );GfxSetTextColor( ColorRGB (103,103,103));GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );GfxSetTextColor( ColorRGB (103,103,103));GfxTextOut( " [email protected]", Status("pxwidth")/C14, Status("pxheight")/C15*4 );GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);_SECTION_END(); _SECTION_BEGIN("Parameters");LB1= Param("Long LookBack Periods",42,1,60,1);LB3= Param("Mid LookBack Periods",18,1,30,1);LB2= Param("Short LookBack Periods",6,1,30,1); _SECTION_END(); ppl = ParamToggle("","Off|On",0);numbars = LastValue(Cum(Status("barvisible")));fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);hts = -33.5;_SECTION_BEGIN("Indicators");RSI_Periods = Param("RSI Periods", 2, 1, 100, 1);MA_Periods = Param("Periods for MAV", 50, 1, 200, 1);Daily_Trend_MA_Pds = Param("Periods for Trend EMA", 6, 1, 100, 1);MAV_Value = V/EMA(V, MA_Periods);_SECTION_END();// Check if previous day's close is above its 6-day EMADailyClose = TimeFrameCompress(Close, inDaily);DailyEMA = EMA( DailyClose, Daily_Trend_MA_Pds);DailyClose = TimeFrameExpand(DailyClose, inDaily, expandFirst);DailyEma = TimeFrameExpand(DailyEMA, inDaily, expandFirst);//Plot(DailyEma,"DailEma",colorCustom12,styleLine); // Trend detection based on 6EMA for DailyDaily_Trend_UP = DailyClose > DailyEMA;Daily_Trend_DOWN = DailyClose < DailyEMA;Trend_UP_Text = WriteIf(Daily_Trend_UP, "Daily Trend UP", "");Trend_DOWN_Text = WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");Trend_Neutral_Text = WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend_UP, "Neutral", "");TrendCol = IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_DOWN, colorRed, colorLightGrey));_SECTION_END(); _SECTION_BEGIN("Price");pds = 20;MAFAST = EMA( Close, 20 );MASLOW = EMA( Close, 40 ); DonchianUpper = HHV( Ref( H, -1 ), pds ); // Highest high value of highs in last 20 periodsDonchianLower = LLV( Ref( L, -1 ), pds ); // Lowest low value of low in last 20 periodsDonchianMiddle = ( DonchianUpper + DonchianLower ) / 2; UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close, 40 );DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close, 40 );Color = IIf( UpTrend, colorBlue, IIf( DnTrend, colorRed, colorYellow) ); // Plots a 20 period Donchian channelPlot( C, "Price", Color, styleCandle | styleThick );NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);//Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);_SECTION_END(); _SECTION_BEGIN("PIVOT POINTS"); /* This code calculates the previous days high, low and close */Hi1 = IIf(Day()!=Ref(Day(),-1),Ref(HighestSince(Day()!=Ref(Day(),-1),H,1),-1),0);Hi = ValueWhen(Day()!=Ref(Day(),-1),Hi1,1);Lo1 = IIf(Day()!=Ref(Day(),-1),Ref(LowestSince(Day()!=Ref(Day(),-1),L,1),-1),0);Lo = ValueWhen(Day()!=Ref(Day(),-1),Lo1,1);Cl1 = IIf(Day()!=Ref(Day(),-1),Ref(C,-1),0);C1 = ValueWhen(Day()!=Ref(Day(),-1),Cl1,1);wHi=TimeFrameGetPrice("H",inWeekly,-1);wLo=TimeFrameGetPrice("L",inWeekly,-1);wCl=TimeFrameGetPrice("C",inWeekly,-1);mHi=TimeFrameGetPrice("H",inMonthly,-1);mLo=TimeFrameGetPrice("L",inMonthly,-1);mCl=TimeFrameGetPrice("C",inMonthly,-1); //---------------------------------------------------------------------------------- /* This code calculates Daily Piovts */ rg = (Hi - Lo);bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);r1 = (bp*2)-Lo; r1I = LastValue (r1,1);s1 = (bp*2)-Hi; s1I = LastValue (s1,1);r2 = bp + r1 - s1; r2I = LastValue (r2,1);s2 = bp - r1 + s1; s2I = LastValue (s2,1);r3 = bp + r2 - s1; r3I = LastValue (r3,1);s3 = bp - r2 + s1; s3I = LastValue (s3,1);r4 = bp + r2 - s2; r4I = LastValue (r4,1);s4 = bp - r2 + s2; s4I = LastValue (s4,1);wrg = (wHi - wLo);wbp = (wHi + wLo + wCl)/3; wbpI = LastValue (wbp,1);wr1 = (wbp*2)-wLo; wr1I = LastValue (wr1,1);ws1 = (wbp*2)-wHi; ws1I = LastValue (ws1,1);wr2 = wbp + wr1 - ws1; wr2I = LastValue (wr2,1);ws2 = wbp - wr1 + ws1; ws2I = LastValue (ws2,1);wr3 = wbp + wr2 - ws1; wr3I = LastValue (wr3,1);ws3 = wbp - wr2 + ws1; ws3I = LastValue (ws3,1);wr4 = wbp + wr2 - ws2; wr4I = LastValue (wr4,1);ws4 = wbp - wr2 + ws2; ws4I = LastValue (ws4,1);mrg = (mHi - mLo);mobp = (mHi + mLo + mCl)/3; mobpI = LastValue (mobp,1);mr1 = (mobp*2)-mLo; mr1I = LastValue (mr1,1);ms1 = (mobp*2)-mHi; ms1I = LastValue (ms1,1);mr2 = mobp + mr1 - ms1; mr2I = LastValue (mr2,1);ms2 = mobp - mr1 + ms1; ms2I = LastValue (ms2,1); if(ppl==1) {Plot(bp,"",colorWhite,styleLine|styleLine|styleNoRescale);Plot(s1,"",colorGreen,styleDashed|styleNoRescale);Plot(s2,"",colorBrightGreen,styleDashed|styleNoRescale);Plot(s3,"",colorBrightGreen,styleDashed|styleNoRescale);Plot(s4,"",colorBrightGreen,styleDashed|styleNoRescale);Plot(r1,"",colorRed,styleDashed|styleNoRescale);Plot(r2,"",colorDarkRed,styleDashed|styleNoRescale);Plot(r3,"",colorDarkRed,styleDashed|styleNoRescale);Plot(r4,"",colorDarkRed,styleDashed|styleNoRescale);Plot(wbp,"",colorTan,styleDashed|styleLine|styleNoRescale);Plot(ws1,"",colorPaleGreen,styleDashed|styleNoRescale);Plot(ws2,"",colorPaleGreen,styleDashed|styleNoRescale);//Plot(ws3,"",colorPaleGreen,styleDashed|styleNoRescale);//Plot(ws4,"",colorPaleGreen,styleDashed|styleNoRescale);Plot(wr1,"",colorPaleBlue,styleDashed|styleNoRescale);Plot(wr2,"",colorPaleBlue,styleDashed|styleNoRescale);//Plot(wr3,"",colorPaleBlue,styleDashed|styleNoRescale);//Plot(wr4,"",colorPaleBlue,styleDashed|styleNoRescale);Plot(mobp,"",colorTan,styleDashed|styleLine|styleNoRescale);Plot(ms1,"",colorPaleGreen,styleDashed|styleNoRescale);Plot(mr1,"",colorPaleBlue,styleDashed|styleNoRescale);PlotText(" Pivot = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts), bpI +0.05, colorWhite);PlotText(" Resistance 1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorRed);PlotText(" Support 1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorGreen);PlotText(" Resistance 2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numbars/Hts), r2I +0.05, colorDarkRed);PlotText(" Support 2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars/Hts), s2I +0.05, colorBrightGreen);PlotText(" Resistance 3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numbars/Hts), r3I +0.05, colorDarkRed);PlotText(" Support 3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars/Hts), s3I +0.05, colorBrightGreen);PlotText(" Resistance 4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numbars/Hts), r4I +0.05, colorDarkRed);PlotText(" Support 4 = " + WriteVal(s4,fraction), LastValue(BarIndex())-(numbars/Hts), s4I +0.05, colorBrightGreen);PlotText(" W Pivot = " + WriteVal(wbp,fraction), LastValue(BarIndex())-(numbars/Hts), wbpI +0.05, colorTan);PlotText(" W Resistance 1 = " + WriteVal(wr1,fraction), LastValue(BarIndex())-(numbars/Hts), wr1I +0.05, colorPaleBlue);PlotText(" W Support 1 = " + WriteVal(ws1,fraction), LastValue(BarIndex())-(numbars/Hts), ws1I +0.05, colorPaleGreen);PlotText(" W Resistance 2 = " + WriteVal(wr2,fraction), LastValue(BarIndex())-(numbars/Hts), wr2I +0.05, colorPaleBlue);PlotText(" W Support 2 = " + WriteVal(ws2,fraction), LastValue(BarIndex())-(numbars/Hts), ws2I +0.05, colorPaleGreen);//PlotText(" W Resistance 3 = " + WriteVal(wr3,fraction), LastValue(BarIndex())-(numbars/Hts), wr3I +0.05, colorPaleBlue);//PlotText(" W Support 3 = " + WriteVal(ws3,fraction), LastValue(BarIndex())-(numbars/Hts), ws3I +0.05, colorPaleGreen);//PlotText(" W Resistance 4 = " + WriteVal(wr4,fraction), LastValue(BarIndex())-(numbars/Hts), wr4I +0.05, colorPaleBlue);//PlotText(" W Support 4 = " + WriteVal(ws4,fraction), LastValue(BarIndex())-(numbars/Hts), ws4I +0.05, colorPaleGreen);PlotText(" M Pivot = " + WriteVal(mobp,fraction), LastValue(BarIndex())-(numbars/Hts), mobpI+0.05, colorTan);PlotText(" M Resistance 1 = " + WriteVal(mr1,fraction), LastValue(BarIndex())-(numbars/Hts), mr1I+0.05, colorPaleBlue);PlotText(" M Support 1 = " + WriteVal(ms1,fraction), LastValue(BarIndex())-(numbars/Hts), ms1I+0.05, colorPaleGreen);} _SECTION_END(); _SECTION_BEGIN("PIVOTS Hourly");TimeFrameSet(inHourly);HourlyH= LastValue(Ref(H,-1));HourlyL= LastValue(Ref(L,-1));HourlyC= LastValue(Ref(C,-1));TimeFrameRestore(); //DailyHPP = (HourlyL + HourlyH + HourlyC)/3;HPPI = LastValue (HPP,1);HR1 = (2 * HPP) - HourlyL;HR1I = LastValue (HR1,1);HS1 = (2 * HPP) - HourlyH;HS1I = LastValue (HS1,1);HR2 = HPP + (HourlyH - HourlyL);HR2I = LastValue (HR2,1);HS2 = HPP - (HourlyH - HourlyL);HS2I = LastValue (HS2,1);HR3 = HourlyH + 2*(HPP - HourlyL);HR3I = LastValue (HR3,1);HS3 = HourlyL - 2*(HourlyH - HPP);HS3I = LastValue (HS3,1);SHOWDPIVOTS = ParamToggle("Daily Pivots", "No|Yes",0);SHOW3 = ParamToggle("3rd Line", "No|Yes",0); if (SHOWDPIVOTS & SHOW3){ Plot(HS3, "S3",ColorR); Plot(HR3, "R3",ColorG); PlotText(" H Resis 3 = " + WriteVal(HR3,fraction), LastValue(BarIndex())-(numbars/Hts), HR3I +0.05, colorGreen); PlotText(" H Sup 3 = " + WriteVal(HS3,fraction), LastValue(BarIndex())-(numbars/Hts), HS3I +0.05, colorRed); } for (i=BarCount-2;i>(BarCount-13);i--)//set the last bars to the final PP value{ HPP[i] = HPP[BarCount-1]; HR1[i] = HR1[BarCount-1]; HR2[i] = HR2[BarCount-1]; HS1[i] = HS1[BarCount-1]; HS2[i] = HS2[BarCount-1]; ColorG[i] = colorGreen; ColorB[i] = colorBlue; ColorR[i] = colorRed;} //// Conceal all but the trailing portion of the line//for (i=0;i Ref(C,-1));//gfxpcolor = IIf(gfxcup,colorBrightGreen,colorRed);GfxSetTextColor(colorBrightGreen);//GfxSetTextColor( colorWhite );GfxTextOut( "Time left for candle close " + SecsToGo + " ", cx, cy );_SECTION_END();