Axle, Many thanks for sharing ! If someone else have also divergence codes - please feel free to post. It seems to be very powerful tool.
Pilpilonim --- In [email protected], "axle_d" <[EMAIL PROTECTED]> wrote: > > Pilpilonim, > > Don't want to get int the niddle of a discussion you are having with > Terry but he has done some greta coding there. Ijust thought i would > share an RSI divergence code that wa sposted by Aron Pipa .. all credit > goes to him. I just wanted to give you something else to consider in > divergences. > > /*--------------------------------------------------- > RSI Divergence > Aron Pipa, March, 20 , 2006 > --------------------------------------------------------*/ > > GraphXSpace=7; > n=Param("% Reverse ",20,0,100,1); > > Buy=Sell=0; > Var = Zig(RSI(), n); > t= Trough(RSI(), n, 1); > p= Peak(RSI(), n, 1); > x[0] =Var[0]; > price[0] = C[0]; > j=0; > > // bearish divergence > for ( i=0; i<BarCount; i++) > { > if(Var[i] == p[i]) > { > > j++; > x[j] =Var[i]; > price[j] =C[i]; > if(x[j] <x[j-1] && price[j-1]< price[j]) > Sell[i] =1; > } > } > > // bullish divergence > for ( i=0; i<BarCount; i++) > { > if(Var[i] == t[i]) > { > j++; > x[j] =Var[i]; > price[j] =C[i]; > if(x[j] >x[j-1] && price[j]<price[j-1]) > Buy[i] =1; > } > } > > Plot(Var, "", 39); > PlotShapes ( IIf(Sell, shapeCircle, shapeNone), colorRed, 0 , Var,0); > PlotShapes( IIf(Buy, shapeCircle, shapeNone), colorBrightGreen, 0, > Var,0); > > Title ="RSI Divergence" ; > > --- In [email protected], "Terry" <MagicTH@> wrote: > > > > Pilpilonim, > > > > > > > > The earlier conversion to your VT divergence indicator I posted seems > to > > have problems with the direct translation. There were Ref(xxx,-1) > > statements that shouldn't have been there. Also, to get the indicator > to > > fall on the actual day of the peak or valley in the variable > > "DefineTrough", I had to use ref(xxxx, 1) which is forward looking by > 1 > > day. Try this version instead. It shows you the various peaks and > > troughs for RSI and Price so you can decide if it's really doing the > > job. > > > > > > > > I still wonder, after reading the code in detail, if this is doing > what > > is expected. It finds peaks and valleys in the RSI levels, then it > finds > > matching peaks and valleys in the High and Low prices. When it finds > an > > RSI Trough matched to a Price trough it declares this a Bullish > > Divergence. I'm under the impression a divergence is when two > indicators > > go in different directions. > > > > > > > > Last point, it doesn't correctly find all the peaks and troughs. See > > screen shot with circled peak. It found the Price peak, but not the > RSI > > peak. (Screen shot below.) > > > > > > > > "Relative Strength Index"; > > > > //pilpilonim [EMAIL PROTECTED] "...It sure looks good in VT..." > > > > > > > > SetChartOptions(1,chartShowDates); > > > > > > > > RSIper = Param("RSI Periods",5,2,50,1); > > > > RSIndex = RSI(RSIper); > > > > > > > > //This will detect a trough of RSI, then detect a second trough lower > > than the first Trough > > > > > > > > DefineTrough = Ref(RSIndex > Ref(RSIndex,-1) AND Ref(RSIndex,-1) < > > Ref(RSIndex,-2),1); > > > > PrevTrough = ValueWhen(DefineTrough,RSIndex,2); //Finds the RSI of the > > previous RSI trough > > > > ActualTrough = DefineTrough AND PrevTrough > RSIndex; > > > > > > > > PrevPrcTrough = ValueWhen(DefineTrough,L,2); //Finds the Low of the > > previous RSI trough > > > > ActualPrcTrough = DefineTrough AND PrevPrcTrough > L; > > > > > > > > BullishDivergence = ActualTrough AND ActualPrcTrough; > > > > > > > > //This will detect a peak of RSI, then detect a second peak higher > than > > the first peak} > > > > > > > > DefinePeak = Ref(RSIndex < Ref(RSIndex,-1) AND Ref(RSIndex,-1) > > > Ref(RSIndex,-2),1); > > > > PrevPeak = ValueWhen(DefinePeak,RSIndex,2); > > > > ActualPeak = DefinePeak AND PrevPeak > Ref(RSIndex,-1); > > > > > > > > PrevPrcPeak = ValueWhen(DefinePeak,H,2); > > > > ActualPrcPeak = DefinePeak AND PrevPrcPeak < H; > > > > > > > > BearishDivergence = ActualPeak AND ActualPrcPeak; > > > > > > > > Plot(C,Name(),IIf(C > O,colorGreen,colorRed),styleBar | styleThick); > > > > //Plot(H,"High",colorGrey50); > > > > //Plot(L,"Low",colorGrey50); > > > > > > > > Plot(RSIndex,"\nRSI(" + NumToStr(RSIper,1.0) + > > ")",colorDarkRed,styleOwnScale,0,100); > > > > > PlotShapes(IIf (BullishDivergence,shapeCircle,shapeNone),colorGreen,0,L,0 > > ); > > > > > PlotShapes(IIf (BearishDivergence,shapeCircle,shapeNone),colorRed,0,H,0); > > > > > > > > Plot(DefineTrough > > ,"",colorDarkRed,styleHistogram|styleNoLabel|styleOwnScale,0,6); // To > > highlight inside red > > > > Plot(DefineTrough > > ,"",colorRed,styleHistogram|styleNoLabel|styleOwnScale,0,2); > > > > Plot(PrevTrough ,"\nprev Trough > > RSI",colorRed,styleDashed|styleOwnScale); > > > > Plot(ActualTrough > > ,"",colorRed,styleThick|styleArea|styleNoLabel|styleOwnScale,0,6); > > > > Plot(ActualPrcTrough > > > ,"",colorDarkRed,styleThick|styleArea|styleNoLabel|styleOwnScale,- 1,5); > > > > > > > > Plot(-DefinePeak > > ,"",colorGreen,styleHistogram|styleNoLabel|styleOwnScale,- 6,0); //To > > highlight inside brightgreen > > > > Plot(-DefinePeak > > ,"",colorBrightGreen,styleHistogram|styleNoLabel|styleOwnScale,- 2,0); > > > > Plot(-PrevPeak ,"\nprev Peak > RSI",colorGreen,styleDashed|styleOwnScale); > > > > Plot(-ActualPeak > > > ,"",colorBrightGreen,styleThick|styleArea|styleNoLabel|styleOwnScal e,-6, > > 0); > > > > Plot(-ActualPrcPeak > > ,"",colorGreen,styleThick|styleArea|styleNoLabel|styleOwnScale,- 5,1); > > > > > > > > _N(Title = EncodeColor(colorRed) + "Red bars = RSI trough | " + > > EncodeColor(colorDarkRed) + "Dark red bars = Price trough | " + > > > > EncodeColor(colorBrightGreen) + "Bright green bars = RSI peak | " + > > EncodeColor(colorGreen) + "Green bars = Price Peak\n {{VALUES}}"); > > > > > > > > > > > > -- > > > > Terry > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> GFT Forex Trading Accounts As low as $250 with up to 400:1 Leverage. Free Demo. http://us.click.yahoo.com/lpv1TA/jlQNAA/U1CZAA/GHeqlB/TM --------------------------------------------------------------------~-> Please note that this group is for discussion between users only. To get support from AmiBroker please send an e-mail directly to SUPPORT {at} amibroker.com For other support material please check also: http://www.amibroker.com/support.html Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/amibroker/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
