Trend Break System
Forums › ProRealTime English forum › ProOrder support › Trend Break System
- This topic has 8 replies, 5 voices, and was last updated 7 years ago by
Nicolas.
-
-
06/08/2018 at 10:35 AM #72643
Anybody willing to code / help me code / share (what is nearest example on here?) a System which would enter and exit trades at Trend Breaks determined by failures to exceed previous high, Lows / Failure to get back in trend??
Is this even possible on PRT??
Many Thanks for any Help
GraHal06/08/2018 at 11:05 AM #72653Maybe you can use fractals?
if last fractal > than previous fractal
and sell if under last fractal
https://www.prorealcode.com/prorealtime-indicators/fractal-williams-indicator/
1 user thanked author for this post.
06/08/2018 at 11:09 AM #72657I have removed the images you did not want for you and removed the part of your post referring to them so as not to confuse future readers. 🙂
Are you sure you listed the correct ones as now images 2 and 3 look identical!?
1 user thanked author for this post.
06/08/2018 at 11:16 AM #7265906/08/2018 at 11:29 AM #72661Image 3 now deleted.
Not so sure about the being an insider thing. Being a moderator basically means that Nicolas gives you a broom and asks you to try to keep the place a bit tidy if you happen to be hanging around the place! Moderators are just the same as all the other forum users except they have some basic cleaning equipment.
06/08/2018 at 12:40 PM #72664Basic idea:
You can use a simple moving average and a test if the price has not breached the last highest high or lowest low within the last X periods.
Example for a new buy order:
1/ a new lowest low was set at bar X while price was under a 20 periods moving average.
2/ close is now above the SMA and the current bar is X+Y periods
In preliminary, you would have count if the last bearish trend was well established by counting how many times the SMA20 has decreased in the same row.
1 user thanked author for this post.
06/11/2018 at 8:29 AM #72830Something I worked on at some stage:
Code I am using:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164//Stategy: Trend Breakout//Author: JuanJ//Market: Neutral (Optimized for EURUSD)//Timeframe: 1Hr//Timezone: UTC +2//Timeframe: 1Hr but not 'completely' timeframe dependantDefparam cumulateorders = FalseIf hour < 9 or hour > 22 then //outside market hourspossize = 0If longonmarket Thensell at marketBear = 0Bull = 0ElsIf shortonmarket Thenexitshort at marketBear = 0Bull = 0EndIfElsepossize = 1 //position contract sizeEndIf//Calculate Fractalonce FracH = 0 //initialize fractal countonce FracL = 0 //initialize fractal countFor i = 0 to 4 DoIf high[2] > high[i] Then //look for high fractal with 2 lower highs on either sideFracH = FracH + 1EndIfIf low[2] < low[i] Then //look for low fractal with 2 higher lows on either sideFracL = FracL + 1EndIfNextIf FracH = 4 Then //High Fractal IdentifiedIf Bear = 0 and Bull = 0 ThenBear = 1 //Initialize first trend directionEndIfFractalH = high[2] //High Fractal Price LevelFractalP = barindex - 2 //High Fractal Bar PositionEndIfIf FracL = 4 Then //Low Fractal IdentifiedIf Bear = 0 and Bull = 0 ThenBull = 1 //Initialize first trend directionEndIfFractalL = low[2] //Low Fractal Price LevelFractalP = barindex - 2 //Low Fractal Bar PositionEndIfFracH = 0 //reset fractal countFracL = 0 //reset fractal count//Calculate trendline using widest angle from extreme of last fractal to curent extreme (Trigonometry Function)If Bear = 1 Then //Down trendHeight = FractalH - high //Calcululate height between high fractal and high of current barHeightB = FractalH - close //Calcululate height between high fractal and close of current bar (used to determine trend violation)ElsIf Bull = 1 Then //Up trendHeight = Low - FractalL //Calcululate height between low fractal and low of current barHeightB = close - FractalL //Calcululate height between high fractal and close of current bar (used to determine trend violation)EndIfIf barindex - 2 = FractalP Then //Initialize angle using high of last bar of fractal setMaxAngle = Tan(2/Height) //Initial value of the angle between the fractal and the last highEndIfonce Trendbreak = 0If barindex - 2 > FractalP Then //If current bar greater than end of fractal set:If Bear = 1 Then //For Down TrendIf (Tan((barindex-FractalP)/Height) > MaxAngle) and (((close < open) or (close < close[1]))) ThenMaxAngle = Tan((barindex-FractalP)/Height) //calculate new max trend if down trend rules are validTrendbreak = 0 //No Trend Violation PresentEndIfIf Trendbreak = 0 and (Tan((barindex-FractalP)/HeightB) > MaxAngle) and close > open ThenTrendBreak = 1 //Trend violation potentially present, wait for confirmation on close of next barElsIf Trendbreak = 1 and (Tan(((barindex-1)-FractalP)/HeightB) > MaxAngle) and close > close[1] ThenTrendbreak = 2 //Trend violation confirmed, there was a close outside the trend line (close angle > trend)EndIfElsIf Bull = 1 Then //For Up TrendIf (Tan((barindex-FractalP)/Height) > MaxAngle) and (((close > open) or (close > close[1]))) ThenMaxAngle = Tan((barindex-FractalP)/Height) //calculate new max trend if up trend rules are validTrendbreak = 0 //No Trend Violation PresentEndIfIf Trendbreak = 0 and (Tan((barindex-FractalP)/HeightB) > MaxAngle) and close < open ThenTrendBreak = 1 //Trend violation potentially present, wait for confirmation on close of next barElsIf Trendbreak = 1 and (Tan(((barindex-1)-FractalP)/HeightB) > MaxAngle) and close < close[1] ThenTrendbreak = 2 //Trend violation confirmed, there was a close outside the trend line (close angle < trend)EndIfEndIfEndIfIf Trendbreak = 2 Then //Trend violation is confirmed:If Bear = 1 Then //Down Trend Present (but now broken):BreakoutL = Highest[2](high)[0] //Determine Highest point of violation (including last candle before violation)Buy possize contract at BreakoutL + (AverageTrueRange[7](close)*0.3) stop //Enter into long position at specified price level//N.B. We need to ensure the current position is obviously closed?ElsIf Bull = 1 Then //Up Trend Present (but now broken):BreakoutL = Lowest[2](low)[0] //Determine Lowest point of violation (including last candle before violation)Sellshort possize contract at BreakoutL - (AverageTrueRange[7](close)*0.3) stop //Enter into short position at specified price level//N.B. We need to ensure the current position is obviously closed?EndIfIf Bear = 1 and longonmarket Then //If position is opened counter last trend, reset variablesTrendbreak = 0Bear = 0Bull = 1ElsIf Bull = 1 and shortonmarket Then //If position is opened counter last trend, reset variablesTrendbreak = 0Bear = 1Bull = 0EndIfEndIf//Trade Management (Note that Trend Direction need to be reset with exits's)Deviations = 1.618periods = 34PRICE = LOG(customclose)alpha = 2/(PERIODS+1)if barindex < PERIODS thenEWMA = AVERAGE[3](PRICE)elseEWMA = alpha * PRICE + (1-alpha)*EWMAendiferror = PRICE - EWMAdev = SQUARE(error)if barindex < PERIODS+1 thenvar = develsevar = alpha * dev + (1-alpha) * varendifESD = SQRT(var)BollU = EXP(EWMA + (DEVIATIONS*ESD))BollL = EXP(EWMA - (DEVIATIONS*ESD))RS2 = ROUND(RSI[2](close))PSH = Highest[100](high)[1]PSL = Lowest[100](low)[1]If longonmarket and ((close[1] > BollU and close < BollU) or (high[1] > BollU and high < BollU) or (close > PSH or close < PSL)) ThenLE = 1ElsIf shortonmarket and ((close[1] < BollL and close > BollL) or (low[1] < BollL and low > BollL) or (close < PSL or close > PSH)) ThenSE = 1EndIfIf longonmarket and LE = 1 and RS2 >= 85 and close < BollU ThenSell at marketBear = 0Bull = 0ElsIf shortonmarket and SE = 1 and RS2 <= 15 and close > BollL ThenExitshort at marketBear = 0Bull = 0EndIf06/11/2018 at 9:40 AM #72842Hey great @juanj thanks, I will check this out later. I do recall now seeing this a while back and thinking it was very clever.
Not being a career coder and only starting coding on here about 2 years ago I’ll never emulate such ingenuity and innovation.
A big thank you!
GraHalPS to any readers:
I am always glad of any help from anybody with trading stragegies / ideas I put forward, even if you can produce only a few lines of the code.
I have more ideas, but tend not to post them as it seems that with me being active here for so long then folks may think I am a capable coder and so not offer actual code?
Not complaining, just opening up a bit!? 🙂06/11/2018 at 9:59 AM #72844 -
AuthorPosts
Find exclusive trading pro-tools on