Fibonacci 61.8 retracement strategy
Author: JamirShaikh
Creation Date: 4/1/2014 4:48 PM
profile picture

JamirShaikh

#1
Dear Experts,

I am new to Wealth Lap pro, starting to understand how it all works. Here is my requirement:

1. Find 61.8 retracement of a 10% swing ( can be variance and changed to parameter later)
• For rising chart it is 61.8% from the though (short)
• For falling chart it is 61.8% from the peak (long)
2. Execute to buy/sell position using interday 10 minutes chart
3. Cover/Sell the position when one of these conditions satisfies
• Price changes negatively 5% of the execution price
• OR price changes positively by 38.2% between purchase {price and through} or {price or Peak}
4. Strategy is back testable

I am not through the entire logic, having lots of issues on how to make it work

My Current Code:
CODE:
Please log in to see this code.
profile picture

Cone

#2
QUOTE:
For rising chart it is 61.8% from the though (short)
Does this mean you want to go short at the 0.618 retrace back to the 10% peak? A 0.618 retrace following a 10% peak may not be sufficient to create a 10% trough, so you cannot assume that a trough will exist at the time you sell short.... but you can detect a retrace toward the peak.

Anyway, the requirements/explanation is too confusing for me. Try explaining it in terms of a long position only. Post a real chart with an example of what it should look like using the Drawing Tools.
profile picture

JamirShaikh

#3
Thank you cone for response.

Here is an example long position (attached picture).


profile picture

Cone

#4
You marked the chart "Peak", and this is easy to see in hindsight. What I'm saying is that your "Peak" may not actually be a Peak as defined by the 10% (n%) retrace percentage.

As long as you agree that once the Trough is found, which means that price has risen 10% (or n%), any 0.618 retrace will be bought - whether or not it is actually becomes a true "Peak". For example, since there is no scale on the chart, if that Trough were detected 6 bars later, that first big red bar would have probably retraced 0.618 and be bought... but you didn't mark that Peak.

So, if you understand what I'm saying, in many cases, the "Peak" will not turn out to be n% peak (and in that case, you will have a winning trade if you get the 0.618 retrace). The question is, "what then?" Do you buy again at the 0.618 retrace from the same "peak point"? Or, would you ignore it. For example, I can see 2 buys crossing the 0.618 and 1 sell at 0.382 in your chart.

Also, if a higher peak is reached, do you buy the [new] 0.618 level? Or is one trade from the trough all that you're looking for?

I see how you'd work in shorting following a long profit target, but a short wouldn't be triggered unless "Peak" were actually a 10% Peak. I hope you follow what I'm saying.
profile picture

JamirShaikh

#5
Here is what I am thinking...

Find the first closest peak or though (based on percentage - example 10%).
If though is closest - find closest peak (not based on %)
if falls to the right prior to current bar - Long
if falls to the left prior to current bar - Short

For peak is closest - find closet though (not based on %)
if falls to the right prior to current price - Long
if falls to the right prior to current price - Short

Take the though and peak above and calculate 61.8% retracement (from the closet high/low bar) and take the trade Long/Short when price corss the the retracement price first time. For our attached example, it went up after touching 61.8% and went upto 38.2% retracement, so it will have sold prior to coming in for second time to the 61.8%, we will not take the position around second time ... If it does not go up 38.2% (between the long and peak) and start dropping below 61.8% we will cover with 5% loss.

Close at
5% loss
OR when it reaches 38.2% between the trade point and prior identified though or peak.

Thank you again cone!
profile picture

Cone

#6
Here's the long strategy to get you started. It uses the ZigZag Class Reference (click) to easily identify peaks and troughs between the High and Low series. Although it simplifies the script, it may be a little complex to understand the "moving parts" of it at first.

NOTE! This requires that you install the Community.Components extension from this site.

You can run the code on any time frame, but start with a Daily (or 30 min) chart to visualize more trading opportunities.

CODE:
Please log in to see this code.
profile picture

Gerig

#7
Thank Cone, with great pleasure to read your script, as always perfectly.
profile picture

kcbars

#8
Hello. I've been experimenting with this on an intraday basis, and the problem I keep having is if a sell order is generated by the strategy but not filled, then I end up with multiple buys. I've tried changing the sell logic to use market orders,

CODE:
Please log in to see this code.


This helps, but is still not perfect. I've tried inserting if ActivePosition.Count < 1, or = zero, but am still having issues. Any input on the best way to approach this so there can only be one buy/sell at a time? Thanks.
profile picture

Eugene

#9
Cone's Strategy code above is perfectly single-position and thus can not lead to taking multiple positions in the same stock. So the best way is to unroll the change that made it deviate from the single-position template. ;)
profile picture

kcbars

#10
I hear you, so this morning I copied the above strategy and let it run for the first twenty minutes or so. The only thing I changed were the slider parameters. Attached are the results. Highlighted are the last two symbols in which sells were "missed", which is what I'm trying to avoid. Hopefully that makes sense. Thanks.
profile picture

Gerig

#11
I think the script that made ​​Cone is very good, but it lacks one very important point that is associated with the technique of the entrance to the Long position on the correction. The peaks on the chart should move up, if this condition is not available you can not go to Long. I rewrote the script a few Cone (Cone hope react with understanding).
CODE:
Please log in to see this code.
profile picture

Cone

#12
@ kcbars
As Eugene pointed out, it is literally impossible for the strategy to hold more than 1 Position in the same instrument hypothetically. The problem is that live trading limit strategies does not necessarily reflect what happens hypothetically; and the situation is even worse for the paper trader because of the way it was implemented. I have no qualms about calling it "deficient". Please read the User Guide > Orders > Paper Trading > How Orders Are Filled

That said, you're likely to find the same out-of-synch situations even with a live account when trading a limit order strategy; the shorter the interval, the more likely you'll get out of synch with the strategy. Wealth-Lab will always fill an BuyAtLimit that hits the low of the bar (and conversely a SellAtLimit that hits the high), but your order may or may not be filled in live trading. See Orders > Portfolio Synch > Theoretical vs. Actual

@ Gerig
If you really want to get peak/troughs between the High and Lows, you need to use the zigzag component for that purpose. Using Peak/Trough.Series indicators, you'll often detect multiple troughs between peaks and vice-versa when applying them on different series, and this will undoubtedly be observed in the chart in your adaptation.
profile picture

Gerig

#13
Unfortunately, I do not know how to implement it on zigZag component for determining Peak # 1 and Peak# 2. I would be grateful if you help.
profile picture

Gerig

#14
@Cone
Perhaps you're right, it is more logical application of ZigZag. I learned how to find a series of Peaks, so the script is:
CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).