Forums › ProRealTime English forum › ProOrder support › Double bottom or double top › Reply To: Double bottom or double top
10/30/2017 at 6:47 AM
#50871
Hi all,
I was working in the detection of double top and double bottom (W&M).
- I solve the issue of repeating the locas max and min by adding another condition
- It knows where the pattern is activated or cancelled
- It draws an arrow in possible places to open a trade
- It still having a strange signal when the markets moves very quickly (but I don’t have any idea why is drawing a very strange triangle)
But I do not know yet how will be the ideal W and M pattern, I wonder why there are so many false double top or double bottoms. I though it was the most reliable technical pattern.
Hope I heard from you
W&M patterns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
//LOCALS MINIMUMS AND MAXIMUMS USING LEO MOVING AVERAGE //Autor: LEO //VARIABLES TO BE OPTIMIZED //PERIOD=20 //Period for analysis //Kdouble=0.2 //Factor for defining what is double top or bottom //----------- //Leo Moving Average, formula: LMA= WMA+(WMA-SMA) LMA=2*weightedaverage[period](close)-average[period](close) //Smoothed curve of Leo Moving Average IF BARINDEX > period THEN smoothLMA=weightedaverage[period](LMA) ELSE smoothLMA=undefined ENDIF // Direction or trend of the LMA //once LMAdirection=1 IF BARINDEX > period THEN IF LMA > smoothLMA THEN //LMAdirection=1 //colors r=0 g=130 b=0 ELSE //LMAdirection=-1 r=200 g=0 b=0 ENDIF ENDIF // << Storage of minimums and maximums >> once mintemp=low once posmintemp=1 once maxtemp=high once posmaxtemp=1 IF BARINDEX>2 THEN // the value 0.7 is to ensure that the donchian channel is faster than the curves analysis (this value to be checked) IF low < lowest[round(0.7*period)](low[1]) THEN mintemp=low //minimum temporal posmintemp=BARINDEX //postition of minimum temporal ENDIF IF high > highest[round(0.7*period)](high[1]) then maxtemp=high //maximum temporal posmaxtemp=BARINDEX //position maximum temporal ENDIF ENDIF // << Detecting and locating a local minimums >> // Where the LMA is crossing the smoothed LMA, there is a maximum or minimum nearby // If there is a new local min/max, the preivus one is stored in de varible B... (before) once LEVMIN=low once POSLEVMIN=1 once LEVMAX=high once POSLEVMAX=1 once bullcross=0 once bearcross=0 IF BARINDEX > PERIOD THEN //For avoid computer errors bullcross=LMA crosses over smoothLMA bearcross=LMA crosses under smoothLMA ENDIF IF bullcross and POSLEVMIN<>posmintemp THEN BLEVMIN=LEVMIN //previus local minimum is saved BPOSLEVMIN=POSLEVMIN LEVMIN=mintemp POSLEVMIN=posmintemp support=LEVMIN DRAWARROWUP(POSLEVMIN,LEVMIN) coloured(0,0,0,30) ENDIF // --> Detecting and locating a local maximum IF bearcross and POSLEVMAX<>posmaxtemp THEN BLEVMAX=LEVMAX //previus local maximum is saved BPOSLEVMAX=POSLEVMAX LEVMAX=maxtemp POSLEVMAX=posmaxtemp resistance=LEVMAX DRAWARROWDOWN(POSLEVMAX,LEVMAX) coloured(0,0,0,30) ENDIF support=min(low,support) resistance=max(high,resistance) // << DETECTING DOUBLE TOP OR BOTTOMS >> once WidthDoubleTop = high-low once WidthDoubleBottom = high-low once Wpattern=0 once Mpattern=0 // <<<<<< Double bottoms >>>>>>>>> //looking for the top between two local minimums IF bullcross THEN doublebottomtop=high[BARINDEX-POSLEVMIN+1] // we start looking for the top in between two local minimums POSdoublebottomtop=BARINDEX-POSLEVMIN+1 FOR i = (BARINDEX-POSLEVMIN+1) to (BARINDEX-BPOSLEVMIN-1) DO IF high[i] > doublebottomtop THEN doublebottomtop=high[i] POSdoublebottomtop=BARINDEX-i ENDIF NEXT WidthDoubleBottom = doublebottomtop-(BLEVMIN+LEVMIN)/2 // (top betwen local minimums) - (average of the las two local minimums) IF abs(BLEVMIN-LEVMIN) < Kdouble*WidthDoubleBottom THEN // we have a double bottom Wpattern=1 else Wpattern=0 ENDIF ENDIF // <<<<<<<<<< Double tops >>>>>>> //looking for the bottom between two local maximums IF bearcross THEN doubletopbottom=low[BARINDEX-POSLEVMAX+1] POSdoubletopbottom=BARINDEX-POSLEVMAX+1 FOR i = (BARINDEX-POSLEVMAX+1) to (BARINDEX-BPOSLEVMAX-1) DO IF low[i] < doubletopbottom THEN doubletopbottom=low[i] POSdoubletopbottom=BARINDEX-i ENDIF NEXT WidthDoubleTop=(BLEVMAX+LEVMAX)/2 -doubletopbottom IF abs(BLEVMAX-LEVMAX) < Kdouble*WidthDoubleTop THEN // we have a double top Mpattern=1 else Mpattern=0 ENDIF ENDIF // <<<<<<<<<< DOUBLE TOP AND DOUBLE BOTTOM FOR TRADING >>>>>>>> myATR=AverageTrueRange[2*period](close) IF Wpattern=1 THEN IF close > (doublebottomtop+myATR) or close < (LEVMIN-0.5*myATR) THEN Wpattern=0 // <<<< double bottom has been activated or it was cancelled >>>>> ELSE // <<<<<<< HERE WE HAVE A DOUBLE BOTTOM FOR TRADING >>>>> DRAWTRIANGLE(POSLEVMIN,LEVMIN,POSdoublebottomtop,doublebottomtop,BPOSLEVMIN,BLEVMIN) COLOURED(0,255,0,200) DRAWARROWUP(BARINDEX,low) coloured(0,255,0,100) DRAWRECTANGLE(BPOSLEVMIN,doublebottomtop+WidthDoubleBottom,POSLEVMIN,doublebottomtop+WidthDoubleBottom-Kdouble*WidthDoubleBottom) coloured(0,120,0,255) DRAWTEXT("Target",(BPOSLEVMIN+POSLEVMIN)/2,doublebottomtop+WidthDoubleBottom,SansSerif,Bold,13)coloured(0,120,0,255) ENDIF ENDIF IF Mpattern=1 THEN IF close < (doubletopbottom-myATR) or close > (LEVMAX+0.5*myATR) THEN Mpattern=0 //double top has been activated or it was cancelled ELSE // <<<<<<< HERE WE HAVE A DOUBLE TOP FOR TRADING >>>>> DRAWTRIANGLE(POSdoubletopbottom,doubletopbottom,POSLEVMAX,LEVMAX,BPOSLEVMAX,BLEVMAX) COLOURED(255,0,0,200) DRAWARROWDOWN(BARINDEX,high) coloured(255,0,0,100) DRAWRECTANGLE(BPOSLEVMAX,doubletopbottom-WidthDoubleTop,POSLEVMAX,doubletopbottom-WidthDoubleTop+Kdouble*WidthDoubleTop) coloured(200,0,0,255) DRAWTEXT("Target",(BPOSLEVMAX+POSLEVMAX)/2,doubletopbottom-WidthDoubleTop,SansSerif,Bold,13)coloured(200,0,0,255) ENDIF ENDIF RETURN LMA coloured(r,g,b,200) AS "LMA", support[1] coloured(140,0,200,250) style(DOTTEDLINE,1) as "support[1]", resistance[1] coloured(0,0,250,250) style(DOTTEDLINE,1) as "resistance[1]", smoothLMA coloured(r,g,b,200) style(DOTTEDLINE,1) as "smooth LMA" //, lowest[round(0.7*period)](low[1]), highest[round(0.7*period)](high[1]) |