Pseudo triangle trading system 5 min using volume and volatity
Forums › ProRealTime English forum › ProOrder support › Pseudo triangle trading system 5 min using volume and volatity
- This topic has 22 replies, 4 voices, and was last updated 1 year ago by Meta Signals Pro.
Tagged: triangle
-
-
10/06/2017 at 9:15 PM #48476
Hello
I found this system that could be basic and adptable to several instrument but I have difficulties to code it.
This idea is to trade triangle pattern using volatity indicator and volume indicator. ( i know that it is difficult to detect trendline compression)
During triangle , volatility and volumes are decreasing and a proper moving average is flat (according to the article in doc enclosed).
Does someone has the idea how to code it? (specialy with decrease of volume and volatily)
Volume decrease could be code with a decrease of the average of volume
Volatily decrease could be code with a decrease of the average of volatily.
If both are decreasing, a buy or sell stop order is generated at last low/high
Triangle amplitude is equal to the highest(high)[x periods]-lowest(low)[x periods]
Thanks
10/26/2017 at 5:36 PM #50636Hi,
I posted a method to find local maximums and minimums, maybe you can find a way to detects triangles based on that method
https://www.prorealcode.com/topic/dobule-bottom-or-double-top
Let us know if you get it
10/26/2017 at 7:58 PM #50644I made a triangle pattern detector in this topic if you find it useful: https://www.prorealcode.com/topic/trendline-une-approche-du-trading/
10/26/2017 at 8:26 PM #5064610/27/2017 at 8:34 PM #50754Hello
I modified your code of the screener to better understand it with some comments (you used a b c d for points and I use High1 High2 Low1 Low2).
I am able to find compression lines with the screener
Triangle and wedge screener123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960//PRC_Wedge pattern | screener//12.09.2016//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge// modified by Yannick//fractalscp = 50//4 //lookback//Detection Highif high[cp] >= highest[(cp)*2+1](high) thenLLH = 1elseLLH = 0endif//Value of last Highif LLH = 1 thenHigh1 = High2[1]High1bar = High2bar[1]High2 = high[cp]High2bar = barindex[cp]endif//Detection Lowif low[cp] <= lowest[(cp)*2+1](low) thenLLL = -1elseLLL = 0endif//Value of last Lowif LLL = -1 thenLow1 = Low2[1]Low1bar = Low2bar[1]Low2 = low[cp]Low2bar = barindex[cp]endif// condition of screening//condition 1 triangle compression contraction Lows are increasings and High are decreasing High1>High2 and Low1<Low2//condition 2 compression of volatilty Initial swing High1Low1> Last Swing High2Low2 : abs(High1-Low1)> abs(High2-Low2)risingwedge = High1<High2 and Low1<Low2 and abs(High1bar-High2bar)>abs(Low1bar-Low2bar) and abs(High1-High2)<abs(Low1-Low2) //Rising wedge?triangle = High1>High2 and Low1<Low2 and abs(High1-Low1)> abs(High2-Low2) //triangle condition contraction Low increasing and High decreasingfallingwedge = High1>High2 and Low1>Low2 and abs(High1bar-High2bar)<abs(Low1bar-Low2bar) and abs(High1-High2)>abs(Low1-Low2) //Falling weg ?SCREENER [risingwedge or triangle or fallingwedge]//triangle drawlinefuction//Volatility decrease//AverageVolatity//Volatilty//Previous trend detection : triangle should be continuation pattern//Previous trend detection : trend continuation wedge should a short term reversalpattern and long term continuation//close > average[X]and for and indicator, but I have a problem with drawline function which drawlines in the indicator window and not inside pricewindow
Triangle indicator12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758//PRC_Wedge pattern | screener//12.09.2016//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge// modified by Yannick//fractalscp = 10//4 //lookback//Detection Highif high[cp] >= highest[(cp)*2+1](high) thenLLH = 1elseLLH = 0endif//Value of last Highif LLH = 1 thenHigh1 = High2[1]High1bar = High2bar[1]High2 = high[cp]High2bar = barindex[cp]endif//Detection Lowif low[cp] <= lowest[(cp)*2+1](low) thenLLL = -1elseLLL = 0endif//Value of last Lowif LLL = -1 thenLow1 = Low2[1]Low1bar = Low2bar[1]Low2 = low[cp]Low2bar = barindex[cp]endif// condition of screening//condition 1 triangle compression contraction Lows are increasings and High are decreasing High1>High2 and Low1<Low2//condition 2 compression of volatilty Initial swing High1Low1> Last Swing High2Low2 : abs(High1-Low1)> abs(High2-Low2)c1 = High1<High2 and Low1<Low2 and abs(High1bar-High2bar)>abs(Low1bar-Low2bar) and abs(High1-High2)<abs(Low1-Low2) //Rising wedge?c2 = High1>High2 and Low1<Low2 and abs(High1-Low1)> abs(High2-Low2) //triangle condition contraction Low increasing and High decreasingc3 = High1>High2 and Low1>Low2 and abs(High1bar-High2bar)<abs(Low1bar-Low2bar) and abs(High1-High2)>abs(Low1-Low2) //Falling weg ?if c1 or c2 or c3 thenDRAWLINE(Low1bar,Low1,Low2bar,Low2)DRAWLINE(High1bar,High1,High2bar,High2)endifReturn//Volatility decrease//AverageVolatity//Volatilty10/27/2017 at 8:39 PM #5075710/28/2017 at 8:48 PM #50796Better like this
Triangle detector with volatily dectector and drawlinefunction1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071//PRC_Wedge pattern | screener//12.09.2016//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge// modified by Yannick//fractalscp = 10//4 //lookback//volatiltyHistVolatily=HistoricVolatility[300](close)//Detection Highif high[cp] >= highest[(cp)*2+1](high) thenLLH = 1elseLLH = 0endif//Value of last Highif LLH = 1 thenHigh1 = High2[1]High1bar = High2bar[1]High2 = high[cp]High2bar = barindex[cp]endif//Detection Lowif low[cp] <= lowest[(cp)*2+1](low) thenLLL = -1elseLLL = 0endif//Value of last Lowif LLL = -1 thenLow1 = Low2[1]Low1bar = Low2bar[1]Low2 = low[cp]Low2bar = barindex[cp]endif// condition of screening//condition 1 triangle compression contraction Lows are increasings and High are decreasing High1>High2 and Low1<Low2//condition 2 compression of volatilty Initial swing High1Low1> Last Swing High2Low2 : abs(High1-Low1)> abs(High2-Low2)risingwedge = High1<High2 and Low1<Low2 and abs(High1bar-High2bar)>abs(Low1bar-Low2bar) and abs(High1-High2)<abs(Low1-Low2) //Rising wedge?triangle = High1>High2 and Low1<Low2 and abs(High1-Low1)> abs(High2-Low2) //triangle condition contraction Low increasing and High decreasingfallingwedge = High1>High2 and Low1>Low2 and abs(High1bar-High2bar)<abs(Low1bar-Low2bar) and abs(High1-High2)>abs(Low1-Low2) //Falling weg ?if risingwedge or triangle or fallingwedge thenDRAWsegment(Low1bar,Low1,Low2bar,Low2)DRAWsegment(High1bar,High1,High2bar,High2) //triangle drawlinefuctionendifif triangle and HistVolatily< HistVolatily[300] thenDRAWCANDLE(High1,high2,low2,low1)DRAWTEXT("fintriangle",low2bar,low2,SansSerif,Bold,16)coloured(153,153,0)DRAWTEXT("debuttriangle",low1bar,low1,SansSerif,Bold,16)coloured(153,153,0)endif//Volatility decrease in triangle lowest 300 period volatily//AverageVolatity//Volatilty//Previous trend detection : triangle should be continuation pattern//Previous trend detection : trend continuation wedge should a short term reversalpattern and long term continuation//close > average[X]Return10/28/2017 at 8:56 PM #5079710/29/2017 at 8:33 AM #50799Please find somescreenshots
for daily , i look at 20 days volatilty and fractal cp=4
for 5 minutes timeframe, I look at 300 bars volatily and fractal cp=10
How can prt draw directly in price window and not in indicator window?
10/29/2017 at 10:00 AM #50808How can prt draw directly in price window and not in indicator window?
Just add your indicator on price with the wrench icon on the left upper side of your price chart.
10/30/2017 at 9:12 PM #50970Thanks
It is better like this
I have to improve the logic by
-filtering using stochastic oscillation which could give information on the period of fractal to control
-control the angle of the triangle (more symetric triangle pattern),
-preventing fake detection by measuring the time distance between Low1-Low2 and Hig1-High2
I will try to use @juanj code from calculating diagonal trend line using trigonometry for trading of breakout of lines.
Some picture of my manual trade on sugar that I am following, which is detected
And other time frames
10/31/2017 at 2:43 PM #5107810/31/2017 at 9:29 PM #51144I improved the quality of the triangle signal with some extra logic condition 3 and 4
12345678910111213// condition of screening Triangle//condition 1 triangle compression contraction Lows are increasings and High are decreasing High1>High2 and Low1<Low2//condition 2 compression of volatilty Initial swing High1Low1> Last Swing High2Low2 : abs(High1-Low1)> abs(High2-Low2)//condition 3 triangle oscillation inside the triangle e.g. correct order of bars L/H/L/H or H/L/H/L//condition 4 triangle amplitude ratio control H1L1< 2 H2L2triangle = High1>High2 and Low1<Low2 and abs(High1-Low1)> abs(High2-Low2) //triangle conditions 1+2 contraction Low increasing and High decreasingoscillationH1L1H2L2= High1bar< Low1bar and Low1bar< High2bar and High2bar<Low2bar //triangle condition 3 oscillationoscillationL1H1L2H2= Low1bar<High1bar and High1bar<Low2bar and Low2bar< High2bar //triangle condition 3 oscillationtriangleamplitude=abs(High1-Low1)< 2* abs(High2-Low2) //2is value that could be improvedThe next question is how to generate stop orders on lines that are calculated at each bar and has to stay valid for1 bar and is modified at each new bar , I need help.
In this case x=0 current bar?
1234567891011121314151617181920212223242526272829303132333435positionsize=1TP= min(High2-Low1, High1-Low2)SL = TP/2//Equation of line y=ax+b// slope a= (yB-yA)/(xB-xA)= deltay/deltax// intercept b= yA-xA(YB-YA)/(xB-xA)//calculation of upperline equation and position yHigh for buystop//aH=(H2-H1)/(H2bar-H1bar)bH=High1-High1bar*(High2-High1)/(High2bar-High1bar)yHigh=bH//aH*????//calculation of lowerline equation//aL=(L2-L1)/(L2bar-L1bar)bL=Low1-Low1bar*(Low2-Low1)/(Low2bar-Low1bar)yLow=bL//+aL*????if triangle and triangleamplitude and oscillationH1L1H2L2 or triangle and triangleamplitude and oscillationL1H1L2H2 thenorderloop=1Endiffor orderloop=1 to cp dobuy positionsize lot at yHigh STOPSell positionsize lot at yLow STOPnext//buy stop at x=0 y=b ????if onmarket thenset target profit TPset stop loss SLorderloop=0endif11/02/2017 at 11:36 AM #5128711/12/2017 at 4:17 PM #52442Thanks I modified the buying and sellingshort logic.
I still have to
-calculate better the buystop and sellstop limite with TP and SL
-improving time limitation on the trade regarding
-improve triangle detection
Plenty of brain work
123456if not onmarket and Tradetriangle=1 thenyhigh=yhigh+aHyLow=yLow+aLbuy positionsize contract at yHigh STOPSellshort positionsize contract at yLow STOPEndif -
AuthorPosts
Find exclusive trading pro-tools on