Breakout next 5 Bars

Viewing 15 posts - 1 through 15 (of 47 total)
  • Author
    Posts
  • #207461 quote
    killerplatuze
    Participant
    New

    Hi,

    if i have a popgun i wanna go short if one of the next 5 bars is lower than the last bar of the popgun is, the opposite for long. SL under the last bar of the popgung -5 points, long the opposite.

    I this dont happend the order should be cancel.

    How can i code this?

    PG = High[2]>High[1] and Low[2]<Low[1] and High>High[1] and Low<Low[1]

    #207468 quote
    JS
    Participant
    Senior

    Hi @killerplatuze

    Try this one…

    DefParam CumulateOrders=False
    
    //PopGun
    If High[7]>High[6] and Low[7]<Low[6] and High[5]>High[6] and Low[5]<Low[6] then
    If Low[4]<Low[5] or Low[3]<Low[5] or Low[2]<Low[5] or Low[1]<Low[5] or Low<Low[5] then
    SellShort 1 contract at Market
    Set Stop Price Low[5]+5
    EndIf
    If High[4]>High[5] or High[3]>High[5] or High[2]>High[5] or High[1]>High[5] or High>High[5] then
    Buy 1 contract at Market
    Set Stop Price High[5]-5
    EndIf
    EndIf
    killerplatuze thanked this post
    Scherm­afbeelding-2023-01-15-om-17.18.53.png Scherm­afbeelding-2023-01-15-om-17.18.53.png
    #207473 quote
    killerplatuze
    Participant
    New

    This doesn’t work. The first 3 bars are the Popgun, if the conditions are true. The 3th bar is the the triggerbar, the next 5 bars are the bars which can break out.

    But it works with OR.

    But i have a problem with TP and SL. The SL should be 5 points below the triggerbar if long.

    The TP should be one ATR of the triggerbar.

    So i need help again with TP and SL, thx a lot.

     

     

    DefParam CumulateOrders=False
    
    PG = High[2]>High[1] and Low[2]<Low[1] and High>High[1] and Low<Low[1]
    TP = AverageTrueRange[1]
    
    //PopGun
    If PG then
    If High[3] OR High[4] OR High[5] OR High[6] OR High[7] then
     Buy 1 contract at Market
    Set Stop Price Low[2]-5
    Set Target Profit TP
    EndIf
    Endif
    PG.jpg PG.jpg
    #207476 quote
    JS
    Participant
    Senior

    You have 3 bars for the PopGun and 5 bars for the breakout, a total of 8 bars…

    From right to left B[0] B[1] B[2] B[3] B[4] B[5] B[6] and B[7] (total 8 bars)

    “If High[3] or High[4]” and so on is not a valid condition because they are all true…

    There is a High[3] (true) or there is a High[4] (true) and so on…

    The conditions in the code match your story…

    You can put the Stop wherever you want but your trigger bar is B[5] and not B[2]

    If you want to use the ATR for your TP, this ATR will have to be calculated over a certain (lookback) period…

    killerplatuze thanked this post
    #207477 quote
    killerplatuze
    Participant
    New
    Thx, i have seen my mistake.   But if i use your code the result is wrong, as you can see it at the attached picture The buy for the first PG is on Bar too late, the buy for the second bar ist 2 bars too late.
    PG2.jpg PG2.jpg
    #207479 quote
    JS
    Participant
    Senior

    Unfortunately it doesn’t work that way, the order is…

    1. B[5] is the trigger bar
    2. B[4] is the breakout bar, here is the condition true and then the next bar…
    3. Buy when B[3] opens…

    This is the order in which PRT processes the market orders…

    #207481 quote
    JS
    Participant
    Senior

    Alternatively, you can use Stop orders instead of market orders…

    Buy 1 contract at High[5] STOP

    These orders are executed immediately…

    killerplatuze thanked this post
    #207482 quote
    killerplatuze
    Participant
    New
    This Order must be canceled if no bar gets a trigger, how can in do this?
    #207483 quote
    JS
    Participant
    Senior

    These STOP orders are “pending” orders and they start at the beginning of the new bar and are valid until the end of that bar…

    So, when the condition (PopGun) is true then these pending orders are started /placed and when not hit in the next five bars (under a certain conditions) then this “pending STOP order” will not be placed afterwards …

    So, you don’t have to cancel anything…

    For example:

    PopGun is true  extra condition is true  place the pending stop orders  pending stop order is hit  extra condition is no longer true  no more placement of the pending STOP orders…

    killerplatuze thanked this post
    #207485 quote
    JS
    Participant
    Senior

    I think you can reduce the code to this…

    DefParam CumulateOrders=False
    
    //PopGun
    If High[7]>High[6] and Low[7]<Low[6] and High[5]>High[6] and Low[5]<Low[6] then
    Buy 1 contract at High[5] STOP
    SellShort 1 contract at Low[5] STOP
    Set Stop Price Low[5]+5
    Set Stop Price High[5]-5
    EndIf
    Scherm­afbeelding-2023-01-15-om-22.49.21.png Scherm­afbeelding-2023-01-15-om-22.49.21.png
    #207487 quote
    JS
    Participant
    Senior

    I think you’ve found a nice pattern…

    Excellent Risk/Reward ratio

    Excellent Profit/Loss ratio

    %profit trades is bad but that’s because there are a lot of small losses that are offset by relatively large profits…

    This can probably be improved…

    killerplatuze thanked this post
    #207490 quote
    killerplatuze
    Participant
    New
    Something is wrong, the trade starts much too late
    PG3.jpg PG3.jpg
    #207495 quote
    JS
    Participant
    Senior

    You must go back to the first code and replace the market orders with STOP orders…

    (The last code only looks at the PopGun)

    #207502 quote
    killerplatuze
    Participant
    New
    DefParam CumulateOrders=False
     
    //PopGun
    If High[7]>High[6] and Low[7]<Low[6] and High[5]>High[6] and Low[5]<Low[6] then
    If Low[4]<Low[5] or Low[3]<Low[5] or Low[2]<Low[5] or Low[1]<Low[5] or Low<Low[5] then
    sellShort 1 contract at Low[5] STOP
    Set Stop Price Low[5]+5
    EndIf
    If High[4]>High[5] or High[3]>High[5] or High[2]>High[5] or High[1]>High[5] or High>High[5] then
    Buy 1 contract at High[5] STOP
    Set Stop Price High[5]-5
    EndIf
    EndIf
    This is the code, same result. Trade starts much too late. Its crazy.
    #207516 quote
    JS
    Participant
    Senior

    Hi,

    You can try this one…

    The problem is that your PopGun in its current form does not indicate a direction (Long or Short)…

    DefParam CumulateOrders=False
    //PopGun
    If High[2]>High[1] and Low[2]<Low[1] and High>High[1] and Low<Low[1] then
    Buy 1 contract at High STOP
    Set Stop Price High-50
    SellShort 1 contract at Low STOP
    Set Stop Price Low+50
    EndIf
    killerplatuze thanked this post
Viewing 15 posts - 1 through 15 (of 47 total)
  • You must be logged in to reply to this topic.

Breakout next 5 Bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 46 replies,
has 5 voices, and was last updated by Chrisinobi
3 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/15/2023
Status: Active
Attachments: 11 files
Logo Logo
Loading...