DRAWSEGMENT assistance
Forums › ProRealTime English forum › ProBuilder support › DRAWSEGMENT assistance
- This topic has 27 replies, 2 voices, and was last updated 3 years ago by IG_CFD_Trader.
-
-
06/30/2017 at 9:23 PM #39523
Hi Nicolas and other forum members,
The attached code draws high and low points on the chart.
How do I amend it using drawsegment command so that:
- it connects the last 2 high points and the last 2 low points on the chart ONLY.
- every time a new 2 high and low points are formed, these new points are connected and the 2 old segment lines are automatically removed (i.e. code basically draws the latest 2 high and 2 low points continually)
Any assistance is appreciated.
Walid
06/30/2017 at 9:36 PM #39525Would you mind add the code in readable format in your next post please? Should be easier to help.
If a graphical component has been plotted, it cannot be erased. But there are some tricks to do it, that’s why I need to explore your code, but preferably on the forum, thank you.07/01/2017 at 12:34 AM #3952712345678910111213141516171819202122232425262728293031323334353637383940414243444546474849TH=max(high,close[1])TL=min(low,close[1])r=0e=1r=strengthif high[r]>highest[r](TH) thene=1while high[r]=high[r+e] doe=e+1wendif high[r]>highest[r](TH[r+e]) thenHiPoint = high[r]endifEndifif low[r]<lowest[r](TL) thene=1while low[r]=low[r+e] doe=e+1wendif low[r]<lowest[r](TL[r+e]) thenLoPoint = low[r]endifendifreturn HiPoint as "SupplyLine", LoPoint as "DemandLine"07/02/2017 at 7:35 PM #3959507/03/2017 at 12:20 AM #39611No only the current supply and demand zones (i.e. always lines connecting the highs and lows of latest 2 supply lines and 2 demand lines only.
07/03/2017 at 9:55 AM #39655This is how it looks now. Segments are plotted between the 2 last tow detected Highs and Lows. As I said previously, the plotted lines can’t be erased.
123456789101112131415161718192021222324252627282930313233343536373839404142434445//defparam drawonlastbaronly=true//defparam calculateonlastbars=200strength=20TH=max(high,close[1])TL=min(low,close[1])r=0e=1r=strengthif high[r]>highest[r](TH) thene=1while high[r]=high[r+e] doe=e+1wendif high[r]>highest[r](TH[r+e]) thenHiPoint = high[r]HiBar = barindex[r]drawsegment(HiBar[1],HiPoint[1],HiBar,HiPoint) coloured(200,0,0)endifEndifif low[r]<lowest[r](TL) thene=1while low[r]=low[r+e] doe=e+1wendif low[r]<lowest[r](TL[r+e]) thenLoPoint = low[r]LoBar = barindex[r]drawsegment(LoBar[1],LoPoint[1],LoBar,LoPoint) coloured(0,200,0)endifendifreturn //HiPoint as "SupplyLine", LoPoint as "DemandLine"07/06/2017 at 8:42 PM #39971Hi Nicolas,
Thank you for posting amended code.
You are almost there.
One final change that needs to be made: the segment lines need to connect the current HiPoint with the first preceding HiPoint before it that is HIGHER than the current HiPoint and same for LoPoint segment, the segment lines need to connect the current LoPoint with the first preceding LoPoint before it that is LOWER than the current LoPoint
07/07/2017 at 8:55 AM #3999507/07/2017 at 9:10 AM #39998Yes you can call it a triangle if you like. Basically I want to connect the high of the most current HiPoint on the chart with the high of the first Hipoint before it that is higher than it. It must be higher than it. Same for lopoints
07/07/2017 at 9:26 AM #4000007/07/2017 at 9:30 AM #4000307/07/2017 at 10:57 AM #4001307/07/2017 at 11:06 AM #40014This is what I made so far. It works, but as you can see, sometimes the last high or low points in the past are used several times. In this code we are not fetching through the whole history but only in the last “length * 5” bars, you can change this factor of course.
07/07/2017 at 9:10 PM #40047Looks good but you forgot to post the code 🙂 can you post the code please for the changes you made?
07/09/2017 at 1:03 PM #40165Before posting it I wanted to be sure this was in accordance with your query, here is the code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051strength=20lookback=strength*5TH=max(high,close[1])TL=min(low,close[1])r=0e=1r=strengthif high[r]>highest[r](TH) thene=1while high[r]=high[r+e] doe=e+1wendif high[r]>highest[r](TH[r+e]) thenHiPoint = high[r]HiBar = barindex[r]for i = 1 to lookback doif hibar[i]<>hibar thenif hipoint[i]>hipoint thendrawsegment(HiBar[i],HiPoint[i],HiBar,HiPoint) coloured(200,0,0)breakendifendifnextendifEndifif low[r]<lowest[r](TL) thene=1while low[r]=low[r+e] doe=e+1wendif low[r]<lowest[r](TL[r+e]) thenLoPoint = low[r]LoBar = barindex[r]for i = 1 to lookback doif lobar[i]<>lobar thenif lopoint[i]<lopoint thendrawsegment(loBar[i],loPoint[i],loBar,loPoint) coloured(0,200,0)breakendifendifnextendifendifreturn -
AuthorPosts