+91-0000000000

}

Monday – Friday : 9:00 AM – 6:30 PM

Modified H & S Pattern

The Modified H & S Pattern AFL in Amibroker is designed to identify variations of the Head and Shoulders pattern. Leveraging amibroker data feed  functionalities enables traders to recognize potential reversal patterns based on modified Head and Shoulders formations. This AFL assists traders in understanding price dynamics and potential trend reversals for effective trade decisions.

/
_SECTION_BEGIN("H&S");
/*for a Short description of Head & Shoulders Pattern you may see at
http://www.chartpattern.com/head_sholuders.html
http://www.chartpatterns.com/headandshoulderschartsstocks.htm
etc.
Paste the formula in Automatic Analysis AND Explore for n last quotations, n=1.
Paste the same formula in Indicator Builder AND select scaling Automatic.
H&S points AND respective neckline is painted yellow, inverted H&S is light blue.
H&S is considered as a bearish formation, confirmed after the neckline breakout.
Inverted H&S is considered as a bullish formation, confirmed after the neckline breakout.
Sensitivity is calibrated at the per=5 line. Increasing per makes the formula less sensitive.
The last shoulder should be less than back=50 days ago AND the distance between shoulders should be less than inter=100 days. 

Formula:*/
x = Cum(1);
per = 15;
back=50;
inter=100;
s11=H;s12=L;

// Volume filter
VFilter = Param( "Volume MA filter", 1000, 50000, 500000, 100000 );
Timeframe = Interval(2);
//Plot(MA(C,3),"MAC",colorYellow);
// Adjust for weekly if necessary
if( Timeframe == "5-day" || Timeframe == "Weekly" ) {
  VFilter  = VFilter * 5;
}
Pfilter = 1;
Vok = MA(V,10)>Vfilter;
Pok = MA(C,10)>pfilter;

/* H & S */
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
medt1=LastValue(ValueWhen( pR, x, 2 ));
startt1=LastValue(ValueWhen( pR, x, 3 ));
dt1=endt1-startt1;
C1=x==endt1 OR x==medt1 OR x==startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
medR=LastValue(ValueWhen( pR, s11, 2 ) );
startR = LastValue( ValueWhen( pR, s11, 3  ));
Filter1=medR>endR AND medR>startR AND abs(startR-endR)<0.02*(startR+endR) AND
dt1LastValue(x)-back AND V[endt1]startt1 AND xmedt1 AND xstartt-5,trendlineS,-1e10);Graph3BarColor=7;Graph3Name = "Bearish H&S";
/*Inverted H & S*/
tpR = TroughBars( s12, per, 1 ) == 0;
tendt1=LastValue(ValueWhen(tpr,x,1));
tmedt1=LastValue(ValueWhen(tpr,x,2));
tstartt1=LastValue(ValueWhen(tpr,x,3));
tdt1=tendt1-tstartt1;
C2=x==tendt1 OR x==tmedt1 OR x==tstartt1;
tendR = LastValue(ValueWhen( tpR, s12, 1 ) );
tmedR=LastValue(ValueWhen( tpR, s12, 2 ) );
tstartR = LastValue( ValueWhen( tpR, s12, 3  ));
Filter2=tmedRLastValue(x)-back AND V[endt1]tstartt1 AND xtmedt1 AND xRstartt-5,trendlineR,-1e10);Graph4BarColor=10;Graph4Name = "Bullish H&S";

Bear = pok AND vok AND Filter1 AND Cross(TrendlineS, C) ;
Bull = pok AND vok AND Filter2 AND Cross(C, TrendlineR);
PlotShapes(Bull*shapeHollowUpArrow,colorBlue, 0, Low, Offset = -12);
PlotShapes(Bear*shapeHollowDownArrow,colorRed, 0, High, Offset = -12);

Filter = Bull OR Bear;
NumColumns=2;
Column0=Filter1;
Column1=Filter2;
Column0Format=Column1Format=1.0;
Column0Name="H&S";
Column1Name="inv H&S";
_SECTION_END();

Open chat
1
Hi, how can I help you?