Channel breakout created by undecided bar
Forums › ProRealTime English forum › General trading discussions › Channel breakout created by undecided bar
- This topic has 7 replies, 3 voices, and was last updated 7 years ago by Stratus6.
-
-
06/19/2017 at 11:07 PM #38621
Hi all,
Here’s my code. Strategy looks pretty good but unable to get the code to work. The idea is a range is set by a longer than average (1.5xaverage of last 20bars) bar.
A trade is then entered following a close outside of the limits (high or low) of this undecided bar.
If higher a buy trade is entered, if lower a sell trade is executed.
The stop strategy is simple and looks effective. It uses either the low of the undecided bar if a buy is activated (or the high of the undecided bar if sell is activated).
However 1 major and 1 minor problem
- The code doesnt work
- The pprofit distance needs optimising
Fine tuning/help welcomed.
Thanks
Linden
Many
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596//-------------------------------------------------------------------------// Main code : Undecided Bar as baseline//-------------------------------------------------------------------------// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedDEFPARAM Preloadbars = 1000Defparam Flatbefore = 143000Defparam Flatafter = 210000// Money ManagementCapital = 10000Risk = 0.05StopLoss = atr// VARY TO DETERMINE RISK//Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*Risk)PositionSize = abs(round((maxrisk/StopLoss+0.01)/PointValue)*pipsize)if PositionSize >= 100 ThenPositionSize = 100endifatr = AverageTrueRange[20]*1.5// Conditions to enter long positionsc1 = High[1] - Low[1] > atrc2 = Close[1] - Open[1] > 0.5c3 = High[1] - Close[1] > (Close[1] - Open[1]) *6c4 = Open[1] - Low[1] > (Close[1] - Open[1]) *6c5 = Close[0] - Open[0] > (High[0] - Max(Open[0],Close[0]))*0.5IF c1 and c2 and c3 and c4 and c5 thenTopofBar = high[1]Achat = 0endifIf achat = 0 thenif open > TopofBar thenif onmarket = 0 thenbuy positionsize lots at marketendifendifendifOnce Downstop = 1Once Uptarget = 1Downstop = Low[1] - 1Uptarget = High[1] - Close[1]// Conditions to exit long positionsSet Target pProfit UptargetSell at Downstop stop// Conditions to enter short positionsc6 = High[1] - Low[1] > atrc7 = Close[1] - Open[1] < -0.5c8 = High[1] - Open[1] > (Open[1] - Close[1]) *6c9 = Close[1] - Low[1] > (Open[1] - Close[1]) *6c10 = Open[0] - Close[0] > (Min(Open[0],Close[0]) - Low[0])*0.5IF c6 and c7 and c8 and c9 and c10 and onmarket = 0 thenBottomofBar = low[1]Vente = 0endifIf Vente = 0 thenIf open < BottomofBar thenIf onmarket = 0 thensellshort positionsize Lots at marketendifendifendif// Conditions to exit short positionsOnce Upstop = 1Once Downtarget = 1Upstop = High[1] + 1Downtarget = Close[1]- Low[1]Set Target pProfit DowntargetExitshort at Upstop stop06/20/2017 at 9:29 AM #38624> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
Did you try to graph all your “c” conditions already? The no trading problem might come from these conditions not met all at the same time.
You should also try to GRAPH the “BottomofBar” and “TopofBar” to know if your price levels are correctly calculated.
It seems that you have copy/paste some of the codes from another strategy? I can see french words in the code 😉
06/20/2017 at 5:44 PM #38681You don’t need five conditions to enter a trade.
12345678910If (high-low) > averagetruerange[20]×1.5 thenupper =highLower =lowRangebar=1EndifIf close crosses over upper and rangebar=1 thenBuy 1 contract at marketRangebar=0EndifDid not test the code but the idea is clear, i hope.
06/20/2017 at 6:33 PM #38682Instead of optimizing the pprofit you can also look for prolonged periods of contraction. If the price has been trading inside the range for X+ bars already the final breakout might be more vicious.
Or maybe look into volume confirmation to filter false signals.
06/22/2017 at 9:33 PM #38828Thanks for your input.
Yep I did copy and paste some code when I got stuck 😉
That looks good Derek, I’ve just got 2 questions
- Why do you need the line 9) Rangebar = 0
- The code you wrote doesnt account for a short body in the middle of a long long spike either side. How would I factor this in?
- Many thanks for your time 🙂
06/23/2017 at 4:52 PM #38915Hey,
- To avoid reentry after a false breakout. You can leave it out if you can work without referring to the event later in your code. Or you go testing if your strategy performs better on a later breakout attempt.
- That’s intended. Otherwise wait for confirmation of the range. See 1.
- I love simplicity in a furios world.
But now for 1.: are you referring to extra long bars with a full body and a close very near the top, or the bottom respectively? We can shortcut around both issues.
Since the market doesn’t care what timeframe we’re trading on, the top of the range is confirmed by the retracement! So, we wait for a Rangebar to occur and then look for a follow up event to differentiate a forming range from a straight forward breakout. This way, we don’t need to look at the rangebar when it occurs because they are all equal.
Here is my code (not tested):
12345678910111213141516If (high-low) > averagetruerange[20]×1.5 thenupper =highLower =lowRangebar=1EndifIf Rangebar=1 and close[2] < upper and close[1] < upper and close[0] < upper and close[0] > close[1] then //it's a 1-bar fractal below rangebar's high.Rangetop= upperRangebottom=lowerElsif Rangebar=1 and close[2] > upper and close[1] > upper and close[0] > upper and close[0] < close[1] then //it's a 1-bar fractal above rangebar's lowEndif //the range has at least some confirmation.If close crosses over rangetop or if close crosses under rangebottom thenBuy 1 contract at marketRangebar=0EndifDon’t let your eyes fool you. The initial hypothesis is more likely to be correct if there actually is a range following a rangebar before the breakout 🙂
edit: added the lower range
1 user thanked author for this post.
06/23/2017 at 5:17 PM #38917Ok, this should work. Replace with lines 7-11:
1234567If Rangebar=1 and close[2] < upper and close[1] < upper and close[0] < upper and close[0] > close[1] then //it's a 1-bar fractal below rangebar's high.Rangetop= upperRangebottom=lowerElsif Rangebar=1 and close[2] > upper and close[1] > upper and close[0] > upper and close[0] < close[1] then //it's a 1-bar fractal above rangebar's lowRangetop= upperRangebottom=lowerEndif //the range has at least some confirmation.1 user thanked author for this post.
07/10/2017 at 2:48 PM #40262 -
AuthorPosts
Find exclusive trading pro-tools on