Trendline break
Forums › ProRealTime English forum › ProBuilder support › Trendline break
- This topic has 3 replies, 4 voices, and was last updated 4 years ago by Bos..
-
-
04/08/2020 at 10:06 AM #125179
Hello,
It has been some time since I haven’t been around the forum, as I’m developing my own trade manager in Python. The goal is to trade manually, but let the risk management and the follow up of the trade to the trade manager (best way to earn money on market in my opinion). For people interested, I may commercialize it soon…Anyway, back to prt code.
On top of the wolve wave indicator I just posted, I spent also a lot of time trying to code a trendline break indicator. Please find the result here below. I hope someone can look at it, and try to develop a robot with it, there is certainly a big potential there…If yes, please keep me in the loop;)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590defparam calculateonlastbars=1000defparam drawonlastbaronly=falseshowline=1pinshow=1HLorClose=1if barindex=1 thenlastmax=0lastmin=0prevlastmax=0prevlastmin=0prevlastmax2=0prevlastmin2=0prevlastmax3=0prevlastmin3=0minbar=barindexmaxbar=barindexprevminbar=0prevmaxbar=0//crossbearbar=barindex//crossbullbar=barindexbull=0bear=0endifMA7=average[7](close)MA200=average[200](close)Period=10coefATR=1.5//1. on utilise des MM pour trouver les points hauts/basATR=averagetruerange[50](close)DataF = CloselagF = ROUND((Period-1)/2)dF = (DataF+(DataF-DataF[lagF]))LMA = exponentialaverage[period](dF)//Smoothed curve of zero lag Moving AverageIF BARINDEX > period THENsmoothLMA=weightedaverage[period](LMA)ELSEsmoothLMA=undefinedENDIFif minbar=0 thenminbar=barindexendifif maxbar=0 thenmaxbar=barindexendifIF BARINDEX > PERIOD THEN //For avoid computer errorsbullcross=LMA crosses over smoothLMAbearcross=LMA crosses under smoothLMAENDIF//2. chaque fois qu'il y a un croisement de MM, on stocke le point extrème précédent et sa position, et on trouve le dernier point extrèmeIf bearcross then//on prend le dernier plus baslastmaxtemp=high[1]maxbartemp=barindex[1]for i=0 to barindex-minbar-1 doif high[i]>lastmaxtemp thenlastmaxtemp=high[i]maxbartemp=barindex[i]endifnext//test=lastmaxtemp//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)//test=ATR[1]*CoefATR//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)//on verifie qu'il y a assez d'ampli entre le plus haut récent et le précédent plus bas, sinon on prend pas en compte.If lastmaxtemp-lastmin>ATR[1]*CoefATR thenprevbear2crossbar=prevbearcrossbarprevbearcrossbar=bearcrossbarbearcrossbar=barindex//Si on a skippé un plus bas car pas assez d'ampli, on se retrouve donc avec 2 plus hauts. Si le plus récent est le plus haut, on essaye d'oublier le précédent plus haut. Si le précédent était plus haut, on ne prend pas en compte le dernierif barindex-maxbar<barindex-minbar thenif lastmaxtemp>lastmax then//prevlastmax2=prevlastmax2//prevmaxbar2=prevmaxbar2//prevlastmax=prevlastmax//prevmaxbar=prevmaxbarlastmax=lastmaxtempmaxbar=maxbartempendif//si on est dans le cas normal d'un plus bas suivit d'un plus haut, alors on sauve les derniers plus hautselseprevlastmax3=prevlastmax2prevmaxbar3=prevmaxbar2prevlastmax2=prevlastmaxprevmaxbar2=prevmaxbarprevlastmax=lastmaxprevmaxbar=maxbarlastmax=lastmaxtempmaxbar=maxbartemplong=0bull=0bull2=0endifendif//test=prevlastmax2//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)endifIf bullcross then//on prend le dernier plus baslastmintemp=low[1]minbartemp=barindex[1]for i=0 to barindex-maxbar-1 doif low[i]<lastmintemp thenlastmintemp=low[i]minbartemp=barindex[i]endifnextIf lastmax-lastmintemp>ATR[1]*CoefATR thenprevbull2crossbar=prevbullcrossbarprevbullcrossbar=bullcrossbarbullcrossbar=barindexif barindex-minbar<barindex-maxbar thenif lastmintemp<lastmin then//prevlastmin2=prevlastmin2//prevminbar2=prevminbar2//prevlastmin=prevlastmin//prevminbar=prevminbarlastmin=lastmintempminbar=minbartempendifelseprevlastmin3=prevlastmin2prevminbar3=prevminbar2prevlastmin2=prevlastminprevminbar2=prevminbarprevlastmin=lastminprevminbar=minbarlastmin=lastmintempminbar=minbartempshort=0bear=0bear2=0endifendifendifif pinshow thenDRAWTEXT("▼",prevmaxbar,prevlastmax,Dialog,Bold,12) coloured(255,0,0)endifif pinshow thenDRAWTEXT("▲",prevminbar,prevlastmin,Dialog,Bold,12) coloured(0,255,10)endif//3. Si on a une loi de Dow (2 plus bas montent, 2 plus hauts montent) et qu'on a un peu de vol entre les points, on peut tracer des obliques//neutre=1if lastmax<prevlastmax and prevlastmax<prevlastmax2 and prevlastmax2<>0 and long=0 and maxbar-prevmaxbar2>20 thenbull=1endifif lastmin>prevlastmin and prevlastmin>prevlastmin2 and prevlastmin2<>0 and short=0 and minbar-prevminbar2>20 thenbear=1endifif lastmax<prevlastmax2 and prevlastmax2<prevlastmax3 and prevlastmax3<>0 and long=0 and maxbar-prevmaxbar2>20 thenbull2=1endifif lastmin>prevlastmin2 and prevlastmin2>prevlastmin3 and prevlastmin3<>0 and short=0 and minbar-prevminbar2>20 thenbear2=1endif//test=bear2//drawtext("#test#",barindex,high+5,SansSerif,Bold,10) COLOURED(0,155,10)//if lastmax<prevlastmax2 and prevlastmax<prevlastmax2 and prevlastmax2<prevlastmax3 and prevlastmax3<>0 and long=0 and maxbar-prevmaxbar2>20 then//bull2=1////endif//////if lastmin>prevlastmin2 and prevlastmin>prevlastmin2 and prevlastmin2>prevlastmin3 and prevlastmin3<>0 and short=0 and minbar-prevminbar2>20 then//bear2=1////endif//test=bull2//drawtext("#test#",barindex,high+5,SansSerif,Bold,10) COLOURED(0,155,10)//5. On stocke les points extrèmes dans des variables temporaires, car pour bien tracer les obliques, on va essayer de trouver les bons points entre les points extrèmes, car si le temps passe et que le marché stagne, les obliques coupent les coursif bear=1 thenlastminTemp=lastminprevlastminTemp=prevlastminminbarTemp=minbarprevminbarTemp=prevminbarprevlastmin2Temp=prevlastmin2prevminbar2Temp=prevminbar2AngleBear=tan((prevlastminTemp-prevlastmin2Temp)/prevlastmin2Temp*100)/(prevminbarTemp-prevminbar2Temp)//On regarde d'abord le premier point de l'oblique, pour voir si il est bien placé entre les 2 pt extrèmes, sinon on prend un autre//for i=barindex-prevminbar2Temp-1 downto barindex-prevminbarTemp do//if low[i]<prevlastminTemp+(((barindex[i]-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp) then//prevlastmin2Temp=low[i]//prevminbar2Temp=barindex[i]////// on calcule l'angle de l'oblique//AngleBear=tan((prevlastminTemp-prevlastmin2Temp)/prevlastmin2Temp*100)/(prevminbarTemp-prevminbar2Temp)//endif//next//On recalcule ensuite ou doit se trouver le 3e point de l'oblique en fct des 2 1er. Si il est dans la bonne zone, notre oblique est validéefor i=barindex-prevminbartemp-1 downto barindex-prevbullcrossbar doif low[i]<prevlastminTemp+(((barindex[i]-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp) thenprevlastminTemp=low[i]prevminbartemp=barindex[i]// on calcule l'angle de l'obliqueAngleBear=tan((prevlastminTemp-prevlastmin2Temp)/prevlastmin2Temp*100)/(prevminbarTemp-prevminbar2Temp)endifnextif lastminTemp>prevlastminTemp+(((minbarTemp-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)-ATR/3 and lastminTemp<prevlastminTemp+(((minbarTemp-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)+ATR/3 thenbear=1//on recalcule l'angle sur base du 3e point, si besoinif lastminTemp<prevlastminTemp+(((minbarTemp-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp) thenAngleBear=tan((lastminTemp-prevlastmin2Temp)/prevlastmin2Temp*100)/(minbarTemp-prevminbar2Temp)endifelsebear=0endifendifif bear2=1 thenlastminTemp=lastminminbarTemp=minbarprevlastmin2Temp=prevlastmin2prevminbar2Temp=prevminbar2prevlastmin3Temp=prevlastmin3prevminbar3Temp=prevminbar3AngleBear2=tan((prevlastmin2Temp-prevlastmin3Temp)/prevlastmin3Temp*100)/(prevminbar2Temp-prevminbar3Temp)for i=barindex-prevminbar2temp-1 downto barindex-prevbull2crossbar doif low[i]<prevlastmin2Temp+(((barindex[i]-prevminbar2Temp)*Atan(AngleBear))/100*prevlastmin2Temp) thenprevlastmin2Temp=low[i]prevminbar2temp=barindex[i]// on calcule l'angle de l'obliqueAngleBear2=tan((prevlastmin2Temp-prevlastmin3Temp)/prevlastmin3Temp*100)/(prevminbar2Temp-prevminbar3Temp)endifnext//On recalcule ensuite ou doit se trouver le 3e point de l'oblique en fct des 2 1er. Si il est dans la bonne zone, notre oblique est validéeif lastminTemp>prevlastmin2Temp+(((minbarTemp-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)-ATR/3 and lastminTemp<prevlastmin2Temp+(((minbarTemp-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)+ATR/3 thenbear2=1//on recalcule l'angle sur base du 3e point, si besoinif lastminTemp<prevlastmin2Temp+(((minbarTemp-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)thenAngleBear2=tan((lastminTemp-prevlastmin3Temp)/prevlastmin3Temp*100)/(minbarTemp-prevminbar3Temp)endifelsebear2=0endifendifif bull=1 thenlastmaxTemp=lastmaxprevlastmaxTemp=prevlastmaxmaxbarTemp=maxbarprevmaxbarTemp=prevmaxbarprevmaxbar2Temp=prevmaxbar2prevlastmax2Temp=prevlastmax2AngleBull=tan((prevlastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(prevmaxbarTemp-prevmaxbar2Temp)//test=prevlastmaxTemp+(((prevmaxbarTemp-barindex[29])*Atan(AngleBull))/100*prevlastmaxTemp)//drawtext("#test#",barindex,high+5,SansSerif,Bold,10) COLOURED(0,155,10)//for i=barindex-prevmaxbar2Temp-1 downto barindex-prevmaxbarTemp do//if high[i]>prevlastmaxTemp+(((prevmaxbarTemp-barindex[i])*Atan(AngleBull))/100*prevlastmaxTemp) then//prevlastmax2Temp=high[i]//prevmaxbar2Temp=barindex[i]//AngleBull=tan((prevlastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(prevmaxbarTemp-prevmaxbar2Temp)//endif//next//test=prevbearcrossbar//drawtext("#test#",barindex,high+5,SansSerif,Bold,10) COLOURED(0,155,10)//for i=barindex-prevmaxbarTemp-1 downto barindex-prevbearcrossbar doif high[i]>prevlastmaxTemp+(((barindex[i]-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)thenprevlastmaxTemp=high[i]prevmaxbarTemp=barindex[i]AngleBull=tan((prevlastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(prevmaxbarTemp-prevmaxbar2Temp)endifnextif lastmaxTemp>prevlastmaxTemp+(((maxbarTemp-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)-ATR/3 and lastmaxTemp<prevlastmaxTemp+(((maxbarTemp-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)+ATR/3 thenbull=1if lastmaxtemp>prevlastmaxTemp+(((maxbarTemp-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp) thenAngleBull=tan((lastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(maxbarTemp-prevmaxbar2Temp)endifelsebull=0endifendifif bull2=1 thenlastmaxTemp=lastmaxprevlastmaxTemp=prevlastmaxmaxbarTemp=maxbarprevmaxbarTemp=prevmaxbarprevmaxbar2Temp=prevmaxbar2prevlastmax2Temp=prevlastmax2prevmaxbar3Temp=prevmaxbar3prevlastmax3Temp=prevlastmax3AngleBull2=tan((prevlastmax2Temp-prevlastmax3Temp)/prevlastmax3Temp*100)/(prevmaxbar2Temp-prevmaxbar3Temp)//for i=barindex-prevmaxbar2Temp-1 downto barindex-prevmaxbarTemp do//if tan((prevmaxbarTemp-barindex[i])/(high[i]-prevlastmaxTemp))<AngleBull and tan((prevmaxbarTemp-barindex[i])/(high[i]-prevlastmaxTemp))>0 then//prevlastmax2Temp=high[i]//prevmaxbar2Temp=barindex[i]//AngleBull=tan((prevlastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(prevmaxbarTemp-prevmaxbar2Temp)//endif//nextfor i=barindex-prevmaxbar2Temp-1 downto barindex-prevbear2crossbar doif high[i]>prevlastmax2Temp+(((barindex[i]-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)thenprevlastmax2Temp=high[i]prevmaxbar2Temp=barindex[i]AngleBull2=tan((prevlastmax2Temp-prevlastmax3Temp)/prevlastmax3Temp*100)/(prevmaxbar2Temp-prevmaxbar3Temp)endifnextif lastmaxTemp>prevlastmax2Temp+(((maxbarTemp-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)-ATR/3 and lastmaxTemp<prevlastmax2Temp+(((maxbarTemp-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)+ATR/3 thenbull2=1if lastmaxtemp>prevlastmax2Temp+(((maxbarTemp-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp) thenAngleBull2=tan((lastmaxTemp-prevlastmax3Temp)/prevlastmax3Temp*100)/(maxbarTemp-prevmaxbar3Temp)endifelsebull2=0endifendiftrendbreak=0//6. Si on est dans une loi de dow, on va comparer l'angle de l'oblique quand a déterminé, avec l'angle entre le dernier prix et le dernier point extrème, ce qui va permettre de savoir si cassure ou pasif HLorClose=1 thenHi=highLo=LowelseHi=closeLo=CLoseendifif bear then//if barindex-firstbullbar<20 or only2=1 thenif lo<prevlastminTemp+(((barindex-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)-ATR/3 and low<low[1] thenif HLorClose=1 thenENTRY=min(prevlastminTemp+(((barindex-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp),MA7)-ATR/3elseENTRY=min(close,MA7-ATR/3)endiflastpoint=prevlastminTemp+(((barindex-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)trendbreak=1elsetrendbreak=0endifendifif bull then//if barindex-firstbearbar<20 thenif hi>prevlastmaxTemp+(((barindex-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)+ATR/3 and high>high[1] thenif HLorClose=1 thenENTRY=max(prevlastmaxTemp+(((barindex-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp),MA7)+ATR/3elseENTRY=max(close,MA7+ATR/3)endiflastpoint=prevlastmaxTemp+(((barindex-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)trendbreak=1elsetrendbreak=0endifendifif bear2 then//test=prevlastmin2Temp+(((barindex[1]-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)//test=prevlastmin2Temp+(((barindex-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)if lo<prevlastmin2Temp+(((barindex-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)-ATR/3 and low<low[1] thenif HLorClose=1 thenENTRY=min(prevlastmin2Temp+(((barindex-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp),MA7)-ATR/3elseENTRY=min(close,MA7-ATR/3)endiflastpoint=prevlastmin2Temp+(((barindex-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)trendbreak=1elsetrendbreak=0endifendifif bull2 thenif hi>prevlastmax2Temp+(((barindex-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)+ATR/3 and high>high[1] thenif HLorClose=1 thenENTRY=max(prevlastmax2Temp+(((barindex-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp),MA7)+ATR/3elseENTRY=max(close,MA7+ATR/3)endiflastpoint=prevlastmax2Temp+(((barindex-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)trendbreak=1elsetrendbreak=0endifendif//6. Si on a eu une cassure, on détermine notre point d'entrée et on affiche notre obliqueif trendbreak and (bear or bear2) then//if barindex-firstbullbar<20 or only2=1 thenif showline then//drawline(prevminbarTemp,prevlastminTemp,minbarTemp,lastminTemp) coloured(0,255,10)if bear thendrawsegment(prevminbar2Temp,prevlastmin2Temp,barindex,lastpoint)coloured (255,0,10)elsedrawsegment(prevminbar3Temp,prevlastmin3Temp,barindex,lastpoint)coloured (255,0,10)endifendif//else//if showline then//drawline(prevminbar2Temp,prevlastmin2Temp,prevminbarTemp,prevlastminTemp) coloured(255,255,255)//endif//endifif low<ENTRY thenDRAWARROWDOWN(barindex,high) COLOURED(255,0,10)if close>MA200 thendrawtext("Xoblique",barindex,high+ATR/3,SansSerif,Bold,12) coloured (255,0,10)elsedrawtext("Xoblique",barindex,high+ATR/3,SansSerif,Bold,12) coloured (255,0,10)endifdrawtext("---",barindex,ENTRY,SansSerif,Bold,16) coloured (255,0,10)short=1if bear thenbear=0anglebear=0elsif bear2 thenbear2=0anglebear2=0endifendifendifif trendbreak and (bull or bull2) then//if barindex-firstbearbar<20 or only2=1 thenif showline then//drawline(prevmaxbarTemp,prevlastmaxTemp,maxbarTemp,lastmaxTemp) coloured(255,0,0)if bull thendrawsegment(prevmaxbar2Temp,prevlastmax2Temp,barindex,lastpoint) coloured (0,155,10)elsedrawsegment(prevmaxbar3Temp,prevlastmax3Temp,barindex,lastpoint) coloured (0,155,10)endifendif//else//if showline then//drawline(prevmaxbar2Temp,prevlastmax2Temp,prevmaxbarTemp,prevlastmaxTemp) coloured(255,255,255)//endif//endifif high>ENTRY thenlong=1DRAWARROWUP(barindex,low) coloured (0,155,10)if close<MA200 thendrawtext("Xoblique",barindex,low-ATR/3,SansSerif,Bold,12) coloured (0,155,10)elsedrawtext("Xoblique",barindex,low-ATR/3,SansSerif,Bold,12) coloured (0,155,10)endifdrawtext("---",barindex,ENTRY,SansSerif,Bold,16) coloured (0,155,10)if bull thenbull=0anglebull=0elsif bull2 thenbull2=0anglebull2=0endifendifendif//test=long//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)//endifreturn//return LMA, smoothLMA04/22/2020 at 11:42 PM #12752804/23/2020 at 8:28 AM #12755012/22/2020 at 5:39 AM #154823Hi there,
I’ve been attempting to convert the indicator above into a screener, however i’m not having much luck. Would you be able to please help offer some assistance or insight please?
Thank you
1 user thanked author for this post.
-
AuthorPosts