// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("camarilla levels");
//---- pivot points
DayH = TimeFrameGetPrice("H", inWeekly, -1);		// yesterdays high
DayL = TimeFrameGetPrice("L", inWeekly, -1);		//				low
DayC = TimeFrameGetPrice("C", inWeekly, -1);		//				close
DayO = TimeFrameGetPrice("O", inWeekly,-1);			// current day open
// camarilla pivots
if ( True )
{
A =  Optimize("X",Param("A",0.17,0.1,1,0.01),0.1,1,0.01);

R = DayH - DayL;	  // range
PP = (DayH + DayL +DayC+DayO)/4;
R1 = PP + (R * A);
S1 = PP - (R * A);
BT=R1+4*(R1-PP);
ST=S1-4*(PP-S1);
}

Plot(R1, "",colorGreen,styleStaircase);
Plot(S1, "",colorRed,styleStaircase);


//----
Title = Name()+" SIMPLE PIVOT & FIBO"+Date()+ EncodeColor(colorRed)+"  Long Breakout above  "+WriteVal(R1,1.2)+"\n"+EncodeColor(colorRed)+"  Short breakout below  "+WriteVal(S1,1.2) 

;


Filter=1;
AddColumn(C,"cmp",1.2);
AddColumn(R1,"R4",1.2);
AddColumn(S1,"S4",1.2);
AddColumn(PP,"UP",1.2);
_SECTION_END();

SetPositionSize( 2000, spsShares ); // 2000 shares by default 
_SECTION_BEGIN("camarilla levels");
//---- pivot points
DayH = TimeFrameGetPrice("H", inDaily, -1);		// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);		//				low
DayC = TimeFrameGetPrice("C", inDaily, -1);		//				close
DayO = TimeFrameGetPrice("O", inDaily,-1);			// current day open
// camarilla pivots
if ( True )
{
A =  Optimize("X",Param("A",0.17,0.1,1,0.01),0.1,1,0.01);

R = DayH - DayL;	  // range
PP = (DayH + DayL +DayC+DayO)/4;
R1 = PP + (R * A);
S1 = PP - (R * A);
BT=R1+4*(R1-PP);
ST=S1-4*(PP-S1);
}

Plot(R1, "",colorWhite,styleStaircase);
Plot(S1, "",colorWhite,styleStaircase);


//----
Title = Name()+" SIMPLE PIVOT & FIBO"+Date()+ EncodeColor(colorRed)+"  Long Breakout above  "+WriteVal(R1,1.2)+"\n"+EncodeColor(colorRed)+"  Short breakout below  "+WriteVal(S1,1.2) 

;


Filter=1;
AddColumn(C,"cmp",1.2);
AddColumn(R1,"R4",1.2);
AddColumn(S1,"S4",1.2);
AddColumn(PP,"UP",1.2);
_SECTION_END();




Buy=Cover=Cross (C, R1);
Sell=Short= Cross (S1 ,C);

_SECTION_BEGIN("Analysis");
M1=EMA(((2*WMA(C,200/2))-WMA(C,200)),2);
M2=EMA(((2*WMA(C,200/2))-WMA(C,200)),5);
Buy     = Cross(M1, M2) ;
Sell    = Cross(M2, M1) ;

Buy     = ExRem(Buy, Sell);
Sell    = ExRem(Sell, Buy);
mycolor = IIf(M1 > M2, colorLime, colorRed);
shape   = Buy * shapeUpArrow + Sell * shapeDownArrow ;


PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
dist = 1.5*ATR(20);
for( i = 0; i < BarCount; i++ ) {
       if( Buy[i] ) PlotText( "Buy\n@" + Close[i], i, Low[i] - dist[i], colorGreen );
       if( Sell[i] ) PlotText( "sell\n@" + Close[i], i, Low[i] + dist[i], colorRed );
	}

Plot( Close, "Close", mycolor, styleNoTitle | styleBar | styleThick   );
_SECTION_END();_SECTION_BEGIN("KPL Swing");
//Copyright Kamalesh Langote. Email:kpl@vfmdirect.com. More details at http://www.vfmdirect.com/kplswing
//Save indicator as "kplswing.afl" in C: program files > Amibroker > Formulas > Custom folder and then drap and drop on price chart
no=Param( "Swing", 20, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase); // or styleaArea

Buy=Cross(C,tsl);
Sell=Cross(tsl,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));

_SECTION_BEGIN("ATP");
Atp=ParamToggle("ATP","Off|On",1);
if(Atp==1)
{
 
 
DayChange = Day() != Ref(Day(), -1);
AvgTradePrice = Null;
CurDayBars = 0;
CurDayCloseSum = 0;
 
for (i = 0; i < BarCount; i++)
{
if (DayChange[i])
{
CurDayCloseSum = C[i];
CurDayBars = 1;
}
else
{
CurDayCloseSum = CurDayCloseSum + C[i];
CurDayBars++;
}
AvgTradePrice[i] = CurDayCloseSum / CurDayBars;
}
Plot(AvgTradePrice, "AvgTradePrice",colorOrange,styleThick);
ATP=AvgTradePrice;
 
_SECTION_END();}

_SECTION_BEGIN( "Stokinghem-Diraj 2652 system" );
/*Stokinghem-Diraj 2652 Intra-Day system*/
"========";



SetChartOptions( 0, chartShowArrows | chartShowDates );

H1 = SelectedValue( TimeFrameGetPrice( "H", inDaily, -1 ) );
L1 = SelectedValue( TimeFrameGetPrice( "L", inDaily, -1 ) );
C1 = SelectedValue( TimeFrameGetPrice( "C", inDaily, -1 ) );
H2 = SelectedValue( TimeFrameGetPrice( "H", inDaily, 0 ) );
L2 = SelectedValue( TimeFrameGetPrice( "L", inDaily, 0 ) );
O1 = SelectedValue( TimeFrameGetPrice( "open", inDaily, 0 ) );
/*PIVOT Calculation*/
D1 = ( H1 - L1 );
D2 = ( H2 - L2 );
F1 = D1 * 0.433;
F2 = D1 * 0.766;
F3 = D1 * 1.35;


F4 = 0;

if ( D2 <= F1 )
    F4 = F1;
else
    if ( D2 <= F2  )
        F4 = F2;
    else
        F4 = F3;



S_P = ( O1 - F4 );

B_P = ( O1 + F4 );

BP = ( L2 + F4 );

BPTGT = ( BP + ( BP * .0065 ) );//.0015 brokerage

BPSTPLS = ( BP - ( BP * .0085 ) );

SP = ( H2 - F4 );

SPTGT = ( SP - ( SP * .0065 ) );

SPSTPLS = ( SP + ( SP * .0085 ) );


p = ( H1 + L1 + C1 ) / 3;

s1 = ( H1 );

r1 = ( L1 );

r2 = SelectedValue( L2 );

s2 = SelectedValue( H2 );

//CONDITION

S = ( C > p );

SS = ( C < P );

//Plot 

Plot ( p  , "PIVOT", 25, 4 );PlotText( "PIVOT" , BarCount-25, p+0, 25 );


Plot ( r1, "PRE_LOW", 29, 4 );PlotText( "PreDay LOW" , BarCount-25, r1+0, 29 );

Plot ( s1, "PRE_HIGH", 29, 4 );PlotText( "PreDay HIGH" , BarCount-25, s1+0, 29 );

Plot ( s2, "DAY_HIGH", 42, 4 );PlotText( "Day HIGH" , BarCount-25, s2+0, 42 );

Plot ( r2, "DAY_LOW", 42, 4 );PlotText( "Day LOW" , BarCount-25, r2+0, 42 );




GfxSetBkColor( colorRed );

GfxSetTextColor( 41 );

GfxSelectFont( "TOHMA", 9, 700, False );



GfxSetBkColor( colorLightGrey );

GfxSetTextColor( 16 );



GfxTextOut("* "+ ( WriteVal( H1 ) + "--" + WriteVal( L1 ) + "=PreDay=" + WriteVal( D1 ) ), 32, 100 );

GfxTextOut("* "+ ( WriteVal( H2 ) + "--" + WriteVal( L2 ) + "=ToDay=" + WriteVal( D2 ) ), 32, 115 );

GfxTextOut( "F1=" + ( WriteVal( F1 ) ), 32, 130 );

GfxTextOut( "F2=" + ( WriteVal( F2 ) ), 32, 145 );

GfxTextOut( "F3=" + ( WriteVal( F3 ) ), 32, 160 );


GfxTextOut( "Selected FC==" + ( WriteVal( F4 ) ), 32, 175 );

GfxTextOut( ( "-P-TGT 0.65 and STP-LS 1.0(Inc-Bkrg)-" ), 32, 190 );








Filter =  S OR SS;

AddColumn( IIf( S, 66, 1 ), "Buy", formatChar, 1, bkcolor = IIf( S, 43, 33 ) );

AddColumn( IIf( SS, 83, 1 ), "Sell", formatChar, 1, bkcolor = IIf( SS, 25, 32 ) );



AddColumn( C, "CMP", 1.2, colorDefault, colorLightBlue );

AddColumn( BP, "BUY PRICE", 1.2, colorDefault, colorGreen );

AddColumn( BPTGT, "TGT PRICE", 1.2, colorDefault, colorBrown );

AddColumn( BPSTPLS, "STPLS BUY", 1.2, colorDefault, colorRed );

AddColumn( p, "PIVOT", 1.2, colorDefault, colorYellow );

AddColumn( SPSTPLS, "STPLS SELL", 1.2, colorDefault, colorRed );

AddColumn( SP, "SELL PRICE", 1.2, colorDefault, colorGreen );

AddColumn( SPTGT, "TGT PRICE", 1.2, colorDefault, colorBrown );


AddColumn( H1, "PRE-HIGH" );

AddColumn( L1, "PRE-LOW" );

AddColumn( D1, "PRE-DIFF" );

AddColumn( F1, "0.433" );

AddColumn( F2, "0.766" );

AddColumn( F3, "1.35" );

AddColumn( H2, "D-HIGH" );

AddColumn( L2, "D-LOW" );

AddColumn( D2, "D-DIFF" );

AddColumn( F4, "SELECT FACT" );


Buy = Cross ( ( C ), ( BP ) );

Sell = Cross ( ( C ), ( SP ) );

AlertIf( Buy, "SOUND C:\\Windows\\Media\\Ding.wav", "2652 System", 1, 2 );

AlertIf( Sell, "SOUND C:\\Windows\\Media\\Chime.wav", "2652 System", 2, 2 );



_SECTION_END();


_SECTION_BEGIN("Show Values at H&L");

n=Param("Values back",20,1,200,1);
p=Param("zig %",5,1,100,1);
dist = 0.8*ATR(15);

for( i = 1; i < n; i++ )
{	
	PlotText(""+LastValue(Peak(H,p,i),True),BarCount-3-LastValue(PeakBars(H,p,i)),LastValue(dist,True)+LastValue(Peak(H,p,i),False),colorBlack,ColorRGB(225,225,225));
	PlotText(""+LastValue(Trough(L,p,i),True),BarCount-3-LastValue(TroughBars(L,p,i)),LastValue(Trough(L,p,i),False)-LastValue(dist,True),colorBlack,ColorRGB(225,225,225));
}