// Downloaded From https://www.WiseStockTrader.com
// Renko  Chart
// Graham Kavanagh  13 Aug 2004 ver C - MODIFIED BY m.p.patil
// Custom Indicator, date axis does not apply


 SetBarsRequired(10000,10000);

// Brick size is dependant on what you want, if too small will not produce a chart due to insufficient x-axis bars
//Brick = LastValue( ATR(100) );
//Brick = LastValue( Max(0.02*C, 0.05) );
Brick = Param( "Brick Size", 4, 0.01, 1.00, 0.01 );
reverse = 1;

// Convert the closing price to rising and falling rounded bricks
CF = ceil(H/Brick);
CR = floor(L/Brick);

// initialize first element
j = 0;
RKC[j] = CF[0];
RKO[j] = CF[0] + 1;

down[j] = 1;  // By default the first bar is a down bar.
up[j] = 0;

// Loop to produce the Renko values in number of bricks

for( i=1; i<BarCount-1; i++ )
{
if( CF[i] <= RKC[j] - 1 && down[j] ) // Continue down
	{
		num = RKC[j] - CF[i];
		for( x=1; x<=num; x++ )
		{
			j++;
			up[j] = 0;
			down[j] = 1;
			RKC[j] = RKC[j-1] - 1;
			RKO[j] = RKC[j] + 1;
		}
	}
	else
	{
		if( CR[i] >= RKC[j] + Reverse && down[j] )  // Change down to up
		{
			num = CR[i] - RKC[j];
			j++;
			up[j] = 1;
			down[j] = 0;
			RKC[j] = RKC[j-1] + 2;
			RKO[j] = RKC[j] - 1;			
			for( x=2; x<=num; x++ )
			{
				j++;
				up[j] = 1;
				down[j] = 0;
				RKC[j] = RKC[j-1] + 1;
				RKO[j] = RKC[j] - 1;
			}
		}
		else
		{
			if( CR[i] >= RKC[j] + 1 && up[j] ) // Continue Up
			{
				num = CR[i] - RKC[j];
				for( x=1; x<=num; x++ )
				{
					j++;
					Up[j] = 1;
					Down[j] = 0;
					RKC[j] = RKC[j-1] + 1;
					RKO[j] = RKC[j] - 1;
				}
		 	}
		 	else
		 	{
			 	if( CF[i] <= RKC[j] - Reverse && up[j] )  // Change up to down
			 	{
				 	num = RKC[j] - CF[i];
				 	j++;
					Up[j] = 0;
				 	Down[j] = 1;
				 	RKC[j] = RKC[j-1] - 2;
				 	RKO[j] = RKC[j] + 1;
				 	for( x=2; x<=num; x++ )
				 	{
					 	j++;
					 	up[j] = 0;
				 		down[j] = 1;
				 	 	RKC[j] = RKC[j-1] - 1;
				 	 	RKO[j] = RKC[j] + 1;
					}
				}
			}
		}
	}
}


// move the chart to right end of chart space, ie last brick on last bar position
delta =  BarCount-1 - j;

RKC = Ref( RKC, -delta );
RKO = Ref( RKO, -delta );

Up = Ref( Up, -delta );
Down = Ref( Down, -delta );

/*
rC = RKC * Brick;// + (Up-down)*Brick/2;
rO = RC - (Up-down)*Brick;
rH = Max(rC,rO);
rL = Min(rC,rO);
*/


C = RKC * Brick;// + (Up-down)*Brick/2;
O = C - (Up-down)*Brick;
H = Max(C,O);
L = Min(C,O);

Plot( C, "", colorCustom9,styleCandle); 
// plot chart
//plotOHLC( rO, rH, rL, rC, "Renko Price " , colorBlack, styleCandle);

Buy=Up;
PlotShapes(shapeUpArrow*Buy,colorGreen, 0, L );
Sell=Down;
PlotShapes(shapeDownArrow*Sell,colorRed, 0, H );



GraphXSpace=5;







_SECTION_BEGIN("EMA1 EMA 5");

x = EMA(C,1);
y = EMA(C,5);

Buy=Cross(x,y);
PlotShapes(shapeUpArrow*Buy,colorAqua, 0, L );
Sell=Cross(y,x);
PlotShapes(shapeDownArrow*Sell,colorBlue, 0, H );
Plot(EMA(C,1),"",colorCustom9,styleLine);
//Plot(EMA(C,5),"",colorRed,styleLine);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );
XR=(EMA(C,1) * (1 / 1 - 1) - EMA(C,5) * (1 / 5 - 1)) / (1 / 1 - 2 / 5);

//Indicators


_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 1, 1, 100, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCustom9 ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 5, 1, 100, 1 );
//Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorRed ), ParamStyle("Style") ); 
_SECTION_END();

///////////displaced moving average////////////////////////
x1=MA(C,3);
x2=Ref(C,1);
Plot(x2,"3 displaced 3 MA ",0,5);

Buy=Cross(x2,x1);
PlotShapes(shapeUpTriangle*Buy,colorCustom9, 0, L );
Sell=Cross(x1,x2);
PlotShapes(shapeDownTriangle*Sell,colorCustom12, 0, H );
//Plot(MA(C,3),"",colorRed,styleLine);
Plot(Ref(C,1),"",colorRed,styleLine);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );
_SECTION_END();


/****************************************

Name			:	Logic All In One for Intraday 
Date			:	10th JAN 2009
Author        :	mohan 
E-Mail ID     :  mohanpatil.72@gmail.com

*****************************************/



EnableTextOutput(False);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Title_X	=	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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack), ParamColor("Title", colorDarkTeal));
SetChartBkColor(ParamColor("Background", colorBlack));
_SECTION_END();

//Indicators

_SECTION_BEGIN("Indicators");
RSI_Periods		=	Param("RSI Periods", 5, 1, 100, 1);
MA_Periods		=	Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds	=	Param("Periods for Trend EMA", 6, 1, 100, 1);
_SECTION_END();

SetBarsRequired(100000, 100000);

// Find nearest UP and DOWN bar before current bar
Up_Day	=	Close > Open;
Down_Day	=	Close < Open;
Reference_Low	=	ValueWhen(Up_Day, L, 1);
Reference_High	=	ValueWhen(Down_Day, H, 1);
Buy_Condition	=	C > O AND C > Reference_High;
Sell_Condition	=	C < O AND C < Reference_Low;
a= Buy_Condition;
b= Sell_Condition;
state=IIf(BarsSince(a)<BarsSince(b),1,0);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
sss=state==Ref(state,-1);
col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Buy_Views =	WriteIf(s,"EXIT ALL SHORT POSITIONS\n AND TRADE LONG WITH STOPLOSS="+EncodeColor(colorLime)+WriteVal(L,1.2)+",",""); 
Sell_Views =	WriteIf(ss,"EXIT ALL LONG POSITIONS \n AND TRADE SHORT WITH STOPLOSS="+EncodeColor(colorRed)+WriteVal(H,1.2)+",","");


// RSI and Vol ratio calculation
RSI_Value		=	RSI(RSI_Periods);
MAV_Value	=	V/EMA(V, MA_Periods);

//Percentage change

s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
Percentage= t;

//Percentage Change in Volume 

w = V -Ref(V,-1);
x = (w/Ref(V,-1))*100;
Volume_Ratio = x;
//Volume_Ratio = V/EMA(V,50);
//Conditions

Condition1 = Percentage > 0.5 AND Volume_Ratio > 1.5;
Condition2 = Percentage > 1 AND Volume_Ratio < -1.5;
Condition3 = Percentage < 0 AND Volume_Ratio > -1.5;
Condition4 = Percentage < 1 AND Volume_Ratio < 1.5;
Condition5 = IIf(NOT Condition1 AND NOT Condition2 AND  NOT Condition3 AND  NOT Condition4, True,False);


Fresh_Buying = WriteIf(Condition1,"Fresh Buying", "");
Short_Covering = WriteIf(Condition2,"Short Covering", "");
Fresh_Short_Building = WriteIf(Condition3,"Fresh Short Building", "");
Possible_Bottom = WriteIf(Condition4,"Possible Bottom or Top", "");
No_Major_Move = WriteIf(Condition5, "No_Major_Move","");

//interpretation output

EnableTextOutput(True);
"\nSell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2);
"Buy Above : " + WriteVal(Reference_High, 1.2);
"";
"Current RSI Value: " + WriteVal(RSI_Value, 1.2);
"Current Vol. Ratio: " + WriteVal(MAV_Value, 1.2);
"";
"Fresh Buying: " + WriteIf(Condition1,"Fresh Buying","");

EnableTextOutput(False);

Filter = Buy_Condition OR Sell_Condition;

// Trading System
PositionSize = BuyPrice * 1;
Buy 	= Buy_condition;
Sell 	= Sell_condition;
Buy 	= ExRem( Buy, Sell );
Sell 	= ExRem( Sell, Buy );

// Experimental Code BEGIN
Is_Last_Bar	=	BarIndex()+1	== BarCount;
printf("Last Bar: %g\n", Is_Last_Bar);
Buy_Alert	=	Buy AND Is_Last_Bar;
Sell_Alert	=	Sell AND Is_Last_Bar;
Buy_Alert_Text	=	WriteIf(Buy_Alert, "BUY WARNING!!!", "");
Sell_Alert_Text	=	WriteIf(Sell_Alert, "SELL WARNING!!!", "");
Buy_Alert_Text1	=	WriteIf(Buy_Alert, "BUY", "");
Sell_Alert_Text1	=	WriteIf(Sell_Alert, "SELL", "");
LastbarsignalCol		=	IIf(Buy_Alert, colorGreen, IIf(Sell_Alert, colorRed, colorLightGrey));


//Buy & Sell Arrows Signal
PlotShapes(shapeCircle  * Buy_Alert, colorLime, 0, L, -50);
PlotShapes(shapeCircle * Sell_Alert, colorRed, 0, H, -50);
//PlotShapes(shapeUpTriangle * Buy * (NOT Is_Last_Bar), colorLime, 0, L, -50);
//PlotShapes(shapeDownTriangle * Sell * (NOT Is_Last_Bar), colorRed, 0, H, -50);

//Alerts Singal for Buy & Sell
AlertIf(Buy, "SOUND C:\\Windows\\Media\\Ding.wav",  "Buy Triggered!", 1, 8);
AlertIf(Sell, "SOUND C:\\Windows\\Media\\Ding.wav",  "Sell Triggered!", 2, 8);

// Check if previous day's close is above its 6-day EMA
DailyClose 	=  	TimeFrameCompress(Close, inDaily);
DailyEMA 		= 	EMA( DailyClose, Daily_Trend_MA_Pds); 
DailyClose		=	TimeFrameExpand(DailyClose, inDaily, expandFirst);
DailyEma		=	TimeFrameExpand(DailyEMA, inDaily, expandFirst);

// Trend detection based on 6EMA for Daily 
Daily_Trend_UP				=	DailyClose > DailyEMA;
Daily_Trend_DOWN			=	DailyClose < DailyEMA;
Trend_UP_Text		=	WriteIf(Daily_Trend_UP, "Daily Trend UP", "");
Trend_DOWN_Text	=	WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");
Trend_Neutral_Text	=	WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend_UP, "Neutral", "");
TrendCol		=	IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_DOWN, colorRed, colorLightGrey));


/** Debug BEGIN  */
printf("\nDaily Close: %g ", DailyClose);
printf("\nDaily Trend: %g", (DailyEMA));
/*      Debug END ****/

//Inerpretation 
Title	=	Title_X + "\n"  +

			EncodeColor(colorBlack) + "RSI(" + WriteVal(RSI_Periods, 1)  + "):  " +
			EncodeColor(colorBrightGreen) + WriteVal(RSI_Value, 1.2) + "\n" + 
			EncodeColor(colorBlack) + "Vol. Ratio: " + EncodeColor(colorDarkGreen) + WriteVal(MAV_Value, 1.2) + "\n" +
			EncodeColor(colorRed) + Trend_Down_Text + EncodeColor(colorLime) + Trend_Up_Text +
			EncodeColor(colorWhite) + Trend_Neutral_Text +  "\n" + 
          EncodeColor(colorRed) + Sell_Alert_Text + EncodeColor(colorLime) + Buy_Alert_Text + "\n" +
          EncodeColor(colorRed) + Fresh_Short_Building + EncodeColor(colorLime) + Fresh_Buying + EncodeColor(colorWhite) + Short_Covering + EncodeColor(colorWhite) + Possible_Bottom +"\n" +
          EncodeColor(colorBrightGreen)+ "Buy Above : " + WriteVal(Reference_High, 1.2)+ "\n" +
          EncodeColor(colorCustom5) + "Sell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2) + "\n" +
          EncodeColor(colorCustom12) + "Trend value: " + WriteVal(DailyEMA,1) +"\n"+
          EncodeColor(colorBlue)+ Buy_Views + EncodeColor(colorBlue)+ Sell_Views;
          

//M Ramu Povit Point

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
Dayz = TimeFrameGetPrice("C", inDaily, -6);		//		six days close
if ( True )
{
PP = (Dayc + Dayc -6 )/2;
R1  =  Dayc + (DayH - DayL)/2;
S1  =  Dayc - (DayH - DayL)/2;
R2  =  Dayc + (DayH - DayL);
S2  =  Dayc - (DayH - DayL);
}
Plot(pp, "PP",colorYellow,styleDots+styleNoLine);
Plot(R1, "R1",colorBlue,styleDots+styleNoLine);
Plot(S1, "S1",colorRed,styleDots+styleNoLine);
Plot(R2, "R2",colorBlue,styleDots+styleNoLine);
Plot(S2, "S2",colorRed,styleDots+styleNoLine);


//Average, Volitility & Percentage Scale.
av3=V/EMA(V,50);
V1= MA(V,50);
r = RSI(5); 
s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
p=H-L;
q=(p/Ref(C,-1))*100;

//Explore Options

Filter = 1; /* all symbols and quotes accepted */
//filer = Buy OR Sell ;
AddColumn(Open,"OPEN",1);
AddColumn(High,"HIGH",1);
AddColumn(Low,"LOW",1);
AddColumn(Close,"CLOSE",1); 
AddColumn(t,"Per",1.2);
AddColumn(V,"VOLUME",1);
AddColumn(V1,"AGV VOLUME",1);
AddColumn(av3,"RATIO50",1.2);
AddColumn(r,"RSI",1);
AddTextColumn(WriteVal(Reference_High, 1.2),"BUY ABOVE",colorWhite,colorGreen);
AddTextColumn(WriteVal(ValueWhen(Up_Day, L, 1), 1.2),"SELL BELOW",colorWhite,colorRed); 
AddTextColumn(Trend_Down_Text + Trend_Up_Text,"DAILY TREND",1,colorWhite,TrendCol); 
AddTextColumn(Buy_Alert_Text + Sell_Alert_Text,"LAST BAR SIGNAL",1,colorWhite,Lastbarsignalcol); 

//Moveing Average 5EMA
P = ParamField("High",-1);
Periods = Param("High", 5, 2, 200, 1, 10 );
//Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style") );

Title = Name() + " - {{INTERVAL}} {{DATE}} - NIFTY INTRADAY -(INDIA)  - TIME/DATE AXIS NOT RECOMENDED - ACT ON 3 RD GREEN/RED BOX REVERSAL : Last Value = " + RKC * Brick ;



// Plot Buy Values on the Chart

//for( i = 0; i < BarCount; i++ ) 
//{ 
//if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ], colorBlue); 
//if( Sell[i] ) PlotText( "Sell\n@" + C[ i ], i, H[ i ], colorYellow); 
//}