[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: divergence



PureBytes Links

Trading Reference Links

hi JB, 

15 bar rsi, 21 bar stoch and 21 bar cci negative divergence

 here's something put together using coding that was generously 
supplied by Dimitris.

 Don

              /*The Saturation Indicator D_sat, by Dimitris Tsokakis, 
Dec 2002*/

              Plot(IIf(Day() > Ref(Day(),-
              1),1,0),"",colorPink,styleHistogram|styleOwnScale);

              Plot(IIf(Month() != Ref(Month(),-
              1),1,0),"",colorWhite,styleHistogram|styleOwnScale);
              P=30;
              CMO30=100*((Sum(IIf(C>Ref(C,-1),(C-Ref(C,-1)),0),P))-
(Sum(IIf(C<Ref
              (C,-1),(Ref(C,-1)-C),0),P)))/((Sum(IIf(C>Ref(C,-1),(C-
Ref(C,-1)),0),P)
              +(Sum(IIf(C<Ref(C,-1),(Ref(C,-1)-C),0),P))));

              C1=DEMA(CMO30,30);
              D_sat10=RSIa(C1,10);
              D_sat5=RSIa(C1,5);
              //Time_Study = 
              Plot(D_sat10,"D_sat10",4,5);
              Plot(D_sat5,"D_sat5",5,5);
              Plot(D_sat5-D_sat10,"D_sat difference",7,15);


              // Rribbon Code starts here

              up =Cross(d_sat5,d_sat10)OR d_sat5 > d_sat10;
              down =Cross(d_sat10,d_sat5)OR d_sat10 > d_sat5;

              //Plot( Close, "Price", colorBlue, styleCandle );
              Plot( 100, /* defines the height of the ribbon in 
percent of pane 
              width */
              "Ribbon",IIf( up, colorWhite, IIf( down, colorBlue, 
0 )), /* choose 
              color*/
              styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

              Buy = d_sat5 < .45;
              Sell = d_sat5 > 99 AND D_sat10 > 95.20; 
              PlotShapes(IIf
(Buy,shapeUpArrow,shapeNone),colorBrightGreen ,O,40);
              PlotShapes(IIf(Sell,shapeDownArrow, shapeNone), 
colorRed );

              Title = WriteVal( Interval()/60,1 )+" "+ "Min.with"+" 
Divergence"+
              "\nO="+WriteVal(O,1.2)+ 
              "\nH="+WriteVal(H,1.2)+
              "\nL ="+WriteVal(L,1.2)+
              "\nC="+WriteVal(C,1.2);

              //plot shapes for CCI > 160 < -160
              OffsetOBCCI = Param(" Red 1 ",78,-100,100);
              OffsetOSCCI = Param(" Green 1 ",-37,-100,100);
              PlotShapes( IIf(CCI(21)>160 , shapeDigit1+ 
shapePositionAbove, 
              shapeNone), colorRed,H,OffsetOBCCI );
              PlotShapes( IIf(CCI(21)<-160, shapeDigit1+ 
shapePositionAbove, 
              shapeNone), colorBrightGreen,L,OffsetOSCCI );

              //plot shapes for RSI >62 < 200
              OffsetOBRSI = Param(" Red 2 ",52,-100,100);
              OffsetOSRSI = Param(" Green 2 ",-3,-100,100);
              PlotShapes( IIf(RSI(14)>62 , shapeDigit2+ 
shapePositionAbove, 
              shapeNone), colorRed,H,OffsetOBRSI );
              PlotShapes( IIf(RSI(14)<23, shapeDigit2+ 
shapePositionAbove, 
              shapeNone), colorBrightGreen,L,OffsetOSRSI );

              //plot shapes for Stoch 
              OffsetOBStoch = Param(" Red 3 ",23,-100,100);
              OffsetOSStoch = Param(" Green 3 ",22,-100,100);
              PlotShapes( IIf(Stoch()>62 , shapeDigit3+ 
shapePositionAbove, 
              shapeNone), colorRed,H,OffsetOBStoch );
              PlotShapes( IIf(Stoch()<.70, shapeDigit3+ 
shapePositionAbove, 
              shapeNone), colorBrightGreen,L,OffsetOSStoch );

              /************************************/

              ST33=CCI(21);
              TR1=LLVBars(ST33,4);
              TR2=IIf(ST33<30 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-
1),0);
              TRC=IIf(TR2>0,C,0);
              vs=ValueWhen(tr2, Ref(st33,-1), 1);
              dvs=vs-Ref(vs,-1);
              vc=ValueWhen(trc, LLV(C,3), 1);
              dvc=vc-Ref(vc,-1);
              diver=IIf(dvs>0 AND dvc<0,30,0);
              DAS=BarsSince(Ref(TR2,-1)>0);
              DDCCI=IIf(DAS<20 AND C>=Ref(C,-1),DIVER,0);
              Buy=DDCCI>0 ;

              /*Negative divergence for use in Indicator Builder and 
Automatic 
              Analysis (scan mode),by Dimitris Tsokakis*/

              ST33=CCI(21);
              TR1=HHVBars(ST33,4);
              TR2=IIf(ST33>70 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-
1),0);
              TRC=IIf(TR2>0,C,0);
              vs=ValueWhen(tr2, Ref(st33,-1), 1);
              dvs=vs-Ref(vs,-1);
              vc=ValueWhen(trc, HHV(H,3), 1);
              dvc=vc-Ref(vc,-1);
              diver=IIf(dvs<0 AND dvc>0,90,0);
              DAS=BarsSince(Ref(TR2,-1)>0);
              dddCCI=IIf(DAS<20 AND C<Ref(C,-1),DIVER,0);
              Negccidiv=dddCCI==90;
              OffsetCCI = Param("Black 1",77,-100,300,1);
              PlotShapes( IIf(negccidiv, shapeDigit1+ 
shapePositionAbove, 
              shapeNone), colorBlack,H,OffsetCCI );

              ST33=RSI(15);
              TR1=HHVBars(ST33,4);
              TR2=IIf(ST33>70 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-
1),0);
              TRC=IIf(TR2>0,C,0);
              vs=ValueWhen(tr2, Ref(st33,-1), 1);
              dvs=vs-Ref(vs,-1);
              vc=ValueWhen(trc, HHV(H,3), 1);
              dvc=vc-Ref(vc,-1);
              diver=IIf(dvs<0 AND dvc>0,90,0);
              DAS=BarsSince(Ref(TR2,-1)>0);
              dddRSI=IIf(DAS<20 AND C<Ref(C,-1),DIVER,0);
              NegRSIdiv=dddRSI==90;
              OffsetRsi = Param("Black 2",40,-100,300,1);
              PlotShapes( IIf(negRSIdiv, shapeDigit2+ 
shapePositionAbove, 
              shapeNone), colorBlack,H,OffsetRsi );

              ST33=Stoch(21);
              TR1=HHVBars(ST33,4);
              TR2=IIf(ST33>70 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-
1),0);
              TRC=IIf(TR2>0,C,0);
              vs=ValueWhen(tr2, Ref(st33,-1), 1);
              dvs=vs-Ref(vs,-1);
              vc=ValueWhen(trc, HHV(H,3), 1);
              dvc=vc-Ref(vc,-1);
              diver=IIf(dvs<0 AND dvc>0,90,0);
              DAS=BarsSince(Ref(TR2,-1)>0);
              dddSTOCH=IIf(DAS<20 AND C<Ref(C,-1),DIVER,0);
              NegSTOCHdiv=dddSTOCH==90;
              Offsetstoch = Param("Black 3",16,-100,300,1);
              PlotShapes( IIf(negSTOCHdiv, shapeDigit3+ 
shapePositionAbove, 
              shapeNone), colorBlack,H,Offsetstoch );

              /***********************************/

              WriteIf(negSTOCHdiv,EncodeColor(colorRed)
+"divergence",EncodeColor
              (colorBlack));

--- In amibroker@xxxxxxxxxxxxxxx, "emarco" <emarco@xxxx> wrote:
> Hi Dimitris,
> 
> I am developing a trading system and improving the exit signals.
> Looking at divergences I found very good exit signals.
> I found several divergence codes  for IB done by you to backtest. 
They are really very good!!
> Do u have any other code about divergence? RSI divergence?
> Below are the ones I found.
> Thanks
> 
> JB
> 
> 
>  
> ST33=MACD();
> bars=50;
> TR1=LLVBars(ST33,5);
> COND1=TR1>0 AND Ref(TR1,-1)==0 AND Ref(ST33,-1)<0;
> TR2=IIf(COND1,Ref(ST33,-1),0);
> Plot(st33,"MACD",1,1);
> M1=ValueWhen(COND1,ST33);
> P1=ValueWhen(COND1,LLV(L,3));
> DM1=M1-Ref(M1,-1);DP1=P1-Ref(P1,-1);
> DT=Ref(BarsSince(COND1),-1);
> POSDIV=DM1>0 AND DP1<0 AND DT<BARS;Plot(Ref(POSDIV*Ref(ST33,-
1),1),"",5,2);
> TR11=HHVBars(ST33,5);
> COND11=TR11>0 AND Ref(TR11,-1)==0 AND Ref(ST33,-1)>0;
> TR21=IIf(COND11,Ref(ST33,-1),0);
> M11=ValueWhen(COND11,ST33);
> P11=ValueWhen(COND11,HHV(H,3));
> DM11=M11-Ref(M11,-1);DP11=P11-Ref(P11,-1);
> DT1=Ref(BarsSince(COND11),-1);
> NEGDIV=DM11<0 AND DP11>0 AND DT1<BARS;Plot(NEGDIV*ST33,"",4,2);
> Filter=posdiv OR negdiv;
> AddColumn(posdiv,"POSITIVE DIV",1.0);
> AddColumn(NEGDIV,"NEGATIVE DIV",1.0);
> 
> Paste in indicator builder or in AA and explore .
> For the N100 database, 13/100 of the population presented a bullish 
MACD divergence on March13, signaling the recent movement.
> Another version of MACD divergence may come through trendlines.
> There are some code problems, trendlines are based on Peak/Trough , 
which do not function properly with negative arrays.
> We may overcome this difficulty using a 1000+MACD() instead of MACD
() itself [I think the lowest MACD() for the last 10 years
> was around -800 for ^N225]. I have to check some details for a 
uniform per= value and post this alternative too. 
> 
> Description:
> A negative Stochastic divergence occurs when the tangent of 
Stochastic oscillator's graph is descending, whereas the tangent of 
price's graph is ascending for the same time interval .
> The occurrence of a negative stochastic divergence in overbought 
area, usually signals a trend reversal,
> especially if it is confirmed by complementary criteria.
> 
> Formula:
> /*Negative Stochastic divergence for use in 
> Indicator Builder and Automatic Analysis (scan mode),
> by Dimitris Tsokakis*/
> 
> ST33=stochd(14);
> TR1=HHVBARS(ST33,4);
> TR2=IIF(ST33>70 AND TR1>0 AND REF(TR1,-1)==0,ref(ST33,-1),0);
> TRC=IIF(TR2>0,C,0);
> vs=valuewhen(tr2, ref(st33,-1), 1);
> dvs=vs-ref(vs,-1);
> vc=valuewhen(trc, HHV(H,3), 1);
> dvc=vc-ref(vc,-1);
> diver=iif(dvs<0 and dvc>0,90,0);
> DAS=BARSSINCE(REF(TR2,-1)>0);
> ddd=IIF(DAS<20 AND C<REF(C,-1),DIVER,0);
> GRAPH1=TR2;
> graph0=ddd;
> graph0barcolor=4;
> GRAPH1STYLE=2;
> graph1barcolor=1;
> SELL=ddd==90;
> Description:A positive stochastic divergence occurs when the 
tangent of Stochastic oscillator's graph is ascending, whereas the 
tangent of price's graph is descending for the same time 
interval .The occurrence of a positive stochastic divergence in 
oversold area, usually signals a trend reversal,especially if it is 
confirmed by complementary criteria.Formula:/*Positive Stochastic 
Divergence for use in 
> Indicator Builder and Automatic Analysis (scan mode),
> by Dimitris Tsokakis*/
> 
> ST33=STOCHD(14);
> TR1=LLVBARS(ST33,4);
> TR2=IIF(ST33<30 AND TR1>0 AND REF(TR1,-1)==0,ref(ST33,-1),0);
> TRC=IIF(TR2>0,C,0);
> vs=valuewhen(tr2, ref(st33,-1), 1);
> dvs=vs-ref(vs,-1);
> vc=valuewhen(trc, LLV(c,3), 1);
> dvc=vc-ref(vc,-1);
> diver=iif(dvs>0 and dvc<0,30,0);
> DAS=BARSSINCE(REF(TR2,-1)>0);
> DD=IIF(DAS<20 AND C>=REF(C,-1),DIVER,0);
> GRAPH0=TR2;
> GRAPH0STYLE=2;
> graph0barcolor=12;
> graph1=dd;
> graph1barcolor=5;
> BUY=DD>0 ;


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/