Indicator for identifying peaks and lows

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #34862 quote
    balance
    Participant
    Junior

    Hi Nicholas.
    I have an indicator that identifies candle sequences – ascending sequences, and descending sequences.

    I really want to continue his action.
    And on the information obtained from it, create an indicator that identifies peak and low points.

    Could you please direct me how to do this?

    Here’s how it works –

    The example is a peak search.

    . On Sunday the sequence started to rise

    . On Wednesday the rising sequence broke – and a descending sequence began

    As soon as the descending sequence begins, the indicator searches between them for the candle with the highest peak of all the candles and marks it as a peak point – with a gray or black arrow down. (Above the candle)

     

    I attach the existing code.
    (When the full code is ready, I’d be happy to share it and what you can get from it extensively – with our community members)

    // find the highest value from squence
    if highSeq < high[1] and dec = 0 then
    
    highSeq = high[1]
    HBlow = low[1] // Low of highest bar in sequence
    //Re-set the high of lowest bar
    LBHigh = 10000000000/PIPSize
    endif
    
    // find the highest value from squence
    if lowSeq > low[1] and inc = 0 then
    
    lowSeq = low[1]
    LBhigh = high[1]// High of lowest bar in sequence
    //Re-set the Low of highest bar
    HBlow = 0
    endif
    
    // Check if close is higher than high of lowest bar on the sequance
    if LBhigh < Close and inc = 0 then
    // If condition meet, make incremental as true or 1 and decrimental as 0 or false
    inc = 1
    dec = 0
    // Re-sets decremental sequence
    lowseq = 10000000000/PIPSize
    
    // Darw arrow up when chart is shifted from incremental to decrimental
    DRAWARROWUP(barindex, low - ArrowDistance*Pipsize) COLOURED(UpArrowRValue,UpArrowGValue,UpArrowBValue)
    
    endif
    
    // Check if close is lower than low of highest bar on the sequance
    if HBlow > Close and dec = 0 then
    dec = 1
    inc = 0
    // Re-sets incremental sequence
    highseq = 0
    // Darw arrow up when chart is shifted from incremental to decrimental
    DRAWARROWDOWN(barindex, high+ArrowDistance*Pipsize) COLOURED(DownArrowRValue,DownArrowGValue,DownArrowBValue)
    endif
    // Only for drawing line on the chart
    if inc = 1 and ShowMA then
    DRAWSEGMENT(barindex[1],low[1],barindex,low[0]) COLOURED(0,255,0)
    endif
    if dec = 1 and ShowMA then
    DRAWSEGMENT(barindex[1],high[1],barindex[0],high[0]) COLOURED(255,0,0)
    endif
    
    return //Nothing will be returned because it has to be shown in price

    Edited by moderator to make “PRT code” format appear, please use “insert PRT code” button

     

    I very much beg your help – and thank you in advance.

    Example-of-the-requested-indicator.png Example-of-the-requested-indicator.png Identification-of-peaks-and-lows.docx
    #34917 quote
    Nicolas
    Keymaster
    Master

    On your example, why is the ascending sequence only broke on Wednesday since 2 descending candlesticks has already been met since the lastest high?

    Does a sequence only start after X new highs / Y new lows?

    #34982 quote
    StantonR
    Participant
    Senior

    HI Balance

    You invited me to work on this on Freelancer.com. Better to do it here can help you for free then.
    When you first posted it to me I was looking at the Bill Williams Fractals as a possible solution.

    Bill Williams Fractals

    This Identifies the pivot points.

    fractals.png fractals.png
    #35134 quote
    balance
    Participant
    Junior

    Hi Nicholas,
    Hope I understood your question correctly.

    Sequences are not dependent on peaks and lows, but on other conditions.
    For example – the condition for a rising sequence is – as long as the closing price of the current candle does not fall below the lowest of the highest candle in the rising sequence.

    In fact, the peak can only be determined after the ascending sequence has ended, because if I understand correctly, you can not delete arrows after they have already been marked in the graph

    #35138 quote
    balance
    Participant
    Junior

    Hi StantonR

    First of all thank you for your kindness.
    And the proposal to use the indicator you mentioned.

    But, after looking at him, he seemed to have a real flood of arrows.
    It seems to me that according to my proposal there will be far fewer (each sequence can have only one point of peak or low)

    Am I not right? Please write me what you think.

    (By the way, you are still invited to accept my invitation.) What is your FREELANCER username?

    #35164 quote
    Nicolas
    Keymaster
    Master

    So let’s try this code and give us your feedbacks about it. Just a rough code, because I’m busy this morning 🙂

    if close>close[1] and close>hightrough then
    //low of current peak
    lowpeak = low
    endif
    
    if close<close[1] and (close<lowpeak or lowpeak=0) then
    //high of current tough
    hightrough = high
    endif
    
    if hightrough>hightrough[1] then
    drawarrowdown(barindex[1],high[1])coloured(200,0,0)
    endif
    
    if lowpeak<lowpeak[1] then
    drawarrowup(barindex[1],low[1])coloured(0,200,0)
    endif
    
    return 
    swing-peak-and-tough.png swing-peak-and-tough.png
    #35348 quote
    Sofitech
    Participant
    Master

    Hello Nicolas.
    How can I create a return instruction show a result I can use to create alert on my chart ? (with your code).

    #35364 quote
    Nicolas
    Keymaster
    Master

    You should use this code instead and get the values of the “up” and “down” variables in your own automated trading strategy:

    if close>close[1] and close>hightrough then
    //low of current peak
    lowpeak = low
    endif
    
    if close<close[1] and (close<lowpeak or lowpeak=0) then
    //high of current tough
    hightrough = high
    endif
    
    if hightrough>hightrough[1] then
    drawarrowdown(barindex[1],high[1])coloured(200,0,0)
    down=1
    else
    down=0
    endif
    
    if lowpeak<lowpeak[1] then
    drawarrowup(barindex[1],low[1])coloured(0,200,0)
    up=1
    else
    up=0
    endif
    
    return up, down
    #35470 quote
    balance
    Participant
    Junior

    Hi Nicholas,
    Thanks for the code you submitted. He looked great.
    But I have some comments on it to improve,

    1. There are lots of high and low points, making it difficult to filter.
    2 are often not placed in an exact place – for example, you can see in the attached screenshot – a number of low points located in the middle of the rise …

    According to the definition I raised at the beginning of the topic – there will be far fewer points on the graph.

    I have attached two examples. You can see in them that there is a huge difference (75%) in the number of arrows on the graph compared to what is currently there.

    So what are you saying ? What do you think ?
    Could you please help develop something like this?

    As mentioned above, I have attached two examples. One – of the results of the code at the moment. And the second – of the desired results according to the definitions I wrote above.

    Thanks again.
    And a wonderful week.

    chaim (balance)

    Example-of-existing-indicator.png Example-of-existing-indicator.png
    #35472 quote
    balance
    Participant
    Junior

    It seems that the second example did not come up,
    So I bring it up again.

    Example-of-the-code-requested.png Example-of-the-code-requested.png
    #35651 quote
    GraHal
    Participant
    Master

    If anybody is interested I made a Strategy out of Nicolas Code.

    Seemed rude not to! 🙂
    GraHal

    Dax 1 Day and I just realised the results below are over only 1000 Days, Oops!  It was just a ‘curiosity exercise’ anyway.

    //https://www.prorealcode.com/topic/indicator-for-identifying-peaks-and-lows/
    //Nic HighsLows Dax 1D
    
    DEFPARAM CUMULATEORDERS = False
    
    if close>close[1] and close>hightrough then
    //low of current peak
    lowpeak = low
    endif
     
    if close<close[1] and (close<lowpeak or lowpeak=0) then
    //high of current tough
    hightrough = high
    endif
     
    if hightrough>hightrough[1] then
    //drawarrowdown(barindex[1],high[1])coloured(200,0,0)
    down=1
    else
    down=0
    endif
     
    if lowpeak<lowpeak[1] then
    //drawarrowup(barindex[1],low[1])coloured(0,200,0)
    up=1
    else
    up=0
    endif
    
    If Up=1 and Chandle[20](close) > -45 Then
    Buy at Market
    Endif
    
    If Down=1 and Chandle[20](close) < 35 Then
    SellShort at Market
    Endif
    
    //Alternative Exit
    //If LongonMarket and Close < ExponentialAverage[190](close) Then
    //Sell at Market
    //endif
    //
    //If ShortonMarket and Close > ExponentialAverage[150](close) Then
    //Exitshort at Market
    //endif
    
    If LongonMarket Then
    SET TARGET PPROFIT 425
    SET STOP PTRAILING 725
    Endif
    
    If ShortonMarket Then
    SET TARGET PPROFIT 175
    SET STOP PTRAILING 400
    Endif
    
       
     
    //return up, down
    
    Nic1.jpg Nic1.jpg Nic2.jpg Nic2.jpg Nic-HighsLows-Dax-1D.itf
    #36587 quote
    Copperwave
    Participant
    Veteran

    Hi – I have been looking into this and while the concept is good, it is asking too much of price action behaviour to work reliably…unless I’m missing something in your signal definitions. The indicator Nicolas prototyped does what you ask. Where it fails, (in terms of too many false positives) is because that is what price action does. Price chop you will get multiple triggers. I think filtering those out requires some sort of lookback comparison in which case then you might as well use a variation of  Fractals.

    For what its worth I made a small tweak to Nicolas’s code (I added [1] to the high/low statements in the draw sections) that reduces the false positives by about 50% but I think the basic concept is flawed. It will work fine if candles appear in an organised uptrend/downtrend but this rarely happens. It looks good in static analysis but will fail in realtime use – I think 🙂 Still nice idea – but my coding isn’t good enough.

    if (close>close[1]) and (close>hightrough) then
    //low of current peak
    lowpeak = low
    endif
    if (close<close[1]) and (close<lowpeak) then
    //high of current trough
    hightrough = high
    endif
    if hightrough>hightrough[1] then
    drawarrowdown(barindex[1],high[1])coloured(200,0,0)
    hightrough = high[1]
    endif
    
    if lowpeak<lowpeak[1] then
    drawarrowup(barindex[1],low[1])coloured(0,200,0)
    lowpeak = low[1]
    endif
    
    return

     

     

    Best

    //copperwave

    Nicolas thanked this post
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Indicator for identifying peaks and lows


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
balance @balance Participant
Summary

This topic contains 11 replies,
has 6 voices, and was last updated by Copperwave
8 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/08/2017
Status: Active
Attachments: 9 files
Logo Logo
Loading...