Simple Coding Help - No Promise.

sr114

Well-Known Member
2nd, Ask yourself, below code repeat 100 times, which are not using the looping variable i, is this necessary ?
repeat 1 time and repeat 100 times are the result the same ?
if the same why not move out ?


Code:
for(i=0;i<100;i++)
{
[B][I][COLOR="Red"]d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
f = s0*nd1-E*exp(-r*t)*nd2-C;
//#Derivative of d1 w.r.t. sigma:
d11 = (sigma^2*t*sqrt(t)-(log(s0/E)+(r+sigma^2/2)*t)*sqrt(t))/(sigma^2*t);
//#Derivative of d2 w.r.t. sigma:
d22 = d11-sqrt(t);
//#Derivative of f(sigma):
f1 = s0*nd1*d11-E*exp(-r*t)*nd2*d22;
//#Update sigma:
sigma = sigma - f/f1;
sig = sigma;[/COLOR][/I][/B]
}
the looping variable i is used for increment or decrement of the value of sigma.

the calculation part of d1 to fi is dependent on the value of sigma - so they cant be put out of the loop.

only problem is the condition checking if statement and may be the loop execution can be stopped by using a break statement

rgds
 

sr114

Well-Known Member
Hi Kelvin,
Don't know much about AFL. but sigma value is updating from it's previous value in each iteration inside the for loop. Don't know the significance of why loop is iterating 100 times.

sigma = sigma - f/f1;
actually the loop can be used for may be 10 or 15 times but 100 is used to get the proper sigma value.

actually the loop will stop executing may be after 8th or 10th execution

rgds
 

josh1

Well-Known Member
This AFL gives me Previous Day OHLC and also Day Hi Lo for different time intervals. However, It becomes very slow when I move the chart backwards. Can it be made faster any way? I am more concerned for Previous day Hi Lo.

Code:
_SECTION_BEGIN("PreDHLCDayHLRN");
PreDHLC = ParamToggle("Show PreDHLC","Show|Hide",1);

if (PreDHLC == 1) { 

LV_Datenum=LastVisibleValue(DateNum());						//Calculate Date Number of Last Visible Bar
//Hor0 = Param("Hor0",900,0,1368,1);
//Ver0 = Param("Ver0",30,0,768,1);

CurrentDayBars=BarsSince(DateNum()<LV_Datenum);				//Calculate number of bars for last visible day
PDay_Datenum=Ref(DateNum(),-CurrentDayBars);					//Calculate Date number of previous day
P2Day_Datenum=BarsSince(DateNum()<LastValue(PDay_Datenum));//Calculate Date number of day before previous day
z=P2Day_Datenum-CurrentDayBars;

// Calculation of Last Visible Day High
// Day High = Higher of Highest Open or Highest Close during the day
Hi0=IIf(HHV(C,CurrentDayBars)> HHV(O,CurrentDayBars),HHV(C,CurrentDayBars),HHV(O,CurrentDayBars));
//Hi0bar=HHVBars(Hi0,CurrentDayBars);

x20=BarCount-LastValue(CurrentDayBars)-5;
x21=BarCount-1;
y20=LastVisibleValue(Hi0);
y21=y20;
Line2 = LineArray( x20, y20, x21, y21,1 );
Plot( Line2, "day high line", TDClrs,styleThick|styleNoTitle|styleNoLabel,0,0,5);
  	PlotText("DH " + y21, LastValue(BarIndex())+6, y21, TDClrs);

//Calculation of Last Visible Day Day Low
//Li0=LLV(L,CurrentDayBars);
//Day Low = Lower of Lowest Open or Lowest Close during the day
Li0=IIf(LLV(C,CurrentDayBars)< LLV(O,CurrentDayBars),LLV(C,CurrentDayBars),LLV(O,CurrentDayBars));
Li0bar=LLVBars(Li0,CurrentDayBars);

x30=BarCount-LastValue(CurrentDayBars)-4;
//x31=BarCount-1;
y30=LastVisibleValue(Li0);
y31=y30;
Line3 = LineArray( x30, y30, x21, y31, 1 );
Plot( Line3, "day low line", TDClrs,styleThick|styleNoTitle|styleNoLabel,0,0,5 );
  	PlotText("DL " + y31, LastValue(BarIndex())+6, y31, TDClrs);

//Calculation of Day Open
//Day Open = Open of Fis
dao=Ref(Open,-CurrentDayBars+1);
x101=BarCount-1-LastValue(CurrentDayBars-1);
y101=LastValue(dao);
y111=y101;
Line1=LineArray( x101, y101, x21, y111, 1 );
Plot( Line1, "DO Line", ParamColor("Open line", colorWhite),styleThick|styleNoTitle|styleNoLabel ,0,0,0);
  	PlotText("DO " + y101, LastValue(BarIndex())-20, y111, TDCLRs);


//Calculation of Previous Day High
//Hi=Ref(HHV(H,z),-CurrentDayBars);
Hi=IIf(Ref(HHV(C,z),-CurrentDayBars) > Ref(HHV(O,z),-CurrentDayBars), Ref(HHV(C,z),-CurrentDayBars), Ref(HHV(O,z),-CurrentDayBars));

Hibar=Ref(HHVBars(Hi,z),-CurrentDayBars)+CurrentDayBars;
x0=BarCount-1-LastValue(Hibar)-4;
//x1=BarCount-1;
y0=LastValue(Hi);
y1=y0;
Line = LineArray( x0, y0, x21, y1, 1 );
Plot( Line, "high line", ParamColor("PDH", PDHClr),styleThick|styleNoTitle|styleNoLabel,0,0,5 );
  	PlotText("PDH " + y0, LastValue(BarIndex())+4, y1, PDHClr);

//Calculation of Previous Day LOW
//Lo=Ref(LLV(L,z),-CurrentDayBars);
Lo=IIf(Ref(LLV(C,z),-CurrentDayBars) < Ref(LLV(O,z),-CurrentDayBars), Ref(LLV(C,z),-CurrentDayBars), Ref(LLV(O,z),-CurrentDayBars));
Lobar=Ref(LLVBars(Lo,z),-CurrentDayBars)+CurrentDayBars;

x00=BarCount-1-LastValue(Lobar)-5;
x01=BarCount-1;
//x01=Status("lastvisiblebar")+10;

y00=LastValue(Lo);
y01=y00;

Line11=LineArray(x00,y00,x01,y01,1);
Plot(Line11,"Low Line", PDLCLr,styleThick|styleNoTitle|styleNoLabel,0,0,5);
//Plot(Line11,"Low Line",ParamColor("PDL", PDLCLr),styleThick|styleNoTitle|styleNoLabel,0,0,5);
  	PlotText("PDL " + y01, LastValue(BarIndex())+4, y01, PDLClr);


//Calculation of Previous Day Close
pc=Ref(Close,-CurrentDayBars);

x10=BarCount-1-LastValue(CurrentDayBars)-5;
x11=BarCount-1;
y10=LastValue(pc);
y11=y10;

Line1=LineArray( x10, y10, x11, y11, 1 );
Plot( Line1, "Close line", ParamColor("Close line", colorWhite),styleThick|styleNoTitle|styleNoLabel ,0,0,5);
  	PlotText("PDC " + y11, LastValue(BarIndex())-26, y11, PDCClr);

}

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
 
Last edited:
Dear Sir
Please help me to generate signal;

Buy= when candle stop Above 40 days EMA high
Buy Exit= When candle stop Below 40 days EMA Low

and Sell= vise versa, Next Candle stop

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = 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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );// 40 days High Green Line
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


_SECTION_BEGIN("EMA-2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );// 40 days Low Red Line
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


//MOMIN//////////////////
_SECTION_BEGIN("Magfied Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",1480,1,1800,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor-690 , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor-690 , Ver+45 );
_SECTION_END();
 

sr114

Well-Known Member
This AFL gives me Previous Day OHLC and also Day Hi Lo for different time intervals. However, It becomes very slow when I move the chart backwards. Can it be made faster any way? I am more concerned for Previous day Hi Lo.
Dnld the plugin from the link and put it in the plugin folder.

http://www.amibroker.org/3rdparty/deDateTime.zip

afl is faster
Code:
 _SECTION_BEGIN("Background_Setting");
 SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
 ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorBlack)); 
 SetChartBkColor(ParamColor("Outer Panel",colorBlack));
 SetChartOptions(0,chartShowArrows|chartShowDates);
 SetBarsRequired(sbrAll,sbrAll);
 _SECTION_END();

 _SECTION_BEGIN("Price");
 SetBarFillColor(IIf(C > Ref(C,-1) ,ParamColor("Candle Up Color", colorBrightGreen),IIf(C < Ref(C,-1),ParamColor("Candle Down Color", colorRed),colorLightGrey)));
 Plot(C,"close",IIf(C > O ,ParamColor("Shadow Up Color", colorBlack),IIf(C < O ,ParamColor("Shadow Down Color", colorBlack),colorLightGrey)),64,0,0,0,0);
 GraphXSpace=Param("GraphXSpace",20,-10,25,1);
 _SECTION_END();

 _SECTION_BEGIN("Time Calculation");
 beginTradeTime = ParamTime("Strt Time ", "9:15:00");
 endTradeTime    = ParamTime("End Time","15:30:00");

 DaysBack = 1;

 dayHigh = deTimeRangeHHV(H,beginTradeTime ,endTradeTime );
 dayLow = deTimeRangeLLV(L,beginTradeTime ,endTradeTime );
 
 Ystdhigh = ValueWhen(deFlagLastBarOfDay(endTradeTime ),dayHigh ,DaysBack);
 Ystdlow = ValueWhen(deFlagLastBarOfDay(endTradeTime ), dayLow ,DaysBack); 

 ydaycls=deValueWhenTime ( C, endTradeTime );
 Ystdclos = ValueWhen(deFlagLastBarOfDay(endTradeTime ), ydaycls,DaysBack); 
 Today = LastValue(Day());

 Plot(IIf(Today == Day(),dayHigh ,Null),"",colorPaleGreen,styleLine );
 Plot(IIf(Today == Day(),dayLow ,Null),"",colorSkyblue,styleLine );

 Plot(IIf(Today == Day(),Ystdhigh ,Null),"",colorBrightGreen,styleLine ); 
 Plot(IIf(Today == Day(),Ystdlow,Null) ,"",colorOrange,styleLine );
 Plot(IIf(Today == Day(),YstdClos,Null),"",colorBlue,styleLine ); 

 C11=ParamColor("Text col",colorBlue );
 numbars = LastValue(Cum(Status("barvisible")));
 fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
 hts  = Param ("Text Shift", -50,-200,200,25);

 PlotText("PHi = " + WriteVal(Ystdhigh ,fraction),LastValue(BarIndex())-(numbars/hts+25),LastValue (Ystdhigh ,1) , C11);
 PlotText("PLo = " + WriteVal(Ystdlow ,fraction),LastValue(BarIndex())-(numbars/hts+25),LastValue (Ystdlow ,1) , C11);
 PlotText("PCls = " + WriteVal(YstdClos,fraction),LastValue(BarIndex())-(numbars/hts+30),LastValue (YstdClos,1) , C11);

 PlotText("DayHi = " + WriteVal(dayHigh ,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (dayHigh ,1) , C11);
 PlotText("DayLo = " + WriteVal(dayLow ,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (dayLow ,1) , C11);
 _SECTION_END();

 _SECTION_BEGIN("Title");
 
 Title = 
 EncodeColor(colorBrightGreen)+ "Prev Day HiLo with Today's HiLo \n" +  Name() + " : " + EncodeColor(colorBrightGreen)+ Interval(2) 
 +EncodeColor(colorBrightGreen) + " : " + Date() +"\n\n"
 +EncodeColor(colorWhite) + "PHi = " + EncodeColor(colorWhite) + NumToStr(Ystdhigh ,1.2) + "\n" 
 +EncodeColor(colorWhite) + "PLo = " + EncodeColor(colorWhite) + NumToStr(Ystdlow ,1.2) + "\n"  
 +EncodeColor(colorWhite) + "P CLs = " + EncodeColor(colorWhite) + NumToStr(YstdClos,1.2) + "\n\n"  
 +EncodeColor(colorWhite) + "Day Hi = " + EncodeColor(colorWhite) + NumToStr(dayHigh ,1.2) + "\n" 
 +EncodeColor(colorWhite) + "Day Lo = " + EncodeColor(colorWhite) + NumToStr(dayLow,1.2) ; 

 _SECTION_END();
 

josh1

Well-Known Member
@SR114

Your AFL does not plot PDH PDL for earlier days. After removing Today == Day () formula, it did plot but it would plot weird vertical lines at EOD. Thereafter, I replaced formulas in Essential Trader Tools AFL with yours. I am getting very good results.

Here it is --

Code:
_SECTION_BEGIN("Colours");

//SetChartBkGradientFill( ParamColor("BgTop",colorBlack),ParamColor("BgBottom",colorBlack),ParamColor("Titleblock",colorBlack));

PDHClr = ParamColor( "PrvDayHighColor", colorRed);
TDHClr = ParamColor( "2DayHighColor", colorDarkRed);
PDLClr = ParamColor( "PrvDayLowColor", colorYellow);
TDLClr = ParamColor( "2DayLowColor", colorDarkYellow);
PDCClr = ParamColor( "PrvDayCloseColor", colorGrey50);
TDClrs = ParamColor("TodayColors",colorOrange );
Legend = ParamToggle("Show legends","Show|Hide",1);
if (Legend == 0) 
	Legends = "\nLegends\n" 
	+ EncodeColor(PDHClr) + "PreviousDayHigh ----------------\n"
	+ EncodeColor(TDHClr) + "TwoDayDayHigh   ----------------\n"  
	+ EncodeColor(PDLClr) + "PreviousDayLow  ----------------\n"
	+ EncodeColor(TDLClr) + "TwoDayLow       ----------------\n"
	+ EncodeColor(PDCClr) + "PreviousDayClose----------------\n"
	+ EncodeColor(TDClrs) + "TodayColors     ----------------" ;
else 
	Legends = "";

_SECTION_END();


_SECTION_BEGIN("PreviousDay HI-LO");

/* ------------------  Commented by Josh1 ---------------
//DayH = TimeFrameGetPrice("H", inDaily, -1);  DayHI = LastValue (DayH,1);// yesterdays high 
//DayL = TimeFrameGetPrice("L", inDaily, -1);  DayLI = LastValue (DayL,1);    // yesterdays low
/* end ------------------  Commented by Josh1 ---------------*/

DayC = TimeFrameGetPrice("C", inDaily, -1);  DayCI = LastValue (DayC,1);    // yesterdays close
DayO = TimeFrameGetPrice("O", inDaily);      DayOI = LastValue (DayO,1);   // current day open
DH = TimeFrameGetPrice("H", inDaily);  DHI = LastValue (DH,1);// Todays high
DL = TimeFrameGetPrice("L", inDaily);  DLI = LastValue (DL,1);    // Todays low
//DBYH = TimeFrameGetPrice("H", inDaily, -2);  DBYHI = LastValue (DBYH,1);// 2 yesterdays high
//DBYL = TimeFrameGetPrice("L", inDaily, -2);  DBYLI = LastValue (DBYL,1);    // 2 yesterdays low

//End---------------------Inserted by Josh1 --------------- end

beginTradeTime = ParamTime("Strt Time ", "9:15:00");
 endTradeTime    = ParamTime("End Time","15:30:00");

 DaysBack = 1;

 dayHigh = Max(deTimeRangeHHV(O,beginTradeTime ,endTradeTime ),deTimeRangeHHV(C,beginTradeTime ,endTradeTime ));
 dayLow = Min(deTimeRangeLLV(O,beginTradeTime ,endTradeTime),deTimeRangeLLV(C,beginTradeTime ,endTradeTime ));
 
// Ystdhigh = ValueWhen(deFlagLastBarOfDay(endTradeTime ),dayHigh ,DaysBack);
// Ystdlow = ValueWhen(deFlagLastBarOfDay(endTradeTime ), dayLow ,DaysBack); 
 DayH = ValueWhen(deFlagLastBarOfDay(endTradeTime ),dayHigh ,DaysBack);DayHI = LastValue (DayH,DaysBack);// yesterdays high
 DayL = ValueWhen(deFlagLastBarOfDay(endTradeTime ), dayLow ,DaysBack); DayLI = LastValue (DayL,DaysBack);    // yesterdays low

DaysBack = 2;
 DBYH = ValueWhen(deFlagLastBarOfDay(endTradeTime ),dayHigh ,DaysBack);DBYHI = LastValue (DBYH,DaysBack);// yesterdays high
 DBYL = ValueWhen(deFlagLastBarOfDay(endTradeTime ), dayLow ,DaysBack); DBYLI = LastValue (DBYL,DaysBack);    // yesterdays low

// ydaycls=deValueWhenTime ( C, endTradeTime );
// Ystdclos = ValueWhen(deFlagLastBarOfDay(endTradeTime ), ydaycls,DaysBack); 
 Today = LastValue(Day());

//End---------------------Inserted by Josh1 --------------- end
 
numbars = LastValue(Cum(Status("barvisible")))-1;
Hts  = -33.5;
//Today = Ref(LastValue(DaysSince1900()),-1);
Today = LastValue(DaysSince1900());


YHL = ParamToggle("Yesterday HI LO","Show|Hide",1);
//YdClrs = ParamColor("YesterdayColors", colorTurquoise);

if(YHL==1) {

	Plot(DayL,"YL",PDLClr,styleDots|styleThick|styleNoLine|styleNoRescale|styleNoTitle,0,0,2);
	Plot(DayH,"YH",PDHClr,styleDots|styleThick|styleNoLine|styleNoRescale|styleNoTitle,0,0,2);
  	Plot(DayC,"PDC",PDCClr,styleDots|styleNoLine|styleNoRescale|styleNoTitle|styleNoLabel,0,0,2);
	Plot(DBYH,"DBYH",TDHClr,styleDots|styleNoLine|styleNoRescale|styleNoTitle|styleNoLabel);
  	Plot(DBYL,"DBYL",TDLClr,styleDots|styleNoLine|styleNoRescale|styleNoTitle|styleNoLabel);
	Plot(IIf(Today ==DaysSince1900(),DL,Null),"DL",TDClrs,styleLine|styleThick|styleNoRescale|styleNoTitle|styleNoLabel);
	Plot(IIf(Today==DaysSince1900(),DH,Null),"DH",TDClrs,styleLine|styleThick|styleNoRescale|styleNoTitle|styleNoLabel);
	Plot(IIf(Today==DaysSince1900(),DayO,Null),"DO",TDClrs,styleLine|styleThick|styleNoRescale|styleNoTitle|styleNoLabel);

	Dist = 4	;
  	PlotText("__YH ", LastValue(BarIndex())-(numbars/Hts)+Dist, DayHI, PDHClr);
  	PlotText("__YL" , LastValue(BarIndex())-(numbars/Hts)+Dist, DayLI, PDLClr);
 // 	PlotText("__YC " ,     LastValue(BarIndex())-(numbars/Hts), DayCI, PDCClr);
 // 	PlotText("__DO " ,     LastValue(BarIndex())-(numbars/Hts)+Dist, DayOI, TDClrs);
  	PlotText("__DH " ,     LastValue(BarIndex())-(numbars/Hts)+Dist, DHI, TDClrs);
  	PlotText("__DL " ,     LastValue(BarIndex())-(numbars/Hts)+Dist, DLI, TDClrs);
 // 	PlotText("__BYH " ,     LastValue(BarIndex())-(numbars/Hts)+Dist, DBYHI, TDHClr);
 // 	PlotText("__BYL " ,     LastValue(BarIndex())-(numbars/Hts)+Dist, DBYLI, TDLClr);

}

Rn = Param("RN",50,50,1000,50,0);
Miny = Status("axisminy");
yl = int(Miny/Rn)*Rn;
Maxy = Status("axismaxy"); 
yh = int(Maxy/Rn)*Rn;
i=yl;
while( i>= yl AND i<=yh )
{
//PlotShapes(shapeSmallCircle,colorGold,0, i,0);
//PlotText( "__________", LastValue(BarIndex())-(numbars/Hts)-6, i, colorGold );
Plot(IIf(Today == DaysSince1900(),i,Null), "S3",colorGold,styleLine|styleNoRescale|styleNoTitle|styleNoLabel,0,0,2);

i=i+Rn;
}

_SECTION_END();
 

sr114

Well-Known Member
hi,
Firstly thanks you all because helping me
Secondly,
I want to draw a chart compare the % change in closing price of 1 stock and market
please help me
thanks a lot
here for u. period of roc is customisable vua paramater window

Code:
 _SECTION_BEGIN("Background_Setting");
 SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
 ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorBlack)); 
 SetChartBkColor(ParamColor("Outer Panel",colorBlack));
 SetChartOptions(0,chartShowArrows|chartShowDates);
 _SECTION_END();

 _SECTION_BEGIN("Price_idx");
 Index = ParamStr("Index", "NIFTY 50");	
 idx=Foreign(Index,"C");			// Here's the index
 _SECTION_END();

 _SECTION_BEGIN("Price");
 pd=Param ( "Period", 5,1,25,1 );

 r1 = ROC( Close, pd );
 r2 = ROC( idx, pd );
 
 Style = ParamStyle( "Style", styleLine, maskPrice );

 Plot(r1,"",colorBlue,Style );
 Plot(r2,"",colorTan,Style );
 Plot(0,"",colorGrey40,1);

 Title = EncodeColor(colorYellow) + "Rate of Change wrt Mkt \n" + EncodeColor(colorWhite)+ ""+Date() + " \n" + Name()+EncodeColor(5) +
 EncodeColor(colorWhite) + ", Close =" +C + "\nRate of Change in "+pd +" Period = " + NumToStr(r1,1.2)+"\n"+
 EncodeColor(colorWhite) +index + " , Close = "+ idx+"\n"+ "Rate of Change in "+pd+ " Period = "+NumToStr(r2,1.2);
 GraphXSpace=10;
 _SECTION_END();
rgds
 
here for u. period of roc is customisable vua paramater window

Code:
 _SECTION_BEGIN("Background_Setting");
 SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
 ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorBlack)); 
 SetChartBkColor(ParamColor("Outer Panel",colorBlack));
 SetChartOptions(0,chartShowArrows|chartShowDates);
 _SECTION_END();

 _SECTION_BEGIN("Price_idx");
 Index = ParamStr("Index", "NIFTY 50");	
 idx=Foreign(Index,"C");			// Here's the index
 _SECTION_END();

 _SECTION_BEGIN("Price");
 pd=Param ( "Period", 5,1,25,1 );

 r1 = ROC( Close, pd );
 r2 = ROC( idx, pd );
 
 Style = ParamStyle( "Style", styleLine, maskPrice );

 Plot(r1,"",colorBlue,Style );
 Plot(r2,"",colorTan,Style );
 Plot(0,"",colorGrey40,1);

 Title = EncodeColor(colorYellow) + "Rate of Change wrt Mkt \n" + EncodeColor(colorWhite)+ ""+Date() + " \n" + Name()+EncodeColor(5) +
 EncodeColor(colorWhite) + ", Close =" +C + "\nRate of Change in "+pd +" Period = " + NumToStr(r1,1.2)+"\n"+
 EncodeColor(colorWhite) +index + " , Close = "+ idx+"\n"+ "Rate of Change in "+pd+ " Period = "+NumToStr(r2,1.2);
 GraphXSpace=10;
 _SECTION_END();
rgds

thanks a lot bro,
i can use it to analysis now
best wish for you :clap::clap::clap:
 

Similar threads