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.
-
-
08/31/2020 at 1:47 PM #143055
Hello,
I have identified the Peaks and Troughs as per the enclosed code.
Now , if I want to join the 2 higher high troughs and 2 lower low peaks within a timeframe (e.g. from 15:00 to 23:00) how to do it?
Example is enclosed where manual trend lines are drawn between the said period.
Any help would be highly appreciated.
Regards,
Peak-Trough-Line1234567891011121314151617181920//VARIABLES//x = 500H2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]P=PIPSIZE//PEAKiF H1>H2 and L1>L2 and H0<H1 AND L0<L1 AND CLOSE<H1 thenTT=H1//TROUGHelsiF H1<H2 and L1<L2 and H0>H1 AND L0>L1 AND CLOSE>L1 thenTT=L1ELSETT=L0-X*PENDIFreturn TT AS "PT"09/03/2020 at 1:43 PM #143294Any help would be highly appreciated, please.
09/03/2020 at 8:00 PM #143319You need to give high TT’s and the low TT’s different names and store the previous value when a new value is recorded. You also need to store the barindex.
Something like this perhaps. Not tested.
123456789101112131415161718192021222324252627282930313233//VARIABLESH2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]//PEAKiF H1>H2 and L1>L2 and H0<H1 AND L0<L1 AND CLOSE<H1 thenlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] thenDRAWLINE(lasthttbar,lasthtt,httbar,htt) COLOURED(0,128,0)endifendif//TROUGHiF H1<H2 and L1<L2 and H0>H1 AND L0>L1 AND CLOSE>L1 thenlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] thenDRAWLINE(lastlttbar,lastltt,lttbar,ltt) COLOURED(128,0,0)endifendifreturn09/04/2020 at 4:43 AM #143335VERY HELPFUL Vonasi.
Much appreciated.
Many thanks for your time and effort.
Regards,
09/04/2020 at 5:03 AM #143336Hello Vonasi,
Is it possible not to extend the line to its left? if yes then how please? and if I want the line to be drawn for today’s peaks and troughs only then should I check “if date=today”?
Regards,
09/04/2020 at 9:08 AM #143348That’s possible but only with PRT v11 and the DRAWRAY instruction.
v11 only1234567891011121314151617181920212223242526272829303132333435defparam calculateonlastbars=300//VARIABLESH2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]//PEAKiF H1>H2 and L1>L2 and H0<H1 AND L0<L1 AND CLOSE<H1 thenlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] thenDRAWRAY(lasthttbar,lasthtt,httbar,htt) COLOURED(0,128,0)endifendif//TROUGHiF H1<H2 and L1<L2 and H0>H1 AND L0>L1 AND CLOSE>L1 thenlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] thenDRAWRAY(lastlttbar,lastltt,lttbar,ltt) COLOURED(128,0,0)endifendifreturn1 user thanked author for this post.
09/04/2020 at 10:30 AM #143356Try this for just drawing the latest lines:
As Nicolas says you need DRAWRAY and v11 to get rid of the bit of line to the left.
12345678910111213141516171819202122232425262728293031defparam drawonlastbaronly = true//VARIABLESH2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]//PEAKiF H1>H2 and L1>L2 and H0<H1 AND L0<L1 AND CLOSE<H1 thenlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]endifDRAWLINE(lasthttbar,lasthtt,httbar,htt) COLOURED(0,128,0)//TROUGHiF H1<H2 and L1<L2 and H0>H1 AND L0>L1 AND CLOSE>L1 thenlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]endifDRAWLINE(lastlttbar,lastltt,lttbar,ltt) COLOURED(128,0,0)return09/04/2020 at 12:29 PM #143375Many thanks Vonasi and Nicolas. Much appreciated.
I have modified the code, but could not set alarm as it is not identifying the lines’ value correctly,
Is it possible to fix it?
Trend line1234567891011121314151617181920212223242526272829303132333435363738394041424344//VARIABLES// ST= 90000, ET=240000H2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]//PEAKiF 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(205,0,0)endifENDIFendifENDIFENDIF//TROUGHiF 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(0,205,0)endifENDIFendifENDIFENDIFreturn09/04/2020 at 2:06 PM #143388You cannot set an alarm to detect lines drawn in a custom indicator. You will need to calculate the projected forward line value for each bar moving forward by subtracting the lower point value from the higher point value and dividing by the number of bars between them, then add this on to the most recent value for each bar moving forward.
Once you know this value you can test to see if close is above or below it etc.
One downside of this calculation is if you use a time frame with missing bars as these can cause steps in the forward calculation.
An example of this sort of calculation can be found here:
https://www.prorealcode.com/prorealtime-indicators/last-two-pivots-support-and-resistance-lines/
In fact it might be easier for you just to adapt that indicator to do what you want.
09/04/2020 at 2:11 PM #14339009/05/2020 at 10:09 AM #143426Many thanks Vonasi. 2nd example is a brilliant one.
09/10/2020 at 4:31 AM #143807Dear Vonasi, in your last example (https://www.prorealcode.com/prorealtime-indicators/last-two-highest-high-and-lowest-low-lines-yearly-quarterly-monthly-weekly-daily-4-hour-and-1-hour/) you have drawn lines without extending to the left and without “DRAWRAY”. So if that is possible in your example, why can’t we do the same to my indicator (with your help) please?
09/10/2020 at 8:29 AM #14381409/10/2020 at 1:39 PM #143870You are right Nicolas. When can we have “Style” with DRAWLINE and DRAWSEGMENT to increase line thickness? Is Style available with DRAWRAY?
09/10/2020 at 4:18 PM #143881 -
AuthorPosts
Find exclusive trading pro-tools on