Breakout after 5 candles

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #204107 quote
    f1_maik
    Participant
    Junior

     

    Dear ones.
    I need your help again. I’m sorry, but that’s the way it is. Please. Maybe one or the other can shake it from the sleeve.

    We have for the sake of simplicity an Outside.
    Now I would like to set the buy stop 5 points above the high of the candles. But the buy stop should only be executed within 5 candles (n -candles).
    This kind of stops after trigger candles can be found in the strategies of e.g. the Hikkake here
    https://www.prorealcode.com/prorealtime-indicators/hikkake-pattern/.

    Please, do anyone help?

    #204186 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE Tally = 0
    OutSideBAR = (high > high[1]) AND (low < low[1])
    IF OutSideBAR AND Not OnMarket THEN
       Tally = 1
       Entry = high + 5 * PipSize    //Entry price = HIGH + 5 pips
    ENDIF
    IF Tally > 5 OR OnMarket THEN
       Tally = 0
    ELSIF Tally[1] > 0 THEN
       Tally = Tally + 1
    ENDIF
    IF Tally AND Not OnMarket THEN
       BUY 1 CONTRACT AT Entry STOP
       SET STOP   pLOSS   20
       SET TARGET pPROFIT 20
    ENDIF
    //graph Tally
    f1_maik thanked this post
    #204467 quote
    f1_maik
    Participant
    Junior

    Hello Roberto.

    Thank you very much for the code. I just got around to looking at it today and ! – I want to say your code really helps me a lot. Now I can implement it in several (known) strategies. I will offer the strategies here if done. Thank you very much.

    As I see the program performs the buy stop several times within the 5 candles provided the conditions are met. See the screenshot and more detailed there after the 2.Outside.

    Can you change me the code so that it enters only 1 position within the predefined 5 candles? “not onmarket” does not help because the SL/TP is very low and new positions can be entered again and again. If I set the SL/TP on my 200 points, then it works, but is not in my sense. One ( first) position should be opened and then no more within the 5 candles.

    very kind regards to you

    #204470 quote
    f1_maik
    Participant
    Junior

    Thank you! It should be like this?

     

     

    ONCE Tally = 0
    
    OutSideBAR = (high > high[1]) AND (low < low[1])
    IF OutSideBAR AND Not OnMarket THEN
    Tally = 1
    Entry = high + 5 * PipSize //Entry price = HIGH + 5 pips
    ENDIF
    
    IF Tally > 5 OR OnMarket THEN
    Tally = 0
    ELSIF Tally[1] > 0 THEN
    Tally = Tally + 1
    ENDIF
    
    MaxShares = abs(COUNTOFPOSITION) <= 1
    
    IF Tally AND Not OnMarket AND MaxShares THEN
    BUY 1 CONTRACT AT Entry STOP
    SET STOP   pLOSS   20
    SET TARGET pPROFIT 20
    ENDIF
    
    //graph Tally
    #204521 quote
    VinzentVega
    Participant
    Veteran

    I tried it to optimize this setup, but the results are in all timeframes with tick-by-tick backup, horrible.

    #204527 quote
    GraHal
    Participant
    Master

    with tick-by-tick backup, horrible.

    Any ideas why this is so and / or any ideas for improvement?

    f1_maik thanked this post
    #204528 quote
    VinzentVega
    Participant
    Veteran

    with tick-by-tick backup, horrible.

    Any ideas why this is so and / or any ideas for improvement?

    Well, I think SL/TP are to close

    f1_maik thanked this post
    #204540 quote
    f1_maik
    Participant
    Junior

    Please excuse me. It was not about the strategy of trading exactly this breakout. It was about the coding itself, how the code can look like – to trade the breakout after n candles after one candle.

    GraHal thanked this post
    #204541 quote
    f1_maik
    Participant
    Junior

    Examples

    We have a new 20 candle high that is immediately sold. We want to buy on a breakout above the high candle, but only within 10 candles.

    We are trading an IDNR4 and want to buy/sell on a breakout (long/short) within the next 2 candles.

    The same with PopGuns.

    Or finer. We buy on a breakout above a bearish divergence within the next n candles.
    Etc etc

    I miss the basic programming skills, I’m sorry, thanks for your help

    #204543 quote
    JS
    Participant
    Senior

    Hi @f1_maik

    I tried Roberto’s first code and don’t see that the code opens multiple positions within 5 candles…
    In your answer #204467 you talk about a screenshot and more details but unfortunately this screenshot has not been uploaded…
    Can you post it again?

    #204550 quote
    f1_maik
    Participant
    Junior

    Enclosed is the screenshot, 4H candle in the Dax
    You can try it yourself, big candle small SL/TP

    Screenshot_2.jpg Screenshot_2.jpg
    #204681 quote
    robertogozzi
    Moderator
    Master

    Try replacing line 9 with this one, to account for trades opened and closed on the same bar:

    IF Tally > 5 OR OnMarket OR (StrategyProfit <> StrategyProfit[1]) THEN
    f1_maik thanked this post
    #204695 quote
    f1_maik
    Participant
    Junior

    Thank you Roberto for making this clear.
    My mistake not to read you correctly, I would never have noticed otherwise
    Thank you

    #209690 quote
    f1_maik
    Participant
    Junior

    Hello Roberto.
    Again me and again on the subject of breakout in the next 5 candles.

    The problem is as follows.
    Above we have the SL and TP with 20 points and the trade starts directly in the 1.candle after the Outside and wins.
    Then the price immediately falls below the StopBuy and in the next candle we trigger the StopBuy and a 2nd trade is started within the 5 candles. This 2nd or 3rd or 4….. Trade I would like to prevent.

    How to code that the breakout is traded only once within the 5 candles? Cumulateorders false does not work sufficiently, dito not onmarket and the like. It must be ensured that the trade starts only 1x.

    Can it solve countofposition? Countofposition <= 1 within the last 5 candles? Something like that? Can this be programmed in PRT, what would be the code for it?

    lg

    #210296 quote
    robertogozzi
    Moderator
    Master

    This should work (I added the OTD check, One Trade per Day):

    ONCE Tally = 0
    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
    OutSideBAR = (high > high[1]) AND (low < low[1])
    IF OutSideBAR AND Not OnMarket THEN
       Tally = 1
      Entry = high + 5 * PipSize //Entry price = HIGH + 5 pips
    ENDIF
    
    IF Tally > 5 OR OnMarket OR (StrategyProfit <> StrategyProfit[1]) THEN
       Tally = 0
    ELSIF Tally[1] > 0 THEN
       Tally = Tally + 1
    ENDIF
     
    MaxShares = abs(COUNTOFPOSITION) <= 1
     
    IF Tally AND Not OnMarket AND MaxShares AND OTD THEN
       BUY 1 CONTRACT AT Entry STOP
       SET STOP   pLOSS   20
       SET TARGET pPROFIT 20
    ENDIF
     
    //graph Tally
    Midlanddave and f1_maik thanked this post
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Breakout after 5 candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
f1_maik @f1_maik Participant
Summary

This topic contains 16 replies,
has 5 voices, and was last updated by robertogozzi
6 months, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/13/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...