DRAWSEGMENT assistance

Viewing 15 posts - 1 through 15 (of 28 total)
  • Author
    Posts
  • #39523 quote
    IG_CFD_Trader
    Participant
    Average

    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:

    1. it connects the last 2 high points and the last 2 low points on the chart ONLY.
    2. 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

    TD-Points.itf
    #39525 quote
    Nicolas
    Keymaster
    Master

    Would 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.

    #39527 quote
    IG_CFD_Trader
    Participant
    Average
    TH=max(high,close[1])
    
    TL=min(low,close[1])
    
    r=0
    
    e=1
    
    r=strength
    
    if high[r]>highest[r](TH) then
    
    e=1
    
    while high[r]=high[r+e] do
    
    e=e+1
    
    wend
    
    if high[r]>highest[r](TH[r+e]) then
    
    HiPoint = high[r]
    
    endif
    
    Endif
    
    if low[r]<lowest[r](TL) then
    
    e=1
    
    while low[r]=low[r+e] do
    
    e=e+1
    
    wend
    
    if low[r]<lowest[r](TL[r+e]) then
    
    LoPoint = low[r]
    
    endif
    
    endif
    
    
    
    return HiPoint as "SupplyLine", LoPoint as "DemandLine"
    #39595 quote
    Nicolas
    Keymaster
    Master

    Do you want the lines to be plotted also in the price history or only about the current supply and demand zones?

    #39611 quote
    IG_CFD_Trader
    Participant
    Average

    No 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.

    #39655 quote
    Nicolas
    Keymaster
    Master

    This 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.

    //defparam drawonlastbaronly=true
    //defparam calculateonlastbars=200
    
    strength=20
    
    TH=max(high,close[1])
    TL=min(low,close[1])
    r=0
    e=1
    
    r=strength
    
    if high[r]>highest[r](TH) then
    e=1
    
    while high[r]=high[r+e] do
    e=e+1
    wend
    
    if high[r]>highest[r](TH[r+e]) then
    
    HiPoint = high[r]
    HiBar = barindex[r]
    drawsegment(HiBar[1],HiPoint[1],HiBar,HiPoint) coloured(200,0,0)
    endif
    
    Endif
    
    if low[r]<lowest[r](TL) then
    
    e=1
    while low[r]=low[r+e] do
    e=e+1
    wend
    
    if low[r]<lowest[r](TL[r+e]) then
    
    LoPoint = low[r]
    LoBar = barindex[r]
    drawsegment(LoBar[1],LoPoint[1],LoBar,LoPoint) coloured(0,200,0)
    endif
    
    endif
    
    return //HiPoint as "SupplyLine", LoPoint as "DemandLine"
    
    suppy-and-demand-lines.png suppy-and-demand-lines.png
    #39971 quote
    IG_CFD_Trader
    Participant
    Average

    Hi 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

    #39995 quote
    Nicolas
    Keymaster
    Master

    So you want to draw triangle, right?

    #39998 quote
    IG_CFD_Trader
    Participant
    Average

    Yes 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

    #40000 quote
    Nicolas
    Keymaster
    Master

    Ok but the “first preceding HiPoint” is not necessarily the previous one, it could be the 3rd ones from now, right?

    #40003 quote
    IG_CFD_Trader
    Participant
    Average

    yes absolutely.

    #40013 quote
    Nicolas
    Keymaster
    Master

    ok that’s a bit tricky, we’ll have to make a loop through history. Let’s see what can I do!

    #40014 quote
    Nicolas
    Keymaster
    Master

    This 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.

    trend-lines.png trend-lines.png
    #40047 quote
    IG_CFD_Trader
    Participant
    Average

    Looks good but you forgot to post the code 🙂 can you post the code please for the changes you made?

    #40165 quote
    Nicolas
    Keymaster
    Master

    Before posting it I wanted to be sure this was in accordance with your query, here is the code:

    strength=20
    lookback=strength*5
    
    TH=max(high,close[1])
    TL=min(low,close[1])
    r=0
    e=1
    
    r=strength
    
    if high[r]>highest[r](TH) then
    e=1
    while high[r]=high[r+e] do
    e=e+1
    wend
    if high[r]>highest[r](TH[r+e]) then
    HiPoint = high[r]
    HiBar = barindex[r]
    
    for i = 1 to lookback do
    if hibar[i]<>hibar then
    if hipoint[i]>hipoint then
    drawsegment(HiBar[i],HiPoint[i],HiBar,HiPoint) coloured(200,0,0)
    break
    endif
    endif
    next
    endif
    Endif
    
    if low[r]<lowest[r](TL) then
    e=1
    while low[r]=low[r+e] do
    e=e+1
    wend
    if low[r]<lowest[r](TL[r+e]) then
    LoPoint = low[r]
    LoBar = barindex[r]
    
    for i = 1 to lookback do
    if lobar[i]<>lobar then
    if lopoint[i]<lopoint then
    drawsegment(loBar[i],loPoint[i],loBar,loPoint) coloured(0,200,0)
    break
    endif
    endif
    next
    endif
    endif
    
    return
    
    
Viewing 15 posts - 1 through 15 (of 28 total)
  • You must be logged in to reply to this topic.

DRAWSEGMENT assistance


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
IG_CFD_Trader @wnakhoul Participant
Summary

This topic contains 27 replies,
has 2 voices, and was last updated by IG_CFD_Trader
4 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/30/2017
Status: Active
Attachments: 4 files
Logo Logo
Loading...