ProRealCode - Trading & Coding with ProRealTime™
J’ai tenté autre chose sachant que je n’avais pas compris que Barindex s’inscrémentait depuis la première barre jusqu’à l’actuelle ;
Mais j’ai toujours un message d’erreur d’offset négatif …
Quelqu’un voit le problème ?
// Cup and Handle exploration written by Jerry Tyliczka
// visit us at: http://portals.wallstreettape.com
//
// This code written per specifications found at
// http://www.haikulabs.com/mh.htm
// Version 1.0
//
// This code calculates the Alpha, Delta, Beta and Gamma values
// but they are not used in the filter criteria as specified
// by the article which this code was based on.
//
// Look for additional changes as I tweak the below code.
// I will also include Scan feature and Backtesting in future release.
//
// Comments, please write to admin@wallstreettape.com
MinPrice=2.5
MinVolume=10000
//Left side of Handle formation can occur anywhere from 2-25days - look at the last 25 bars AND get the number of bars since condition met.
LH=highest[25](Close) // Highest close past 25 days.
BLH=barindex-barindex[LH] // Tells us # of bars that have past since high reached. Used to determine Lowest bar.
BH=lowest[BLH](Close) // Lowest close since the highest value was reached/
BBH=barindex-barindex[BH] // number of bars that have past since lowest value.
NBLH=abs(BLH-BBH) // this is the number of bars in the formation of the left side handle. NBLH must be atleast 2 to be a valid handle formation.
// Now lets get the cup formation. Cup formation can occur anywhere from 23 to 145 days. The left side of the cup can be from 20-120 days AND the right side can be anywhere from 3-25 days.
// get the right side of the cup(low).
BC=lowest[BLH+25](close) // look at 25 bars since the left side of handle.
BBC=barindex-barindex[BC]
// get the left side of the cup.
//
For index1=145+BBC downto BBC do
if high[index1]> high[index1-1] then
LC=high[index1]
BLC=barindex-barindex[LC]
else
LC=LC
endif
Next
//
//// Get highest value before left side of cup started to form.
//
//once BKC =0
For index2 = barindex downto BLC do
if high[index2]> high[index2-1] then
KC=high[index2]
//BKC=barindex[KC]
else
KC=KC
endif
Next
//
Delta= LC/KC
//
////Calculate the up/down relative price value during time frame RC (Right Cup Formation)
DRPV=0
URPV=DRPV
For i=BLH to BBC do
If Close[i] > Close[i+1] then
URPV = Volume[i]*Close[i]- Close[i+1]
else
UPRV=UPRV
endif
If Close[i] < Close[i+1] then
DRPV = Volume[i]*(Close[i+1]-Close[i])
else
DRPV = DRPV
endif
Next
Alpha = URPV/DRPV // Should be >1
// Calculate Beta
DRPV=0
For j=BBH to BLH do
If Close[j]< Close[j+1] then
DRPV = Volume[i]*(Close[i+1]-Close[i])
else
DRPV=DRPV
endif
Next
Beta = URPV/DRPV
Gamma = log(Alpha) + log(Beta) + delta
//
//AddColumn(LH,"Left Handle")
//AddColumn(BH,"Bottom Handle")
//AddColumn(BC,"Bottom Cup")
//AddColumn(LC,"Left Cup")
//AddColumn(ALPHA,"Alpha")
//AddColumn(DELTA,"Delta")
//AddColumn(BETA,"BETA")
//AddColumn(GAMMA,"Gamma")
// Filter Criteria as follows:
// 1. Right side of handle must be at least 2 bars. NBHL>2
// 2. Bottom of the cup must be lower than the left top of the cup.
// 3. Left handle must be lower than or equal to the lect cup formation.
// 4. Bottom of the cup must be less than the left handle.
// 5. Bottom of the handle must be > 80% of the left handle + 20% of the bottom cup.
// 6. Start of cup/handle formation must be greater than precedding chart value. LC>LC
// 7. Minimum price and volume you can set any way you like.
Screener [ NBLH>2 AND Close>BH AND BC<LC AND LH<=LC AND BC<LH AND BH<LH AND (BH>0.8*LH+0.2*BC) AND KC<LC AND Close>MinPrice AND average[30](Volume) > MinVolume and alpha > 1 and beta> 1](Gamma as "gamma")
A la ligne 23, la variable LH aura une valeur, si vous êtes sur le DAX, environ 12500, donc la ligne suivante sera, par exemple à la première barre:
BLH = 1-12500, donc la valeur de BLH ne peut être que négative!
Donc, la ligne 26 sera:
BH = lowest [-12499](close)
Ça ne peut pas marcher!
Hello Roberto,
Je ne comprends pas car sauf erreur :
La variable LH contiendra le cours de clôture inférieur aux 25 dernières barres, il peut être 12500 ou 1.2000 ou 85.43, etc …, donc 1 – cette valeur ne peut être que négative!
Si vous voulez éviter un décalage négatif, vous devez, avec IF …. ENDIF, exécuter cette ligne uniquement lorsque BARINDEX >= LH.
quelque chose m’échappe Roberto :
=> Barindex[LH] est forcément < à Barindex => c’est les nombre de barres maximal ; Barindex ne renvoie pas une valeur de prix ;
Ce n’est pas BARINDEX qui contient un prix, c’est la variable LH, à laquelle vous avez affecté un prix à la ligne 23, au lieu de lui donner un indice!
BARINDEX [[LH] sera:
par conséquent, sur les premières 12499 barres, le résultat de la ligne 24, c’est-à-dire BLH, ne peut être que négatif (-12499, -12498, -12497, …..).
Je suggère toujours d’attendre jusqu’à ce que Nicolas puisse terminer la conversion du code.
Peut-être que vous, à la ligne 23, et dans d’autres, voudriez-vous que LH contienne le numéro de la bougie où le minimum le plus bas se situe entre les 25 derniers, n’est-ce pas?
Non, LOWEST renvoie un prix, pas un index de l’endroit où il s’est produit!
PRT n’a pas de fonction pour savoir dans quel bougie un certain événement s’est produit, vous devez utiliser une boucle FOR …. NEXT pour examiner les bougies passées et découvrir! C’est une opération plus complexe et ça ralentit beaucoup le code!
oui c’est absolument cela Roberto que je cherche à faire ; c’est une piste ! et ce n’est pas grave pour la lenteur, les machines ne sont pas payées à l’heure 😉
Je peux vous donner un exemple sur la façon de trouver la bougie que vous voulez à la ligne 23, pour les suivantes, vous devrez copier ce code et l’adapter vous-même:
LowestPrice = 999999 //Cette variable est utilisée uniquement pour la boucle FOR ... NEXT
FOR i = 0 TO 24 //25 bougies
IF low[i] < LowestPrice THEN
LH = BarIndex[i] //LH contiendra le numéro de bougie où le minimum le plus bas a été trouvé
LowestPrice = low[i]
ENDIF
NEXT
Les machines ne sont pas payées à l’heure, mais … si vous êtes devant l’écran, avec 4-5 graphiques chacun avec des unités de temps différentes et vous voulez passer à un autre instrument … vous verrez que le ralentissement sera impossible à supporter!
Parce que le problème n’est pas un cycle lui-même, il s’agit de nombreux cycles dans les lignes suivantes!
Hello Rberto, Nouvelle version sans erreur mais ne retourne rien ;-(
Vous voyez pourquoi ? (ne tenez pas compte des commentaires qui ne correspondent plus)
on va y arriver !
// Cup and Handle exploration written by Jerry Tyliczka
// visit us at: http://portals.wallstreettape.com
//
// This code written per specifications found at
// http://www.haikulabs.com/mh.htm
// Version 1.0
//
// This code calculates the Alpha, Delta, Beta and Gamma values
// but they are not used in the filter criteria as specified
// by the article which this code was based on.
//
// Look for additional changes as I tweak the below code.
// I will also include Scan feature and Backtesting in future release.
//
// Comments, please write to admin@wallstreettape.com
MinPrice=2.5
MinVolume=10000
//Left side of Handle formation can occur anywhere from 2-25days - look at the last 25 bars AND get the number of bars since condition met.
// Highest close past 25 days.
LH = highest[25](close)
BLH = 0
For i = 25 downto 0 do
if high[i] = LH then
BLH=i // ( Tells us # of bars that have past since high reached. Used to determine Lowest bar.
else
LH = LH
BLH = BLH
endif
Next
// Lowest close since the highest value was reached/
BH = lowest[BLH](Close)
BBH = 0
For j = BLH downto 0 do
if low[j] = BH then
BBH=j // number of bars that have past since lowest value.
else
BH=BH
BBH = BBH
endif
Next
NBLH=BLH-BBH // this is the number of bars in the formation of the left side handle. NBLH must be atleast 2 to be a valid handle formation.
// Now lets get the cup formation. Cup formation can occur anywhere from 23 to 145 days. The left side of the cup can be from 20-120 days AND the right side can be anywhere from 3-25 days.
// get the right side of the cup(low).
// look at 25 bars since the left side of handle.
BC = lowest[BLH+25](close)
BBC = 0
For k = BLH + 25 downto BLH do
if low[k] = BC then
BBC = k // number of bars that have past since lowest value.
else
BBC = BBC
endif
Next
// get the left side of the cup.
//LC = 0
For m =145 + BBC downto BBC do
BLC = 0
if high[m-1]< high[m] then
LC = high[m]
BLC = m
else
LC=LC
endif
Next
//
//// Get highest value before left side of cup started to form.
//
//KC = 0
//BKC = 0
For n= barindex downto BLC do
if high[n-1]< high[n] then
KC=high[n]
//BKC=n
else
KC=KC
endif
Next
//
Delta= LC/KC
//
////Calculate the up/down relative price value during time frame RC (Right Cup Formation)
DRPV=0
URPV=DRPV
For i=BLH to BBC do
If Close[i] > Close[i+1] then
URPV = Volume[i]*Close[i]- Close[i+1]
else
UPRV=UPRV
endif
If Close[i] < Close[i+1] then
DRPV = Volume[i]*(Close[i+1]-Close[i])
else
DRPV = DRPV
endif
Next
Alpha = URPV/DRPV // Should be >1
// Calculate Beta
For j=BBH to BLH do
If Close[j]< Close[j+1] then
DRPV = Volume[i]*(Close[i+1]-Close[i])
else
DRPV=DRPV
endif
Next
Beta = URPV/DRPV
Gamma = log(Alpha) + log(Beta) + delta
//
//AddColumn(LH,"Left Handle")
//AddColumn(BH,"Bottom Handle")
//AddColumn(BC,"Bottom Cup")
//AddColumn(LC,"Left Cup")
//AddColumn(ALPHA,"Alpha")
//AddColumn(DELTA,"Delta")
//AddColumn(BETA,"BETA")
//AddColumn(GAMMA,"Gamma")
// Filter Criteria as follows:
// 1. Right side of handle must be at least 2 bars. NBHL>2
// 2. Bottom of the cup must be lower than the left top of the cup.
// 3. Left handle must be lower than or equal to the lect cup formation.
// 4. Bottom of the cup must be less than the left handle.
// 5. Bottom of the handle must be > 80% of the left handle + 20% of the bottom cup.
// 6. Start of cup/handle formation must be greater than precedding chart value. LC>LC
// 7. Minimum price and volume you can set any way you like.
Screener [ NBLH>2 AND Close>BH AND BC<LC AND LH<=LC AND BC<LH AND BH<LH AND (BH>0.8*LH+0.2*BC) AND KC<LC AND Close>MinPrice AND average[30](Volume) > MinVolume and alpha > 1 and beta> 1](Gamma as "gamma")
Ligne 23 (et autres si nécessaire) Vous ne l’avez pas remplacé par le mien, vous l’avez laissé tel quel et vous avez ajouté une boucle que je ne comprends pas.
Retirez-le ou commentez et remplacez-le par les 7 lignes de mon code.
Répétez l’opération pour toute autre ligne où elle est nécessaire, en changeant la condition LOWEST ou HIGHEST etc …
Hello Roberto, je n’avais pas vu votre code avant de reposter (il me semble que ce serait plutôt [message supprimé, problème de formattage] non ?)
Pour la clareté du code et pour simplifier le travail de checking de vous-même et de Nicolas j’ai repris et adapté un code déjà créé pour identifier par PRC concernant les bars (ci-dessous) ;
cela vous semble-t-il plus clair ? mais le résultat ne retourne toujours rien.
// Cup and Handle exploration written by Jerry Tyliczka
// visit us at: http://portals.wallstreettape.com
//
// This code written per specifications found at
// http://www.haikulabs.com/mh.htm
// Version 1.0
//
// This code calculates the Alpha, Delta, Beta and Gamma values
// but they are not used in the filter criteria as specified
// by the article which this code was based on.
//
// Look for additional changes as I tweak the below code.
// I will also include Scan feature and Backtesting in future release.
//
// Comments, please write to admin@wallstreettape.com
MinPrice=2.5
MinVolume=10000
//Left side of Handle formation can occur anywhere from 2-25days - look at the last 25 bars AND get the number of bars since condition met.
// Highest close past 25 days.
LH = highest[25](close)
RangLH = 0
For i = 0 to 24 do
if high[i] <> LH then
continue
elsif high[i] = LH then
indexLH = barindex[i]
RangLH=barindex[0]-IndexLH // determines Lowest bar #.
break
endif
Next
// Lowest close since the highest value was reached/
BH = lowest[RangLH](Close)
RangBH = 0
For j = 0 to RangLH do
if low[j] <> BH then
continue
elsif low[j] = BH then
IndexBH = barindex[j]
RangBH=barindex[0]-IndexBH
break
endif
Next
NLH=RangLH-RangBH // this is the number of bars in the formation of the left side handle. NRangLH must be atleast 2 to be a valid handle formation.
// Now lets get the cup formation. Cup formation can occur anywhere from 23 to 145 days. The left side of the cup can be from 20-120 days AND the right side can be anywhere from 3-25 days.
// get the right side of the cup(low).
// look at 25 bars since the left side of handle.
BC = lowest[RangLH+25](close)
RangBC = 0
For k = RangLH to RangLH+ 25 do
if low[k] <> BC then
continue
elsif low[k] = BC then
IndexBC = barindex[k]
RangBC =barindex[0]-IndexBC
break
endif
Next
// get the left side of the cup.
LC = 0
RangLC = 0
For m =RangBC to RangBC+145 do
if high[m+1]< high[m] then
continue
else
IndexLC = barindex[m+1]
LC = high[m+1]
RangLC = barindex[0]-IndexLC
endif
Next
//
//// Get highest value before left side of cup started to form.
//
KC = 0
//BKC = 0
For n= RangLC to barindex do
if high[n+1]< high[n] then
continue
else
//IndexKC = barindex[n+1]
KC = high[n+1]
//RangKC = barindex[0]-IndexKC
//BKC=n
endif
Next
Delta= LC/KC
//Calculate the up/down relative price value during time frame RC (Right Cup Formation)
DRPV=0
URPV=DRPV
For o=RangLH to RangBC do
If Close[o] > Close[o+1] then
URPV = Volume[o]*(Close[o]- Close[o+1])
else
UPRV=UPRV
endif
If Close[o] < Close[o+1] then
DRPV = Volume[o]*(Close[o+1]-Close[o])
else
DRPV = DRPV
endif
Next
Alpha = URPV/DRPV // Should be >1
//
// Calculate Beta
For p=RangBH to RangLH do
If Close[p]< Close[p+1] then
DRPV = Volume[i]*(Close[i+1]-Close[i])
else
DRPV=DRPV
endif
Next
Beta = URPV/DRPV
Gamma = log(Alpha) + log(Beta) + delta
//
//AddColumn(LH,"Left Handle")
//AddColumn(BH,"Bottom Handle")
//AddColumn(BC,"Bottom Cup")
//AddColumn(LC,"Left Cup")
//AddColumn(ALPHA,"Alpha")
//AddColumn(DELTA,"Delta")
//AddColumn(BETA,"BETA")
//AddColumn(GAMMA,"Gamma")
// Filter Criteria as follows:
// 1. Right side of handle must be at least 2 bars. NBHL>2
// 2. Bottom of the cup must be lower than the left top of the cup.
// 3. Left handle must be lower than or equal to the lect cup formation.
// 4. Bottom of the cup must be less than the left handle.
// 5. Bottom of the handle must be > 80% of the left handle + 20% of the bottom cup.
// 6. Start of cup/handle formation must be greater than precedding chart value. LC>LC
// 7. Minimum price and volume you can set any way you like.
Screener [ NLH>2 AND Close>BH AND BC<LC AND LH<=LC AND BC<LH AND BH<LH AND (BH>0.8*LH+0.2*BC) AND KC<LC AND Close>MinPrice AND average[30](Volume) > MinVolume and alpha > 1 and beta> 1](Gamma as "gamma")
Bonjour à tous,
Bon voilà ma faible contribution à la communauté ; ce n’est sans doute pas parfait mais ça fonctionne ; -) Cela demande à être amélioré ;
Il faudrait faire plusieurs choses pour l’optimiser qui dépasse ma compétence :
Par ailleurs, j’ai développé l’indicateur qui permet de repérer LH / BC / LH / BH ; il ne marche qu’en Daily ;
Merci de vos remarques et améliorations
Kris
Timeframe (daily)
MinPrice= close > 2.5
MinVolume= average[23](Volume) > 2000
// LEFT HANDLE///////////////////////
LH = highest[24](high)
For i = 0 to 24 do
if high[i] = LH then
indexLH = i
break
endif
Next
//BOTTOM HANDLE///////////////////////
BH = lowest[1+indexLH](low)
For j = 0 to indexLH do
if low[j] = BH then
IndexBH = j
break
endif
Next
NLH=IndexLH-IndexBH
// BOTTOM CUP//////////////////////
BC = low[indexLH]
For k = indexLH to IndexLH+25 do
if low[k+1] > BC then
indexBC = indexBC
elsif low[k+1] < BC then
BC = low[k+1]
IndexBC = k+1
endif
Next
// LEFT CUP
LC = high[indexBC]
For m =IndexBC to IndexBC+145 do
if high[m+1]< LC then
LC = LC
elsif high[m+1]> LC then
LC = high[m+1]
IndexLC = m+1
endif
Next
// LEFT OF THE CUP
KC = low[indexLC]
For n= IndexLC to IndexLC + 50 do
if low[n+1]> KC then
KC = KC
elsif low[n+1] < KC then
KC = low[n+1]
endif
Next
Delta= LC/KC
DRPV1=0
URPV1=0
For o=IndexBC downto IndexLH do
If Close[o+1] < Close[o] then
URPV1 = Volume[o]*(Close[o]- Close[o+1])+URPV1
else
UPRV1=UPRV1
endif
If Close[o] < Close[o+1] then
DRPV1 = Volume[o]*(Close[o+1]-Close[o])+DRPV1
else
DRPV1 = DRPV1
endif
Next
Alpha = URPV1/DRPV1 // Should be >1
AmplitudeMax = Max(LC,LH)/Min(KC,BC)<1.3
////
//// Calculate Beta
//DRPV2=0
//URPV2=0
//
////
//For p=IndexLH downto IndexBH do
//If Close[p+1] > Close[p] then
//URPV2 = Volume[p]*(Close[p+1]-Close[p])+URPV2
//
//else
//URPV2=URPV2
//endif
//
//If Close[p+1]< Close[p] then
//DRPV2 = Volume[p+1]*(Close[p+1]-Close[p])+DRPV2
//
//else
//DRPV2=DRPV2
//endif
//Next
//
//Beta = DRPV2/URPV2
//Gamma = log(Alpha) + log(Beta) + delta
screener [NLH > 2 AND Close>BH AND BC<LC AND LC>0.97*LH AND LC < 1.03*LH and BC<LH AND BH<LH and delta>1 and BH>0.8*LH and BH>BC AND alpha > 1 and MinPrice AND MinVolume and AmplitudeMax](IndexLH as "rang")//AND (BH>0.8*LH+0.2*BC)and beta> 1
DefParam DrawOnLastBarOnly = true
// LEFT HANDLE///////////////////////
LH = highest[24](high)
For i = 0 to 24 do
if high[i] = LH then
indexLH = i
DRAWARROWDOWN(barindex-i,LH)coloured(255,0,0)
break
endif
Next
DRAWVLINE(barindex-indexLH)coloured(255,0,0)
//BOTTOM HANDLE///////////////////////
BH = lowest[1+indexLH](low)
For j = 0 to indexLH do
if low[j] = BH then
IndexBH = j
DRAWARROWUP(barindex-j,BH)coloured(255,192,203)
break
endif
Next
DRAWVLINE(barindex-indexBH)coloured(255,0,0)
// BOTTOM CUP//////////////////////
BC = low[indexLH]
For k = indexLH to IndexLH+25 do
if low[k+1] > BC then
indexBC = indexBC
elsif low[k+1] < BC then
BC = low[k+1]
IndexBC = k+1
endif
Next
For k = indexLH to IndexLH+25 do
if low[k+1] = BC then
DRAWARROWUP(barindex-(k+1),BC)coloured(255,255,0)
endif
Next
DRAWVLINE(barindex-indexBC)coloured(0,0,255)
// LEFT CUP
LC = low[indexBC]
For m =IndexBC to IndexBC+145 do
if high[m+1]< LC then
LC = LC
elsif high[m+1]> LC then
LC = high[m+1]
IndexLC = m+1
endif
Next
DRAWARROWDOWN(barindex-(IndexLC),LC)coloured(255,255,0)
DRAWVLINE(barindex-indexLC)coloured(255,255,0)
KC = low[indexLC]
For n= IndexLC to IndexLC+50 do
if low[n+1]> KC then
KC = KC
elsif low[n+1] < KC then
KC = low[n+1]
IndexKC = n+1
endif
Next
DRAWARROWUP(barindex-(IndexKC),KC)coloured(0,0,0)
DRAWVLINE(barindex-indexKC)coloured(0,100,0)
Return IndexLC
NB : 00-CUP-HANDLE-DAY-INDICATOR-1.itf est le bon : il y a une coquille dans l’autre fichier ;
Screener Détection Figure Tasse et Anse
This topic contains 66 replies,
has 8 voices, and was last updated by deletedaccount210122
5 years ago.
| Forum: | ProScreener : Scanners de Marché & Détection |
| Language: | French |
| Started: | 06/15/2018 |
| Status: | Active |
| Attachments: | 17 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.