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. It's very interesting, Thanks for sharing a valuable information to us & Knowledgeable also, keep on sharing like this.

    Stock Investor provides leatest Indian stock market news and Live BSE/NSE Sensex & Nifty updates.Find the relevant updates regarding Buy & Sell....

    ShareTrading

    Demat Account

    Equity Trading

    Stock Trading

    ReplyDelete
  2. Great Information! Its looking Nice.....

    You can invest in stocks yourself by buying individual Stocks & Shares or mutual funds,IPOs, or get help investing in stocks by Visit stockinvestor.in
    phillips carbon share price
    shakti pumps share price
    ramco industries
    mahindra amc
    bajaj electricals share price
    kolte patil developers ltd
    sbi insurance
    bsesensex

    ReplyDelete

Post a Comment

Popular posts from this blog

Learn about crypto trading

crypto trading is super easy and when you know the tricks of trade, you keep on making profits. I was clueless about crypto currency trading initially and I found a course on udemy which gives you the exact blueprint for success. Most people think that crypto trading is too tough but if you focus on the basics and put extra effort, everything becomes easy Basics+ Extra effort = success initially I would keep on making losses and roam without a strategy but things are a bit easier. My focus is to make $30 each day from crypto and that's all I need. I am planning to make it $100 in the future, crypto trading is like golden goose and it keeps on laying eggs. most people want to buy 1 bitcoin and get rich overnight which never happens. Be systematic and focus on making $100 and call it a day. To become a doctor, you spend 5 years and a lot of money for your education. But for crypto trading,you want to become one overnight. If you want to learn about technical analy...

Why afternoon trade is profitable?

Trading is risky but not bad to take it as profession full time. There are people who are crypto currency traders who are glued to the screen all the time.   Time and volume can’t be ignored because it when mastered rightly would change the life of an ordinary trader to a super-rich guy within few months. Stock trading is not a casino machine but if you have a strategy in place, you keep getting the positive results. Afternoon trades are like the ending scene of the movies. After the interval block, the audience are curious about the end of the movie. You know the characters well and you can predict the trend of the movie. Why don’t you apply the same with the stocks? There are many ideas on how to pretend the trend and one of the simple key factor is the EMA. A simple 10 day EMA on 5 minute charts would give the clue. If you have time, then check out the courses that would help you learn the basics of trading. You shouldn’t try trading with a stop-loss and that’s the bo...