Fibonacci Retracement of breakout
Forums › ProRealTime English forum › ProOrder support › Fibonacci Retracement of breakout
- This topic has 3 replies, 2 voices, and was last updated 8 years ago by
juanj.
-
-
01/02/2017 at 11:58 PM #19660
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:
12345678910111213141516171819202122232425262728DEFPARAM CumulateOrders = FalseMakeTrade = (Time > 080000) AND (Time < 150000)IF Time = 080000 THENhh = highest[20](Close)ll = lowest[20](Close)ENDIFIF (Time > 080000) AND (Time < 140000) THENTopPoint = highest[24](high)BottomPoint = lowest[24](low)SellFib = (TopPoint - ll) * 0.618BuyFib = (hh - BottomPoint) * 0.618ShortEntry = SellFib + llLongEntry = hh- BuyFibENDIFIF MakeTrade AND Close > hh THENSELLSHORT 1 SHARES AT ShortEntry LIMITENDIFIF MakeTrade AND Close < ll THENBUY 1 SHARES AT LongEntry LIMITENDIFSET TARGET pPROFIT 10SET STOP pLOSS 10I was wondering if anyone would be able to help me with this, and Happy New Year to all!
01/04/2017 at 12:23 PM #19807Dear 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,
12345678910111213141516171819202122232425262728293031323334353637383940414243444546DEFPARAM CumulateOrders = False//5min Fibonaci Fakeout//possize = 1Tradetime = (Time >= 090000 AND Time <= 151500)IF Time >= 090000 and time <= 090500 THEN // high-low boxhh = highest[72](high) // highest high since 03h00ll = lowest[72](low) // lowest low since 03h00ENDIFonce lfakeout = 0 //long fakout indicatoronce sfakeout = 0 //short fakeout indicatoronce ftime = 0 //time in bars above hh or below llIF tradetime THENIf close > hh Thenlfakeout = 1 //long fakeout triggeredftime = ftime + 1fakeh = highest[ftime](high) //measure highest fakeout pointElsif close < ll Thensfakeout = 1 //short fakeout triggeredftime = ftime + 1fakel = lowest[ftime](low) ////measure lowest fakeout pointEndIfEndIfIf lfakeout = 1 and close < hh Thenftime = 0 //reset fakeout time indicatorSellFib = (fakeh - ll) * 0.618 //calculate fibonaci retracementElsIf sfakeout = 1 and close > ll Thenftime = 0 //reset fakeout time indicatorBuyFib = (hh - fakel) * 0.618 //calculate fibonaci retracementENDIFIF lfakeout = 1 and tradetime AND Close < hh THENSELLSHORT possize SHARES AT SellFib LIMIT //place short limit orderlfakeout = 0 //reset fakeout indicatorElsIf sfakeout = 1 and tradetime AND Close > ll THENBUY possize SHARES AT BuyFib LIMIT //place long stop ordersfakeout = 0 //reset fakeout indicatorENDIFSET STOP pTrailing 380 //trailing stop for max profit1 user thanked author for this post.
01/04/2017 at 2:57 PM #19821Hi 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.
12345678910<span class="token keyword">If</span> lfakeout <span class="token operator">=</span> <span class="token number">1</span> <span class="token keyword">and</span> <span class="token keyword">close</span> <span class="token operator"><</span> hh Thenftime <span class="token operator">=</span> <span class="token number">0</span> <span class="token comment" spellcheck="true">//reset fakeout time indicator</span>SellFib <span class="token operator">=</span> <span class="token punctuation">(</span>fakeh <span class="token operator">-</span> ll<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">0.618</span> <span class="token comment" spellcheck="true">//calculate fibonaci retracement</span>SELLENTRY = Sellfib + ll // SET SHORT ENTRYElsIf sfakeout <span class="token operator">=</span> <span class="token number">1</span> <span class="token keyword">and</span> <span class="token keyword">close</span> <span class="token operator">></span> ll Thenftime <span class="token operator">=</span> <span class="token number">0</span> <span class="token comment" spellcheck="true">//reset fakeout time indicator</span>BuyFib <span class="token operator">=</span> <span class="token punctuation">(</span>hh <span class="token operator">-</span> fakel<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">0.618</span> <span class="token comment" spellcheck="true">//calculate fibonaci retracement</span>BUYENTRY = hh - BUYFIB // SET BUY ENTRY<span class="token keyword">ENDIF</span>And then I set the entry levels at the code in bold. Does yours enter only at the start of the tradetime too?
01/04/2017 at 4:31 PM #19837Hmm… 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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546DEFPARAM CumulateOrders = False//5min Fibonaci Fakeout//possize = 1Tradetime = (Time >= 090000 AND Time <= 151500)IF Time >= 090000 and time <= 090500 THEN // high-low boxhh = highest[72](high) // highest high since 03h00ll = lowest[72](low) // lowest low since 03h00ENDIFonce lfakeout = 0 //long fakout indicatoronce sfakeout = 0 //short fakeout indicatoronce ftime = 0 //time in bars above hh or below llIF tradetime THENIf close > hh Thenlfakeout = 1 //long fakeout triggeredftime = ftime + 1fakeh = highest[ftime](high) //measure highest fakeout pointElsif close < ll Thensfakeout = 1 //short fakeout triggeredftime = ftime + 1fakel = lowest[ftime](low) ////measure lowest fakeout pointEndIfEndIfIf lfakeout = 1 and close < hh Thenftime = 0 //reset fakeout time indicatorSellFib = (fakeh - ll) * 0.618 //calculate fibonaci retracementElsIf sfakeout = 1 and close > ll Thenftime = 0 //reset fakeout time indicatorBuyFib = (hh - fakel) * 0.618 //calculate fibonaci retracementENDIFIF lfakeout = 1 and tradetime AND Close < hh and RSI[240](close) > 50 THENSELLSHORT possize SHARES AT SellFib LIMIT //place short limit orderlfakeout = 0 //reset fakeout indicatorElsIf sfakeout = 1 and tradetime AND Close > ll and RSI[240](close) < 50 THENBUY possize SHARES AT BuyFib LIMIT //place long stop ordersfakeout = 0 //reset fakeout indicatorENDIFSET STOP pTrailing 380 //trailing stop for max profit -
AuthorPosts
Find exclusive trading pro-tools on