// Downloaded From https://www.WiseStockTrader.com

_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);			// current day open

// camarilla pivots
if ( True )
{
R = DayH - DayL;	  // range
PP = (DayH + DayL + DayO + DayO) / 4 ;
R4 = (R * 1.1/2)+DayC;
R3 = (R * 1.1/4)+DayC;
S3 = DayC-(R * 1.1/4);
S4 = DayC- (R * 1.1/2);
}

Plot(R4, "",colorGreen,styleLine);
Plot(S4, "",colorDarkBlue,styleLine);
Plot(R3, "R3",colorRed,styleLine);
Plot(S3, "S3",colorDarkBlue,styleLine);
Plot(PP, "",colorYellow,styleLine);


//----
Title = Name()+" Camarilla"+Date()+ EncodeColor(colorRed)+ "   R3  "+WriteVal(R3,1.2)+EncodeColor(colorGreen)+  "  S3  "+ WriteVal(S3,1.2)+"\n"+EncodeColor(colorGreen)+"  Long Breakout above  "+WriteVal(R4,1.2)+"\n"+EncodeColor(colorRed)+"  Short breakout below  "+WriteVal(S4,1.2) 
+"\n"+EncodeColor(colorGreen)+" If Rangebound buy close to  "+ WriteVal(S3,1.2)+
"\n"+EncodeColor(colorRed)+" If Rangebound short close to  "+ WriteVal(R3,1.2);


Filter=1;
AddColumn(C,"cmp",1.2);
AddColumn(R3,"R3",1.2);
AddColumn(R4,"R4",1.2);
AddColumn(S3,"S3",1.2);
AddColumn(S4,"S4",1.2);
_SECTION_END();_SECTION_BEGIN("Kpl System");
/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 Day EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote. Email:kpl@...
no=Param( "Swing", 20, 1,150 );
tsl_col=ParamColor( "Color", colorRed );

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);
Buy=Cover=Cross(C,tsl) ;
Sell=Short=Cross(tsl,C) ;

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,Low,-15);  
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorYellow, 0,High,-15);  
PlotShapes(IIf(Cover, shapeHollowCircle, shapeNone),colorWhite, 0,Close,0);  
PlotShapes(IIf(Short, shapeHollowCircle, shapeNone),colorYellow, 0,Close,0); 



SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);
//-----------end--------------
Long=Flip(Buy,Sell); 
Shrt=Flip(Sell,Buy); 

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);


Edc=(
WriteIf (Buy AND Ref(shrt,-1), " BUY@ "+C+"  ","")+ 
WriteIf (Sell AND Ref(Long,-1), " SEll@ "+C+"  ","")+
WriteIf(Sell , "Last Trade Profit Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Last Trade Profit Rs."+(SellPrice-C)+"",""));
_SECTION_END();

//============== TITLE ==============
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator ) 
(
Title = EncodeColor(colorGold)+ "arihant Trading System" + EncodeColor(colorRose)+" (" +  Name() + ") " + EncodeColor(colorGold)+ Interval(2) + 
 "  " + Date() +" " +" •  Open "+WriteVal(O,1.2)+"  •  "+"Hi "+WriteVal(H,1.2)+"  •  "+"Lo "+WriteVal(L,1.2)+"  •  "+
"Close "+WriteVal(C,1.2)+" ("+WriteVal(C-Ref(C,-1),1,0)+" "+WriteVal((C-Ref(C,-1))*100/Ref(C,-1),1.1)+ "%)  •  Vol= "+ WriteVal(V,1.0)
 


+"\n"+EncodeColor(colorGrey50)+"------------------------------------------------------------------------------------------------------------"

+"\n"+EncodeColor(colorGold)+
WriteIf (Buy , "Signal: Go Long - Entry Price: "+WriteVal(C)+" - Traget: "+WriteVal((BuyPrice-tsl)+BuyPrice)
+" - StopLoss:"+WriteVal(tsl)+"  "
,"")+


WriteIf (Sell , "Signal: Go Short - Entry Price: "+WriteVal(C)+" - Target: "+WriteVal((tsl-SellPrice)-SellPrice)+" - StopLoss:"+WriteVal(tsl)+" ","")+
EncodeColor(ColorRGB(111,208,255))+
WriteIf(Long AND NOT Buy, "Trade: Long - Entry Price: "+WriteVal((BuyPrice))+" - Profit: "+WriteVal((C-BuyPrice))+" "+EncodeColor(colorLime)+"Let your profit runs!","")+
WriteIf(shrt AND NOT Sell, "Trade: Short - Entry Price: "+WriteVal((SellPrice))+" - Profit: "+WriteVal((SellPrice-C))+"  - "+EncodeColor(colorLime)+"Let your profit runs!","")

+"\n"+EncodeColor(colorGrey50)+"------------------------------------------------------------------------------------------------------------"
);

dist = 3*ATR(15);
dist1 = 3*ATR(15);
for( i = 0; i < BarCount; i++ ) 
{ 
 if( Buy[i] ) 
 {
  PlotText( "\nBuy:" + C[ i ] + "\nT= " + ((C[i]-tsl[i])+C[i]) + "\nSL= " + tsl[i], i, C[ i ]-dist[i], colorBlue, colorGreen );
 }
 if( Sell[i] )
 {
  PlotText( "Sell:" + C[ i ] + "\nT= " + (C[i]-(tsl[i]-C[i])) + "\nSL= " + tsl[i], i, C[ i ]+dist1[i], colorRed, colorGreen ); 
 }
}

/*Plot Ribbon */
Ribbon1=IIf(  (C) >(tsl)  ,colorWhite, IIf(( tsl )>( C ), colorOrange,colorYellow));
Plot(3, "Ribbon", Ribbon1, styleOwnScale| styleArea| styleNoLabel,-0.5,100);

_SECTION_END();


                            
_SECTION_BEGIN("");

P1 = Param( "MA01 Period", 5, 2, 200 );
P2 = Param( "MA02 Period", 10, 2, 200 );

MA01=MA(C,P1 );
MA02=MA(C,P2 );

RG=IIf(MA01>MA02,MA01-MA02,-(MA02-MA01));

PlotOHLC( MA02,RG+MA02,MA02,RG+MA02,"",23, styleCandle+4096); 
Plot( SelectedValue(C), "",IIf(SelectedValue(MA01)>SelectedValue(MA02),4,34),styleNoLine);


Title = EncodeColor(44)+Name() +"    ( "+Interval(2)+" )    "+EncodeColor(41 )+WriteVal( DateTime(), formatDateTime);

_SECTION_END();