Previous bar low from highest bar achieved !

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #138016 quote
    Slowlyslowly
    Participant
    Average

    Hi

    how would you code wanting a break of the previous bar low  On the bar prior to the highest bar since the code was activated ? And if a new highest bar was achieved it then moves to recognise the new bar as the highest so targets the bar previous low ?

    #138106 quote
    GraHal
    Participant
    Master

    A picture / screen shot tells a thousand words?

    I’ve read it 4 times and it still isn’t forming a picture in my mind … I might be tired!? 🙂

    #138109 quote
    robertogozzi
    Moderator
    Master

    This is what I coded, provided I could correctly understand what you meant:

    IF BarIndex = 0 THEN                               
       // initialization of variables
       MyHI  = high
       MyBAR = 0
       Entry = 0
    ELSE
       // find new HIGH (MyHI), if any, and eventually update bar index (MyBAR)
       MyHI  = max(MyHI,high)
       MyBAR = max(MyBAR,BarIndex * (MyHI <> MyHI[1]))
    ENDIF
    IF BarIndex > 3 THEN
       //we need at least 3 bars:
       // 1 = the HIGHest
       // 2 = the bar prior to the HIGHEST
       // 3 = the LOW of the bar PRIOR to #2
       i     = BarIndex - MyBAR
       Entry = low[i - 2]
    ENDIF
    // ENTRY is the price you want to break
    Slowlyslowly thanked this post
    #138110 quote
    robertogozzi
    Moderator
    Master

    Try adding this indicator to your chart, to display a histogram whenever a new HIGH is found (start with 200 units, to make sure you don’t have to scroll backwards too far):

    IF BarIndex = 0 THEN
       // initialization of variables
       MyHI  = high
       MyBAR = 0
       //Entry = 0
    ELSE
       // find new HIGH (MyHI), if any, and eventually update bar index (MyBAR)
       MyHI  = max(MyHI,high)
       MyBAR = max(MyBAR,BarIndex * (MyHI <> MyHI[1]))
    ENDIF
    IF BarIndex > 3 THEN
       //we need at least 3 bars:
       // 1 = the HIGHest
       // 2 = the bar prior to the HIGHEST
       // 3 = the LOW of the bar PRIOR to #2
       //i     = BarIndex - MyBAR
       //Entry = low[i - 2]
    ENDIF
    x = 0
    IF MyHI <> MyHI[1] THEN
       x = 1
    ENDIF
    RETURN x AS "Signal"
    Slowlyslowly thanked this post
    #138113 quote
    Slowlyslowly
    Participant
    Average

    Thanks GRAHAL, good idea I’ve now uploaded screen shots – first shows initial set up it takes the highest new bar SINCE code activated. and would trigger a sell when the low of the previous bar is hit . If a new higher bar is achieved it ignores the previous and resets with this new bar and takes the previous bar low as the trigger.

    Paul and GraHal thanked this post
    Screenshot-2020-07-02-at-15.57.44.png Screenshot-2020-07-02-at-15.57.44.png Screenshot-2020-07-02-at-15.56.11.png Screenshot-2020-07-02-at-15.56.11.png
    #138218 quote
    Slowlyslowly
    Participant
    Average

    Roberto

     

    Is it also possible that if the previous bar close is NOT lower than the current bar close nothing is triggered and it looks back to find a previous bar close that is lower than the current bar to activate on ?

    #138271 quote
    robertogozzi
    Moderator
    Master

    There you go:

    IF close[1] >= close THEN
    //   add here the code preventing an event from being triggered
    ENDIF
    #138386 quote
    Slowlyslowly
    Participant
    Average

    Roberto

     

    The code just enters on the first bar close from when the code is activated, every time – seems to be no relation to your code just added a c1 and c2 ?

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Prevents the system from placing new orders on specified days of the week
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    IF BarIndex = 0 THEN
    // initialization of variables
    MyHI  = high
    MyBAR = 0
    Entry = 0
    ELSE
    // find new HIGH (MyHI), if any, and eventually update bar index (MyBAR)
    MyHI  = max(MyHI,high)
    MyBAR = max(MyBAR,BarIndex * (MyHI <> MyHI[1]))
    ENDIF
    IF BarIndex > 3 THEN
    //we need at least 3 bars:
    // 1 = the HIGHest
    // 2 = the bar prior to the HIGHEST
    // 3 = the LOW of the bar PRIOR to #2
    i     = BarIndex - MyBAR
    Entry = low[i - 2]
    c1= myhi>6535
    c2=entry-2
    ENDIF
    if not daysforbiddenentry and c1 and c2 then
    SELLSHORT 3  perpoint AT MARKET
    // ENTRY is the price you want to break
    // Stops and targets
    SET STOP pLOSS 100
    SET TARGET pPROFIT 100
    endif

     

    ?? am i doing something wrong ?

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

Previous bar low from highest bar achieved !


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by Slowlyslowly
5 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/01/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...