TREND LINE through Peaks and Troughs
Forums › ProRealTime English forum › ProBuilder support › TREND LINE through Peaks and Troughs
- This topic has 23 replies, 3 voices, and was last updated 4 years ago by parthapersonal.
-
-
09/13/2020 at 2:04 PM #144084
Many thanks Vonasi and Nicolas. I define Trend Lines in 3 different categories: 1. Invalid Trend Line, 2. Tentative Trend Line and 3. Valid Trend Line.
I join 2 Swing Lows (2nd swing low higher than 1st) with an Up Trend line, provided there is a Swing High (SH) in-between those 2 swing lows. This is a Valid Up trend line.
If there is no in-between swing high, we can not join 2 Swing Lows (2nd swing low higher than the 1st) with an up trend line. This will be an INVALID up trend line.
Similarly, I join 2 Swing highs (2nd swing high lower than the 1st) with an Down Trend line, provided there is a Swing Low (SL) in-between those 2 swing highs. This is a Valid Down trend line.
If there is no in-between swing low, we can not join 2 Swing highs (2nd swing high lower than the 1st) with an down trend line. This will be an INVALID down trend line. These are all shown in the 2 enclosed chart.
Now the question is how to incorporate this concept of valid Trend Line in our previous program as attached please.
Many thanks for your would be response.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576//90000 160000 205 0 0 0 151 51 for ASX//90000 240000 205 0 0 0 151 51 for GBPH2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]A=H2B=H1C=H0D=L2E=L1F=L0iF B>=A AND B>C THENT=-3elset=0endifIF E<=D AND E<F THENT1=3ELSET1=0ENDIFif t=-3 AND T1=0 thensh=bELSif t=-3 AND T1=8 thensh=bELSESH=0ENDIFIf t1=3 AND T=0 thensl=eelsif t1=3 AND T=3 thensl=eelsesl=0endif//PEAK or Swing HighiF SH=B THEN//H1>=H2 and L1>=L2 and H0<H1 AND L0<=L1 THEN//AND CLOSE<H1 thenIF TIME>ST AND TIME<ET and date=today THENlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] thenIF TIME>ST AND TIME<ET and date=today THENIF htt<Htt[1] THENDRAWLINE(lasthttbar,lasthtt,httbar,htt) COLOURED(X,Y,Z)//(205,0,0)endifENDIFendifENDIFENDIF//TROUGH or Swing LowiF SL=E THEN //H1<H2 and L1<L2 and H0>=H1 AND L0>=L1 THEN//anD CLOSE>L1 thenIF TIME>ST AND TIME<ET and date=today THENlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] thenIF TIME>ST AND TIME<ET and date=today THENIF Ltt>Ltt[1] THENDRAWLINE(lastlttbar,lastltt,lttbar,ltt) COLOURED(U,V,W)//(0,205,0)endifENDIFendifENDIFENDIFreturn09/14/2020 at 9:57 AM #14419209/17/2020 at 6:24 AM #144485Valid Trend Line12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576//VARIABLES//90000 160000 205 0 0 0 151 51 for ASX//90000 240000 205 0 0 0 151 51 for GBPH2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]// Swong High and Swing Low separationiF h1>=h2 AND h1>h0 THENT=-3elset=0endifIF l1<=l2 AND l1<l0 THENT1=3ELSET1=0ENDIF// Swong Highif t=-3 AND T1=0 thensh=h1ELSif t=-3 AND T1=8 thensh=h1ELSESH=0ENDIF// Swong LowIf t1=3 AND T=0 thensl=l1elsif t1=3 AND T=3 thensl=l1elsesl=0endif//Down trend segment/ lineiF SH=h1 THENIF TIME>ST AND TIME<ET and date=today THENlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] thenIF TIME>ST AND TIME<ET and date=today THENIF htt<Htt[1] and ltt<htt and ltt<htt[1] THENDRAWsegment(lasthttbar,lasthtt,httbar,htt) COLOURED(X,Y,Z)//(205,0,0)endifENDIFendifENDIFENDIF//Up trend segment/ lineiF SL=l1 THENIF TIME>ST AND TIME<ET and date=today THENlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] thenIF TIME>ST AND TIME<ET and date=today THENIF Ltt>Ltt[1] and htt>ltt and htt>ltt[1] THENDRAWsegment(lastlttbar,lastltt,lttbar,ltt) COLOURED(U,V,W)//(0,205,0)endifENDIFendifENDIFENDIFreturnMany thanks Nicolas. I tried to find the in-between swing high between the 2 swing lows for drawing the up trend segment via the code, “IF Ltt>Ltt[1] and htt>ltt and htt>ltt[1] THEN” and tried to find the in-between swing low between the 2 swing highs for drawing the down trend segment via the code, “IF htt<Htt[1] and ltt<htt and ltt<htt[1] THEN” but it is drawing the segment even if there is no in-between swing high or low.
The captured chart shows an up trend segment by joining 2 swing lows when there is no swing high present in-between the 2 swing lows. This is not correct (marked as “incorrect segment”).
Your assistance would be of great help.
Regards,
09/17/2020 at 9:08 AM #144502But you are comparing price and not bar number! What I was talking about is the sequence of events of the swings: a swing high event must be present between 2 swings low events, and you can test that with their barindex numbers.
09/17/2020 at 2:03 PM #144552Thank you Nicolas, but honestly I am not a master in Barindex numbers coding. Appreciate your help please.
Best Regards,
09/17/2020 at 3:15 PM #14455909/18/2020 at 6:18 AM #144612Many thanks dear. Here it is. Much appreciated
Valid Trend Line123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475//VARIABLES//ST= 0, ET=240000, X=255, Y=0, Z=0, U=0, V=0, W=255H2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]// Swing High and Swing Low separationiF h1>=h2 AND h1>h0 THENT=-3elset=0endifIF l1<=l2 AND l1<l0 THENT1=3ELSET1=0ENDIF// Swing Highif t=-3 AND T1=0 thensh=h1ELSif t=-3 AND T1=8 thensh=h1ELSESH=0ENDIF// Swing LowIf t1=3 AND T=0 thensl=l1elsif t1=3 AND T=3 thensl=l1elsesl=0endif//Down trend segment/ lineiF SH=h1 THENIF TIME>ST AND TIME<ET and date=today THENlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] thenIF TIME>ST AND TIME<ET and date=today THENIF htt<Htt[1] then//and ltt<htt and ltt<htt[1] THENDRAWsegment(lasthttbar,lasthtt,httbar,htt) COLOURED(X,Y,Z)//(205,0,0)endifENDIFendifENDIFENDIF//Up trend segment/ lineiF SL=l1 THENIF TIME>ST AND TIME<ET and date=today THENlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] thenIF TIME>ST AND TIME<ET and date=today THENIF Ltt>Ltt[1] then//and htt>ltt and htt>ltt[1] THENDRAWsegment(lastlttbar,lastltt,lttbar,ltt) COLOURED(U,V,W)//(0,205,0)endifENDIFendifENDIFENDIFreturn.
09/18/2020 at 8:46 AM #144625In that version, descending trend line can be plotted only if the last swing before the current one was a red dot, and vice-versa for an ascending trend line.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788//VARIABLESST= 0ET=240000X=255Y=0Z=0U=0V=0W=255// ----------------------H2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]// Swing High and Swing Low separationiF h1>=h2 AND h1>h0 THENT=-3elset=0endifIF l1<=l2 AND l1<l0 THENT1=3ELSET1=0ENDIF// Swing Highif t=-3 AND T1=0 thensh=h1ELSif t=-3 AND T1=8 thensh=h1ELSESH=0ENDIF// Swing LowIf t1=3 AND T=0 thensl=l1elsif t1=3 AND T=3 thensl=l1elsesl=0endif//Down trend segment/ lineiF SH=h1 THENdrawtext("●",barindex[1],sh,dialog,bold,20) coloured(0,255,0)lastbar=1IF TIME>ST AND TIME<ET and date=today THENlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] and lastbar[1]=-1 thenIF TIME>ST AND TIME<ET and date=today THENIF htt<Htt[1] then//and ltt<htt and ltt<htt[1] THENDRAWsegment(lasthttbar,lasthtt,httbar,htt) COLOURED(X,Y,Z)//(205,0,0)endifENDIFendifENDIFENDIF//Up trend segment/ lineiF SL=l1 THENdrawtext("●",barindex[1],sl,dialog,bold,20) coloured(255,0,0)lastbar=-1IF TIME>ST AND TIME<ET and date=today THENlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] and lastbar[1]=1 thenIF TIME>ST AND TIME<ET and date=today THENIF Ltt>Ltt[1] then//and htt>ltt and htt>ltt[1] THENDRAWsegment(lastlttbar,lastltt,lttbar,ltt) COLOURED(U,V,W)//(0,205,0)endifENDIFendifENDIFENDIFreturn09/18/2020 at 1:28 PM #144662This is brilliant. You are a genius Nicolas.
Many thanks for your intention, effort and time.
-
AuthorPosts
Find exclusive trading pro-tools on