Skip to main content

Resistance and Support Afl amibroker

After months of hardwork, I was able to find this  code, You can use it to find the Resistance and Support of any timeframe in Ambroker. This can be used in weekly timeframes to pick weekly stocks for short term trading.  These levels are also called as the demand and supply zones. I will update in another post about how to pick stocks for weekly timeframes using this amibroker formula.

thanks for reading : )

thanks to original creator of this afl : )



_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
#pragma nocache
// Commentry output ....
EnableTextOutput(False);
AudioAlert = ParamToggle("Audio Alert", "On|Off");
Print_SR = ParamToggle("Sup / Res", "On|Off");



Text_Display = ParamToggle("Alert Messages", "On|Off"); // Display Alert messages on Chart.

_SECTION_BEGIN("DT /DB Parameters");
DT_DB_Sens = Param("Sensitivity % ", 0.15, 0.1, 2.0, 0.05);
DT_DB_Range = Param("How Many Periods ?", 14, 2, 200, 1);
_SECTION_END();



_SECTION_BEGIN("S / R Parameters");
Sensitivity = Param("Sensitivity",32,0,100,1);

DisRange = Param("Plot 'far away' Lines Trigger",300,0,1000,20);
Color_SL= ParamColor("Support",colorLime);
Color_RL= ParamColor("Resistance",colorRed);
_SECTION_END();
MACD_Buy = Cross( MACD(),Signal() );
MACD_Sell = Cross(Signal() ,MACD());

NewDay = Day()!= Ref(Day(), -1);

DH = HHV( H, NewDay);
DL =  LLV(L, NewDay);
rsiDH = HHV( RSIa(H, 14), NewDay); //param 14
rsiDL =  LLV(RSIa(L, 14), NewDay);
RSI_Parameter = Param("RSIA PARAM",15,8,20,1);
////// RSI Day high / low detection ////
RSIBull1 = (L < Ref(dl, -1) AND RSIa(L, RSI_Parameter) > Ref(RSIdl, -1)) OR
           (L > Ref(dl, -1) AND RSIa(L, RSI_Parameter) < Ref(RSIdl, -1)) ;
RSIBear1 = (H > Ref(dh, -1) AND RSIa(H, RSI_Parameter) < Ref(RSIdh, -1)) OR
           (H < Ref(dh, -1) AND RSIa(H, RSI_Parameter) > Ref(RSIdh, -1));
RSIburev = BarsSince(RSIbull1);
RSIberev = BarsSince(RSIbear1);

CCI_Periods = Param("CCI Periods",32,10,50,1);

bear_CCI = (CCI() >Ref( HHV(CCI(), CCI_Periods), -1)   AND H < Ref(HHV(H, CCI_Periods), -1)) OR
             (CCI() < Ref( HHV(CCI(), CCI_Periods), -1)   AND H > Ref(HHV(H, CCI_Periods), -1));

bull_CCI = (CCI() > Ref( LLV(CCI(), CCI_Periods), -1)   AND L < Ref(LLV(L, CCI_Periods), -1)) OR
            ( CCI() < Ref( LLV(CCI(), CCI_Periods), -1)   AND L > Ref(LLV(L, CCI_Periods), -1));
Sbullcci = BarsSince(bull_CCI);
Sbearcci = BarsSince(bear_CCI);

BeReversal = ( Close >= HHV( Close, 18 ) AND RSI(14) < HHV( RSI(14), 18 )) ;
BuReversal = ( Close <= LLV( Close, 18 ) AND RSI(14) > LLV( RSI(14), 18 ));
BeReversal1 = ( RSI(15) <= LLV( RSI(14), 14) AND Close > LLV(Close,14));
BuReversal1 = ( RSI(15) >= HHV( RSI(14), 14 ) AND Close < HHV( Close, 14 ));



NewBeReversal = ( H >= (Ref(HHV( H, 24 ), -1)+1) AND (RSIa(H, 24) < (HHV( RSIa(H, 24), 24 )) - 2));
NewBuReversal = ( L <= (Ref(LLV( L, 24 ), -1)-1) AND (RSIa(L,24) > (LLV( RSIa(L,24), 24 )) + 2));
Confirm_BeReversal = Ref( NewBeReversal, -1) AND H <= Ref(H, -1);
Confirm_BuReversal = Ref(NewBuReversal, -1) AND L >= Ref(L, -1);
since_BeReversal = BarsSince(BeReversal);
since_BuReversal = BarsSince(BuReversal);

since_Confirm_BeReversal = BarsSince(Confirm_BeReversal);
since_Confirm_BuReversal = BarsSince(Confirm_BuReversal);

sinceOverBought = BarsSince(RSI(14) > 65);
sinceOverSold = BarsSince(RSI(14) < 35);



/*BULLISH STOCHASTIC DIVERGENCE, DD==30*/
ST33=StochD();
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=DD;
//Graph0BarColor=4;
STBULL=DD==30;



/*BEARISH STOCHASTIC DIVERGENCE, BDDD==90*/

BTR1=HHVBars(ST33,4);
BTR2=IIf(ST33>70 AND BTR1>0 AND Ref(BTR1,-1)==0,Ref(ST33,-1),0);
BTRC=IIf(BTR2>0,C,0);
Bvs=ValueWhen(Btr2, Ref(st33,-1), 1);
Bdvs=Bvs-Ref(Bvs,-1);
Bvc=ValueWhen(Btrc, HHV(H,3), 1);
Bdvc=Bvc-Ref(Bvc,-1);
Bdiver=IIf(Bdvs<0 AND Bdvc>0,90,0);
BDAS=BarsSince(Ref(BTR2,-1)>0);
Bddd=IIf(BDAS<20 AND C<=Ref(C,-1),BDIVER,0);
//Graph2=BDDD;
//Graph2BarColor=4;
STBEAR=BDDD==90;
sinceSTBULL = BarsSince(STBULL);
sinceSTBEAR = BarsSince(STBEAR);


Hist = MACD()-Signal();
macdBeReversal = ( H >= (Ref(HHV( H, 14 ), -1)+2) AND (Hist < (HHV( Hist, 14 )) - 2));
macdBuReversal = ( L <= (Ref(LLV( L, 14 ), -1)-2) AND (Hist > (LLV( Hist, 14 )) + 2));
Confirm_macdBeReversal = Ref(macdBeReversal, -1) AND H <= Ref(H, -1);
Confirm_macdBuReversal = Ref(macdBuReversal, -1) AND L >= Ref(L, -1);



PlotShapes(shapeHollowSmallSquare  * MACD_Buy, colorGreen, 0, L, -5);
PlotShapes(shapeHollowSmallSquare * MACD_Sell, colorDarkRed, 0, H, 5);

PlotShapes(shapeHollowSmallCircle  * BuReversal, colorGreen, 0, L, -5);
PlotShapes(shapeHollowSmallCircle * BeReversal, colorRed, 0, H, 5);
PlotShapes(shapeSmallCircle  * BuReversal1, colorGreen, 0, L, -5);
PlotShapes(shapeSmallCircle * BeReversal1, colorRed, 0, H, 5);
PlotShapes(shapeSmallCircle  * Confirm_MacdBuReversal, colorDarkGreen, 0, L, -4);
PlotShapes(shapeSmallCircle * Confirm_MacdBeReversal, colorDarkRed, 0, H, 4);
PlotShapes(shapeStar  * confirm_BuReversal, colorDarkGreen, 0, L, -11);
PlotShapes(shapeStar * Confirm_BeReversal, colorRed, 0, H, 11);
PlotShapes(shapeSmallSquare  * STBULL, colorBlue, 0, L, -15);
PlotShapes(shapeSmallSquare * STBEAR, colorRed, 0, H, 15);





Plot( MA( C, 21 ), _DEFAULT_NAME(), ParamColor("Color", colorBlack ),1+ 4096+styleNoTitle );







//per1 = SelectedValue(Sensitivity *SelectedValue(0.2*uIV_AVG30));
per1 = 1;
per2 = SelectedValue(per1 * 3);
x=Cum(1);
Tp1 = TroughBars(L,per1,1) == 0;
Pp1 = PeakBars (H,per1,1) == 0;
Tp2 = TroughBars(L,per2,1) == 0;
Pp2 = PeakBars (H,per2,1) == 0;

XT1 =SelectedValue(ValueWhen(Tp1,x,1));
XT2 =SelectedValue(ValueWhen(Tp1,x,2));
XT3 =SelectedValue(ValueWhen(Tp1,x,3));
XT4 =SelectedValue(ValueWhen(Tp1,x,4));
XT5 =SelectedValue(ValueWhen(Tp1,x,5));
XT6 =SelectedValue(ValueWhen(Tp2,x,1));
XT7 =SelectedValue(ValueWhen(Tp2,x,2));

XP1 =SelectedValue(ValueWhen(Pp1,x,1));
XP2 =SelectedValue(ValueWhen(Pp1,x,2));
XP3 =SelectedValue(ValueWhen(Pp1,x,3));
XP4 =SelectedValue(ValueWhen(Pp1,x,4));
XP5 =SelectedValue(ValueWhen(Pp1,x,5));
XP6 =SelectedValue(ValueWhen(Pp2,x,1));
XP7 =SelectedValue(ValueWhen(Pp2,x,2));

T1 = SelectedValue(ValueWhen(Tp1,L,1));
T2 = SelectedValue(ValueWhen(Tp1,L,2));
T3 = SelectedValue(ValueWhen(Tp1,L,3));
T4 = SelectedValue(ValueWhen(Tp1,L,4));
T5 = SelectedValue(ValueWhen(Tp1,L,5));
T6 = SelectedValue(ValueWhen(Tp2,L,1));
T7 = SelectedValue(ValueWhen(Tp2,L,2));

P1 = SelectedValue(ValueWhen(Pp1,H,1));
P2 = SelectedValue(ValueWhen(Pp1,H,2));
P3 = SelectedValue(ValueWhen(Pp1,H,3));
P4 = SelectedValue(ValueWhen(Pp1,H,4));
P5 = SelectedValue(ValueWhen(Pp1,H,5));
P6 = SelectedValue(ValueWhen(Pp2,H,1));
P7 = SelectedValue(ValueWhen(Pp2,H,2));

breakout_lasttrough_G1 = Cross(T1,C);
breakout_lasttrough_G2 = Cross(T6,C);
breakout_lastpeak_G1 = Cross(C,P1);
breakout_lastpeak_G2 = Cross(C,P6);
bu_breakout = Cross(C,P1) OR Cross(C,P6);
be_breakout = Cross(T1,C) OR Cross(T6,C);
break_G1_val = IIf(breakout_lasttrough_G1,-1,IIf(breakout_lastpeak_G1,1,0));
break_G2_val = IIf(breakout_lasttrough_G2,-1,IIf(breakout_lastpeak_G2,1,0));





Vis_percent =DisRange*SelectedValue(MA(abs(ROC(C,1)),10));
pR = (Vis_percent/100) + 1;
nR = ((100-VIS_percent)/100);
lC = SelectedValue(C);
RT1 = T1<PR*LC & T1>nR*LC;
RT2 = T2<PR*LC & T2>nR*LC;
RT3 = T3<PR*LC & T3>nR*LC;
RT4 = T4<PR*LC & T4>nR*LC;
RT5 = T5<PR*LC & T5>nR*LC;
RP1 = P1<PR*LC & P1>nR*LC;
RP2 = P2<PR*LC & P2>nR*LC;
RP3 = P3<PR*LC & P3>nR*LC;
RP4 = P4<PR*LC & P4>nR*LC;
RP5= P5<PR*LC & P5>nR*LC;
RT6= T6<PR*LC & T6>nR*LC;
RT7= T7<PR*LC & T7>nR*LC;
RP6= P6<PR*LC & P6>nR*LC;
RP7= P7<PR*LC & P7>nR*LC;



AnZ= T1==0 & T2==0 & T3==0 & T4==0 & T5==0 & T6==0 & T7==0 & P1==0 & P2==0 & P3==0 & P4==0 & P5==0 & P6==0 & P7==0;

LastBar = Cum(1) == SelectedValue(Cum(1));


Plot(IIf(x>=XT1 & RT1 &NOT T1==0,T1,-1e10),"T1",colorBlue,1 + 2048+styleNoTitle);
Plot(IIf(x>=XT2 & RT2 &NOT T2==0,T2,-1e10),"T2",IIf( SelectedValue(C)<T2,Color_RL, Color_SL ),1 + 2048+styleNoTitle);
Plot(IIf(x>=XT3 & RT3 &NOT T3==0,T3,-1e10),"T3",IIf( SelectedValue(C) < T3 , Color_RL, Color_SL ),1 + 2048+styleNoTitle);
Plot(IIf(x>=XT4 & RT4 &NOT T4==0,T4,-1e10),"T4",IIf( SelectedValue(C)<T4,Color_RL, Color_SL ),1 + 2048+styleNoTitle);
Plot(IIf(x>=XT5 & RT5 &NOT T5==0,T5,-1e10),"T5",IIf( SelectedValue(C)<T5,Color_RL, Color_SL ),1 + 2048+styleNoTitle);

Plot(IIf(x>=XP1 & RP1 &NOT P1==0,P1,-1e10), "P1" ,colorBlue,1 + 2048+styleNoTitle);
Plot(IIf(x>=XP2 & RP2 &NOT P2==0,P2,-1e10), "P2" ,IIf( SelectedValue(C)<P2,Color_RL, Color_SL ),1 + 2048+styleNoTitle);
Plot(IIf(x>=XP3 & RP3 &NOT P3==0,P3,-1e10), "P3" ,IIf( SelectedValue(C)<P3,Color_RL, Color_SL ),1 + 2048+styleNoTitle);
Plot(IIf(x>=XP4 & RP4 &NOT P4==0,P4,-1e10), "P4" ,IIf( SelectedValue(C)<P4,Color_RL, Color_SL ),1 + 2048+styleNoTitle);
Plot(IIf(x>=XP5 & RP5 &NOT P5==0,P5,-1e10),"P5",IIf( SelectedValue(C)<P5,Color_RL, Color_SL ),1 + 2048+styleNoTitle);

Plot(IIf(x>=XT6 & RT6 &NOT T6==0,T6,-1e10),"T6",IIf( SelectedValue(C)<T6,Color_RL, Color_SL ),8 + 2048+styleNoTitle);
Plot(IIf(x>=XT7 & RT7 &NOT T7==0,T7,-1e10),"T7",IIf( SelectedValue(C)<T7,Color_RL, Color_SL ),8 + 2048+styleNoTitle);
Plot(IIf(x>=XP6 & RP6 &NOT P6==0,P6,-1e10),"P6",IIf( SelectedValue(C)<P6,Color_RL, Color_SL ),8 + 2048+styleNoTitle);
Plot(IIf(x>=XP7 & RP7 &NOT P7==0,P7,-1e10),"P7",IIf( SelectedValue(C)<P7,Color_RL, Color_SL ),8 + 2048+styleNoTitle);

breakout_lasttrough_G1 = Cross(T1,C);
breakout_lasttrough_G2 = Cross(T6,C);
breakout_lastpeak_G1 =   Cross(C,P1);
breakout_lastpeak_G2 =   Cross(C,P6);
bu_breakout = Cross(C,P1)  OR  Cross(C,P6);
be_breakout = Cross(T1,C)  OR  Cross(T6,C);
break_G1_val = IIf(breakout_lasttrough_G1,-1,IIf(breakout_lastpeak_G1,1,0));
break_G2_val = IIf(breakout_lasttrough_G2,-1,IIf(breakout_lastpeak_G2,1,0));
MAV_Value1 =ROC(Volume);
C1 = Ref(Close,-1);
O1 = Ref(Open,-1);

Longcandle = abs (C - O)>= 3 * abs (C1 - O1);
Volumecolor = IIf(MAV_Value1 > 3 AND C > O, colorGreen,IIf(MAV_Value1 > 3 AND C < O, colorRed,
IIf(MAV_Value1 > 1.2, colorBlue, IIf(MAV_Value1 > 0.8, colorLightBlue,  colorWhite))));
Plot( 1, "", Volumecolor, styleArea | styleOwnScale | styleNoLabel, -0.1, 25 );
x = (MAV_Value1 > 3 OR MAV_Value1 > 1.2 OR  MAV_Value1 > 0.8) AND MA(V,10)>100000 AND Close>50 ;
bf = Ref(HHV(MAV_Value1, 6), -1) < 1.1;
Buy1 = GapUp() AND bu_breakout AND x AND NOT Longcandle ;
Sell1= GapDown() AND be_breakout AND x AND NOT Longcandle;
Buy =  ((bu_breakout AND x AND NOT Longcandle ) OR Buy1) AND MACD()>Signal() AND C>O AND (C-O) > C*0.0012;
Sell =  ((be_breakout AND x AND NOT Longcandle) OR Sell1) AND MACD()<Signal() AND C<O AND (C-O) > C*0.0012;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Filter = Buy OR  Sell ;// OR Buy1  OR Sell1 ;
AddColumn(Close,"close",1.2);
AddColumn(Volume,"volume");
AddColumn(Buy,"buy");
AddColumn(Sell,"sell");
AddColumn(Buy1,"buy1");
AddColumn(Sell1,"sell1");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                    
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                    
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);


_SECTION_END();

Comments

  1. how to use sir, lot of star, box, etc plse explain

    ReplyDelete

Post a Comment

Popular posts from this blog

How to use Jstock for intraday trading using Google Finance

In this post, I would like to help how to paper trade using jstock stocks scanner. This is an easy , free online software for paper trading NSE and BSE stocks. You can now look for stocks to paper trade, you can get an idea how trading works.
Follow the link to download the software  from this location (http://jstock.org/download.html) , I love to use the windows version and very impressive when it comes to paper trading. I use it to track stocks easily or paper trade daily using this amazing software.  It also comes with an android version, I am not sure of how it works!!  I will review it during some other time. But for now, lets look at the Jstock stock screener or scanner for the PC windows version.
You need have to the latest version of java installed I guess, because it runs on java platform.  After you have installed and started by double clicking. You could different tabs horizontally on the top. Close the country accordingly  depending on your need ( in my case, it is india…

JSTOCK STOCKS SCANNER

JSTOCK is a free stocks scanner, you can scan for 23 countries. Based on different criteria the search can be done.rsi buy and sell,macd buy and sell,uptrend stocks and downtrend stocks,cci buy and sell stocks.It has an Jdraw component installed and you can draw and make your own calculations.


You can do eod calculation search and realtime search ,but realtime search is little delayed due to the yahoo finance server delay.Anyways it is always worth for this application.you can export your calculations into a zip archive and you can use it again.

It includes the new cloud computing feature , you can use it in your home or office. It stores several informations for the application.you can also include your gmail id and receive email alerts or sms alerts to your mobile phone,which no one offers for free.

Check out my favorite stocks scanner code made using Jdraw which is used by many traders to make 10 percent income from stocks. Find the best formula to pick stocks in day trade and in …