ProRealCode - Trading & Coding with ProRealTime™
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;)
defparam calculateonlastbars=1000
defparam drawonlastbaronly=false
showline=1
pinshow=1
HLorClose=1
if barindex=1 then
lastmax=0
lastmin=0
prevlastmax=0
prevlastmin=0
prevlastmax2=0
prevlastmin2=0
prevlastmax3=0
prevlastmin3=0
minbar=barindex
maxbar=barindex
prevminbar=0
prevmaxbar=0
//crossbearbar=barindex
//crossbullbar=barindex
bull=0
bear=0
endif
MA7=average[7](close)
MA200=average[200](close)
Period=10
coefATR=1.5
//1. on utilise des MM pour trouver les points hauts/bas
ATR=averagetruerange[50](close)
DataF = Close
lagF = ROUND((Period-1)/2)
dF = (DataF+(DataF-DataF[lagF]))
LMA = exponentialaverage[period](dF)
//Smoothed curve of zero lag Moving Average
IF BARINDEX > period THEN
smoothLMA=weightedaverage[period](LMA)
ELSE
smoothLMA=undefined
ENDIF
if minbar=0 then
minbar=barindex
endif
if maxbar=0 then
maxbar=barindex
endif
IF BARINDEX > PERIOD THEN //For avoid computer errors
bullcross=LMA crosses over smoothLMA
bearcross=LMA crosses under smoothLMA
ENDIF
//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ème
If bearcross then
//on prend le dernier plus bas
lastmaxtemp=high[1]
maxbartemp=barindex[1]
for i=0 to barindex-minbar-1 do
if high[i]>lastmaxtemp then
lastmaxtemp=high[i]
maxbartemp=barindex[i]
endif
next
//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 then
prevbear2crossbar=prevbearcrossbar
prevbearcrossbar=bearcrossbar
bearcrossbar=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 dernier
if barindex-maxbar<barindex-minbar then
if lastmaxtemp>lastmax then
//prevlastmax2=prevlastmax2
//prevmaxbar2=prevmaxbar2
//prevlastmax=prevlastmax
//prevmaxbar=prevmaxbar
lastmax=lastmaxtemp
maxbar=maxbartemp
endif
//si on est dans le cas normal d'un plus bas suivit d'un plus haut, alors on sauve les derniers plus hauts
else
prevlastmax3=prevlastmax2
prevmaxbar3=prevmaxbar2
prevlastmax2=prevlastmax
prevmaxbar2=prevmaxbar
prevlastmax=lastmax
prevmaxbar=maxbar
lastmax=lastmaxtemp
maxbar=maxbartemp
long=0
bull=0
bull2=0
endif
endif
//test=prevlastmax2
//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)
endif
If bullcross then
//on prend le dernier plus bas
lastmintemp=low[1]
minbartemp=barindex[1]
for i=0 to barindex-maxbar-1 do
if low[i]<lastmintemp then
lastmintemp=low[i]
minbartemp=barindex[i]
endif
next
If lastmax-lastmintemp>ATR[1]*CoefATR then
prevbull2crossbar=prevbullcrossbar
prevbullcrossbar=bullcrossbar
bullcrossbar=barindex
if barindex-minbar<barindex-maxbar then
if lastmintemp<lastmin then
//prevlastmin2=prevlastmin2
//prevminbar2=prevminbar2
//prevlastmin=prevlastmin
//prevminbar=prevminbar
lastmin=lastmintemp
minbar=minbartemp
endif
else
prevlastmin3=prevlastmin2
prevminbar3=prevminbar2
prevlastmin2=prevlastmin
prevminbar2=prevminbar
prevlastmin=lastmin
prevminbar=minbar
lastmin=lastmintemp
minbar=minbartemp
short=0
bear=0
bear2=0
endif
endif
endif
if pinshow then
DRAWTEXT("▼",prevmaxbar,prevlastmax,Dialog,Bold,12) coloured(255,0,0)
endif
if pinshow then
DRAWTEXT("▲",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=1
if lastmax<prevlastmax and prevlastmax<prevlastmax2 and prevlastmax2<>0 and long=0 and maxbar-prevmaxbar2>20 then
bull=1
endif
if lastmin>prevlastmin and prevlastmin>prevlastmin2 and prevlastmin2<>0 and short=0 and minbar-prevminbar2>20 then
bear=1
endif
if lastmax<prevlastmax2 and prevlastmax2<prevlastmax3 and prevlastmax3<>0 and long=0 and maxbar-prevmaxbar2>20 then
bull2=1
endif
if lastmin>prevlastmin2 and prevlastmin2>prevlastmin3 and prevlastmin3<>0 and short=0 and minbar-prevminbar2>20 then
bear2=1
endif
//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 cours
if bear=1 then
lastminTemp=lastmin
prevlastminTemp=prevlastmin
minbarTemp=minbar
prevminbarTemp=prevminbar
prevlastmin2Temp=prevlastmin2
prevminbar2Temp=prevminbar2
AngleBear=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ée
for i=barindex-prevminbartemp-1 downto barindex-prevbullcrossbar do
if low[i]<prevlastminTemp+(((barindex[i]-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp) then
prevlastminTemp=low[i]
prevminbartemp=barindex[i]
// on calcule l'angle de l'oblique
AngleBear=tan((prevlastminTemp-prevlastmin2Temp)/prevlastmin2Temp*100)/(prevminbarTemp-prevminbar2Temp)
endif
next
if lastminTemp>prevlastminTemp+(((minbarTemp-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)-ATR/3 and lastminTemp<prevlastminTemp+(((minbarTemp-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)+ATR/3 then
bear=1
//on recalcule l'angle sur base du 3e point, si besoin
if lastminTemp<prevlastminTemp+(((minbarTemp-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp) then
AngleBear=tan((lastminTemp-prevlastmin2Temp)/prevlastmin2Temp*100)/(minbarTemp-prevminbar2Temp)
endif
else
bear=0
endif
endif
if bear2=1 then
lastminTemp=lastmin
minbarTemp=minbar
prevlastmin2Temp=prevlastmin2
prevminbar2Temp=prevminbar2
prevlastmin3Temp=prevlastmin3
prevminbar3Temp=prevminbar3
AngleBear2=tan((prevlastmin2Temp-prevlastmin3Temp)/prevlastmin3Temp*100)/(prevminbar2Temp-prevminbar3Temp)
for i=barindex-prevminbar2temp-1 downto barindex-prevbull2crossbar do
if low[i]<prevlastmin2Temp+(((barindex[i]-prevminbar2Temp)*Atan(AngleBear))/100*prevlastmin2Temp) then
prevlastmin2Temp=low[i]
prevminbar2temp=barindex[i]
// on calcule l'angle de l'oblique
AngleBear2=tan((prevlastmin2Temp-prevlastmin3Temp)/prevlastmin3Temp*100)/(prevminbar2Temp-prevminbar3Temp)
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ée
if lastminTemp>prevlastmin2Temp+(((minbarTemp-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)-ATR/3 and lastminTemp<prevlastmin2Temp+(((minbarTemp-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)+ATR/3 then
bear2=1
//on recalcule l'angle sur base du 3e point, si besoin
if lastminTemp<prevlastmin2Temp+(((minbarTemp-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)then
AngleBear2=tan((lastminTemp-prevlastmin3Temp)/prevlastmin3Temp*100)/(minbarTemp-prevminbar3Temp)
endif
else
bear2=0
endif
endif
if bull=1 then
lastmaxTemp=lastmax
prevlastmaxTemp=prevlastmax
maxbarTemp=maxbar
prevmaxbarTemp=prevmaxbar
prevmaxbar2Temp=prevmaxbar2
prevlastmax2Temp=prevlastmax2
AngleBull=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 do
if high[i]>prevlastmaxTemp+(((barindex[i]-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)then
prevlastmaxTemp=high[i]
prevmaxbarTemp=barindex[i]
AngleBull=tan((prevlastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(prevmaxbarTemp-prevmaxbar2Temp)
endif
next
if lastmaxTemp>prevlastmaxTemp+(((maxbarTemp-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)-ATR/3 and lastmaxTemp<prevlastmaxTemp+(((maxbarTemp-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)+ATR/3 then
bull=1
if lastmaxtemp>prevlastmaxTemp+(((maxbarTemp-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp) then
AngleBull=tan((lastmaxTemp-prevlastmax2Temp)/prevlastmax2Temp*100)/(maxbarTemp-prevmaxbar2Temp)
endif
else
bull=0
endif
endif
if bull2=1 then
lastmaxTemp=lastmax
prevlastmaxTemp=prevlastmax
maxbarTemp=maxbar
prevmaxbarTemp=prevmaxbar
prevmaxbar2Temp=prevmaxbar2
prevlastmax2Temp=prevlastmax2
prevmaxbar3Temp=prevmaxbar3
prevlastmax3Temp=prevlastmax3
AngleBull2=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
//next
for i=barindex-prevmaxbar2Temp-1 downto barindex-prevbear2crossbar do
if high[i]>prevlastmax2Temp+(((barindex[i]-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)then
prevlastmax2Temp=high[i]
prevmaxbar2Temp=barindex[i]
AngleBull2=tan((prevlastmax2Temp-prevlastmax3Temp)/prevlastmax3Temp*100)/(prevmaxbar2Temp-prevmaxbar3Temp)
endif
next
if lastmaxTemp>prevlastmax2Temp+(((maxbarTemp-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)-ATR/3 and lastmaxTemp<prevlastmax2Temp+(((maxbarTemp-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)+ATR/3 then
bull2=1
if lastmaxtemp>prevlastmax2Temp+(((maxbarTemp-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp) then
AngleBull2=tan((lastmaxTemp-prevlastmax3Temp)/prevlastmax3Temp*100)/(maxbarTemp-prevmaxbar3Temp)
endif
else
bull2=0
endif
endif
trendbreak=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 pas
if HLorClose=1 then
Hi=high
Lo=Low
else
Hi=close
Lo=CLose
endif
if bear then
//if barindex-firstbullbar<20 or only2=1 then
if lo<prevlastminTemp+(((barindex-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)-ATR/3 and low<low[1] then
if HLorClose=1 then
ENTRY=min(prevlastminTemp+(((barindex-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp),MA7)-ATR/3
else
ENTRY=min(close,MA7-ATR/3)
endif
lastpoint=prevlastminTemp+(((barindex-prevminbarTemp)*Atan(AngleBear))/100*prevlastminTemp)
trendbreak=1
else
trendbreak=0
endif
endif
if bull then
//if barindex-firstbearbar<20 then
if hi>prevlastmaxTemp+(((barindex-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)+ATR/3 and high>high[1] then
if HLorClose=1 then
ENTRY=max(prevlastmaxTemp+(((barindex-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp),MA7)+ATR/3
else
ENTRY=max(close,MA7+ATR/3)
endif
lastpoint=prevlastmaxTemp+(((barindex-prevmaxbarTemp)*Atan(AngleBull))/100*prevlastmaxTemp)
trendbreak=1
else
trendbreak=0
endif
endif
if 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] then
if HLorClose=1 then
ENTRY=min(prevlastmin2Temp+(((barindex-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp),MA7)-ATR/3
else
ENTRY=min(close,MA7-ATR/3)
endif
lastpoint=prevlastmin2Temp+(((barindex-prevminbar2Temp)*Atan(AngleBear2))/100*prevlastmin2Temp)
trendbreak=1
else
trendbreak=0
endif
endif
if bull2 then
if hi>prevlastmax2Temp+(((barindex-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)+ATR/3 and high>high[1] then
if HLorClose=1 then
ENTRY=max(prevlastmax2Temp+(((barindex-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp),MA7)+ATR/3
else
ENTRY=max(close,MA7+ATR/3)
endif
lastpoint=prevlastmax2Temp+(((barindex-prevmaxbar2Temp)*Atan(AngleBull2))/100*prevlastmax2Temp)
trendbreak=1
else
trendbreak=0
endif
endif
//6. Si on a eu une cassure, on détermine notre point d'entrée et on affiche notre oblique
if trendbreak and (bear or bear2) then
//if barindex-firstbullbar<20 or only2=1 then
if showline then
//drawline(prevminbarTemp,prevlastminTemp,minbarTemp,lastminTemp) coloured(0,255,10)
if bear then
drawsegment(prevminbar2Temp,prevlastmin2Temp,barindex,lastpoint)coloured (255,0,10)
else
drawsegment(prevminbar3Temp,prevlastmin3Temp,barindex,lastpoint)coloured (255,0,10)
endif
endif
//else
//if showline then
//drawline(prevminbar2Temp,prevlastmin2Temp,prevminbarTemp,prevlastminTemp) coloured(255,255,255)
//endif
//endif
if low<ENTRY then
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
if close>MA200 then
drawtext("Xoblique",barindex,high+ATR/3,SansSerif,Bold,12) coloured (255,0,10)
else
drawtext("Xoblique",barindex,high+ATR/3,SansSerif,Bold,12) coloured (255,0,10)
endif
drawtext("---",barindex,ENTRY,SansSerif,Bold,16) coloured (255,0,10)
short=1
if bear then
bear=0
anglebear=0
elsif bear2 then
bear2=0
anglebear2=0
endif
endif
endif
if trendbreak and (bull or bull2) then
//if barindex-firstbearbar<20 or only2=1 then
if showline then
//drawline(prevmaxbarTemp,prevlastmaxTemp,maxbarTemp,lastmaxTemp) coloured(255,0,0)
if bull then
drawsegment(prevmaxbar2Temp,prevlastmax2Temp,barindex,lastpoint) coloured (0,155,10)
else
drawsegment(prevmaxbar3Temp,prevlastmax3Temp,barindex,lastpoint) coloured (0,155,10)
endif
endif
//else
//if showline then
//drawline(prevmaxbar2Temp,prevlastmax2Temp,prevmaxbarTemp,prevlastmaxTemp) coloured(255,255,255)
//endif
//endif
if high>ENTRY then
long=1
DRAWARROWUP(barindex,low) coloured (0,155,10)
if close<MA200 then
drawtext("Xoblique",barindex,low-ATR/3,SansSerif,Bold,12) coloured (0,155,10)
else
drawtext("Xoblique",barindex,low-ATR/3,SansSerif,Bold,12) coloured (0,155,10)
endif
drawtext("---",barindex,ENTRY,SansSerif,Bold,16) coloured (0,155,10)
if bull then
bull=0
anglebull=0
elsif bull2 then
bull2=0
anglebull2=0
endif
endif
endif
//test=long
//drawtext("#test#",barindex,low-20,SansSerif,Bold,10) coloured (0,0,10)
//endif
return
//return LMA, smoothLMA
Signal and basic system attached, exit signal and stops would need to be worked to suit the product etc
For people interest on what it looks on the chart, here is a picture of the indicator kindly shared by stefou102. Really nice and accurate, thanks for giving back to the community! 🙂
Trendline break
This topic contains 3 replies,
has 4 voices, and was last updated by Bos.
5 years, 1 month ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 04/08/2020 |
| Status: | Active |
| Attachments: | 3 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.