// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("Sound-script");
Length=Param("Length",25, 2); 
Deviation=Param("Deviation",2);
MoneyRisk=Param("Money Risk", 1);
LineStyle=ParamToggle("Display line mode", "No|Yes", 0); 
cUpTrendLine = ParamColor("UpTrendLine", colorGold);
cDnTrendLine = ParamColor("DownTrendLine", colorGold);

TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);

procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
{
global UpTrendLine;
global DownTrendLine;
global smax;
global smin;

	UpTrendLine=Null;
	DownTrendLine=Null;
	smax=Null;
	smin=Null;
	trend=0;


	for (i=Length+1; i<BarCount; i++)	
  { 
		smax[i]=bbtop[i];
		smin[i]=bbbot[i];
		if (C[i]>smax[i-1]) trend=1;
		if (C[i]<smin[i-1]) trend=-1;
		if(trend>0 && smin[i]<smin[i-1]) smin[i]=smin[i-1];
		if(trend<0 && smax[i]>smax[i-1]) smax[i]=smax[i-1];
		bsmax[i]=smax[i]+0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
		bsmin[i]=smin[i]-0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
		if(trend>0 && bsmin[i]<bsmin[i-1]) bsmin[i]=bsmin[i-1];
		if(trend<0 && bsmax[i]>bsmax[i-1]) bsmax[i]=bsmax[i-1];
		if (trend>0) 
		{ 
			UpTrendLine[i]=bsmin[i];
			if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1])) 
			{ 
				Say("hi i am Kumaran Attention please, Market Going, UP");
				PopupWindow(Date()+ "\n  > " +  Name() + "\n  > Buy : " + h[ i ] + "\n  > Target : " +(L[i]*1.005) +"\n  > Stop Loss : " + (L[i]*0.9975),"Alert", 100, 640*mtRandom(), 480*mtRandom());				TurnedUp=StaticVarSet("TurnedUp",1);
				TurnedDown=StaticVarSet("TurnedDown",0);

			} 
		} 
	
   	if (trend<0) 
		{ 
			DownTrendLine[i]=bsmax[i];
			if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1])) 
			{
				Say("Attention please, Market Going, DOWN");
				PopupWindow( Date()+ "\n  > " + Name() + "\n  > Sell : " + L[i] + "\n  > Target : " + (H[i]*0.995)+"\n  > Stop Loss : " +(H[i]*1.0025),"Alert", 100, 640*mtRandom(), 480*mtRandom());
				TurnedUp=StaticVarSet("TurnedUp",0);
				TurnedDown=StaticVarSet("TurnedDown",1);
			} 
		} 
	} 
} 
	bbtop=BBandTop(C,Length,Deviation);
	bbbot=BBandBot(C,Length,Deviation);

	CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
	UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
	DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));
	
mycolor = IIf( TurnedUp>TurnedDown , colorLime, colorRed);



dist = 2.8*ATR(10);
dist1 = 2*ATR(10);
for( i = 0; i < BarCount; i++ ) 
{ 
 if( UpTrendSignal[i] ) 
 {
  PlotText( "\nBuy:" + H[ i ] , i, H[ i ]-dist[i], colorGreen, colorWhite );
 }
 if( DownTrendSignal[i] )
 {
  PlotText( "Sell:" + L[ i ] , i, l[ i ]+dist1[i], colorRed, colorWhite ); 
 }
}


  DisplayStyle = styleNoLabel|styleLine|styleNoTitle;
  if(LineStyle == 0) DisplayStyle |= styleLine; 


	Plot(UpTrendLine,"Buy Stop Loss",cUpTrendLine,DisplayStyle);
	Plot(DownTrendLine,"Sell Stop Loss",cDnTrendLine,DisplayStyle) ;

	PlotShapes(IIf(UpTrendSignal,shapeSquare,shapeNone),colorLime,0,bbbot,Offset=-1);
	PlotShapes(IIf(UpTrendSignal,shapeUpArrow,shapeNone),colorWhite,0,bbbot,Offset=-1);


	PlotShapes(IIf(DownTrendSignal,shapeSquare,shapeNone),colorOrange,0,bbtop,Offset=-1);
	PlotShapes(IIf(DownTrendSignal,shapeDownArrow,shapeNone),colorWhite,0,bbtop,Offset=-1);










_SECTION_END();


Plot( C, "Close", mycolor, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
_SECTION_BEGIN("Background text");
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "WayToWin", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
_SECTION_END();



_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();