Fibonacci Retracement of breakout

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #19660 quote
    kg6450
    Participant
    Average

    Hi all, I know I’ve asked a simliar question to this in the past but I’m still finding a lot of difficulty coding this system and was hoping someone may be able to help.

    The system I am trying to code is run every day and sets the breakout box between 3am and 8am in the morning. No trades are made during this time, the box is just set.

    After this, we wait for a breakout between 8am and 2pm. This is where it gets a little complicated – Instead of trading the breakout, I want to trade the fakeout and enter at the fibonacci retracement of the previous movement.

    If price closes above high set between 3 and 8am, then an entry order is placed to short at the 61.8% retracement of the new highest high and the lowest low from between 3 and 8 am. If the time is between 8am and 2pm and price closes below the lowest low that was set between 3 and 8am then an entry order is set to buy at the 61.8% retracement of the highest high from between 3 and 8am and the new lowest low.

    I have used the fibonacci screener that was recommended to me before but what I am finding difficult is getting the correct entry levels set. I am also struggling to set the entry orders to be valid for a certain amount of time – i.e. If it gets to 3pm and either there was no breakout or price did not meet the entry order then no positions are taken and the system starts again the next day.

    So far I’ve written this on the 15min timeframe:

    DEFPARAM CumulateOrders = False
    
    MakeTrade = (Time > 080000) AND (Time < 150000)
    
    IF Time = 080000 THEN
    hh = highest[20](Close)
    ll = lowest[20](Close)
    ENDIF
    
    IF (Time > 080000) AND (Time < 140000) THEN
    TopPoint = highest[24](high)
    BottomPoint = lowest[24](low)
    SellFib = (TopPoint - ll) * 0.618
    BuyFib = (hh - BottomPoint) * 0.618
    ShortEntry = SellFib + ll
    LongEntry = hh- BuyFib
    ENDIF
    
    IF MakeTrade AND Close > hh THEN
    SELLSHORT 1 SHARES AT ShortEntry LIMIT
    ENDIF
    
    IF MakeTrade AND Close < ll THEN
    BUY 1 SHARES AT LongEntry LIMIT 
    ENDIF
    
    SET TARGET pPROFIT 10
    SET STOP pLOSS 10
    
    

    I was wondering if anyone would be able to help me with this, and Happy New Year to all!

    #19807 quote
    juanj
    Participant
    Master

    Dear kg6450

    I have coded your strategy and made some minor modifications.

    Backtested over a 2 year period the profit:drawdown ratio look good even though only short trades are triggered.

    Someone can maybe assist with resolving that but unfortunately I cannot spend too much time on this.

    I changed the strategy to run on 5min for better breakout accuracy.

    Please test and let me know what you think.

    Regards,

    DEFPARAM CumulateOrders = False
    
    //5min Fibonaci Fakeout//
    
    possize = 1
    
    Tradetime = (Time >= 090000 AND Time <= 151500)
    
    IF Time >= 090000 and time <= 090500 THEN // high-low box
    hh = highest[72](high) // highest high since 03h00
    ll = lowest[72](low) // lowest low since 03h00
    ENDIF
    
    once lfakeout = 0 //long fakout indicator
    once sfakeout = 0 //short fakeout indicator
    once ftime = 0 //time in bars above hh or below ll
    
    IF tradetime THEN
    If close > hh Then
    lfakeout = 1 //long fakeout triggered
    ftime = ftime + 1
    fakeh = highest[ftime](high) //measure highest fakeout point
    Elsif close < ll Then
    sfakeout = 1 //short fakeout triggered
    ftime = ftime + 1
    fakel = lowest[ftime](low) ////measure lowest fakeout point
    EndIf
    EndIf
    
    If lfakeout = 1 and close < hh Then
    ftime = 0 //reset fakeout time indicator
    SellFib = (fakeh - ll) * 0.618 //calculate fibonaci retracement
    ElsIf sfakeout = 1 and close > ll Then
    ftime = 0 //reset fakeout time indicator
    BuyFib = (hh - fakel) * 0.618 //calculate fibonaci retracement
    ENDIF
    
    IF lfakeout = 1 and tradetime AND Close < hh THEN
    SELLSHORT possize SHARES AT SellFib LIMIT //place short limit order
    lfakeout = 0 //reset fakeout indicator
    ElsIf sfakeout = 1 and tradetime AND Close > ll THEN
    BUY possize SHARES AT BuyFib LIMIT //place long stop order
    sfakeout = 0 //reset fakeout indicator
    ENDIF
    
    SET STOP pTrailing 380 //trailing stop for max profit
    
    Nicolas thanked this post
    #19821 quote
    kg6450
    Participant
    Average

    Hi juanj,

    Thanks so much for coding that! I’ve had a go running it and I’ve had a few problems.

    The entry point of the system doesn’t seem to be at the fib retracement level, it seems to just enter at the start of the trading hours?

    When you set the fib entry levels I think you just found the 0.618 difference between the highs and lows but didn’t actually set the order level i.e.

    If lfakeout = 1 and close < hh Then
    ftime = 0 //reset fakeout time indicator
    SellFib = (fakeh - ll) * 0.618 //calculate fibonaci retracement
    SELLENTRY = Sellfib + ll // SET SHORT ENTRY
    ElsIf sfakeout = 1 and close > ll Then
    ftime = 0 //reset fakeout time indicator
    BuyFib = (hh - fakel) * 0.618 //calculate fibonaci retracement
    BUYENTRY = hh - BUYFIB // SET BUY ENTRY
    ENDIF
    

    And then I set the entry levels at the code in bold. Does yours enter only at the start of the tradetime too?

    #19837 quote
    juanj
    Participant
    Master

    Hmm… like I said don’t really have much time to play around with it so difficult to say.

    However in keeping what works;

    Using my funky short generating code. I added a RSI (although I don’t like indicators) to help with false signals.

    And the results is quite fair considering only half of it works (see attached).

    If you can re-engineer the code to generate only longs and then run them together you would have one neat automated strategy.

    DEFPARAM CumulateOrders = False
    
    //5min Fibonaci Fakeout//
    
    possize = 1
    
    Tradetime = (Time >= 090000 AND Time <= 151500)
    
    IF Time >= 090000 and time <= 090500 THEN // high-low box
    hh = highest[72](high) // highest high since 03h00
    ll = lowest[72](low) // lowest low since 03h00
    ENDIF
    
    once lfakeout = 0 //long fakout indicator
    once sfakeout = 0 //short fakeout indicator
    once ftime = 0 //time in bars above hh or below ll
    
    IF tradetime THEN
    If close > hh Then
    lfakeout = 1 //long fakeout triggered
    ftime = ftime + 1
    fakeh = highest[ftime](high) //measure highest fakeout point
    Elsif close < ll Then
    sfakeout = 1 //short fakeout triggered
    ftime = ftime + 1
    fakel = lowest[ftime](low) ////measure lowest fakeout point
    EndIf
    EndIf
    
    If lfakeout = 1 and close < hh Then
    ftime = 0 //reset fakeout time indicator
    SellFib = (fakeh - ll) * 0.618 //calculate fibonaci retracement
    ElsIf sfakeout = 1 and close > ll Then
    ftime = 0 //reset fakeout time indicator
    BuyFib = (hh - fakel) * 0.618 //calculate fibonaci retracement
    ENDIF
    
    IF lfakeout = 1 and tradetime AND Close < hh and RSI[240](close) > 50 THEN
    SELLSHORT possize SHARES AT SellFib LIMIT //place short limit order
    lfakeout = 0 //reset fakeout indicator
    ElsIf sfakeout = 1 and tradetime AND Close > ll and RSI[240](close) < 50 THEN
    BUY possize SHARES AT BuyFib LIMIT //place long stop order
    sfakeout = 0 //reset fakeout indicator
    ENDIF
    
    SET STOP pTrailing 380 //trailing stop for max profit
    Fibonaci-Fakeout.jpg Fibonaci-Fakeout.jpg
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Fibonacci Retracement of breakout


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kg6450 @kg6450 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by juanj
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/02/2017
Status: Active
Attachments: No files
Logo Logo
Loading...