I have AFL code for plotting BB,RSI,OBV and volume in same chart.It seems proper code for scaling is not used so whenever I switch over chart from Nifty to another scrip display of chart gets squeezed.When I check parameters>axis and grid,i find -ve value in minimum column.This seems to be root cause of problem.Pl. do necessary correction.
SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
_SECTION_BEGIN("rsi");
rs = ParamToggle("RSI", "Hide|Show",1);
per=Param("RSI-PER",9,5,20,1);
x=ParamColor("rsi color",colorBlack);
PR=Param("lookback PER",9,5,20,1);
_SECTION_END();
_SECTION_BEGIN("GIP-3");
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 )) ));
Cr = IIf(RSI(9) <= LLV(RSI(9),9) , colorRed , IIf(RSI(9) >=HHV(RSI(9),9) , colorGreen ,IIf(C > O , colorWhite , colorBlack)));
SetBarFillColor( Cr );
Plot( C, "Close", Cr, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue(O-C ));
}
_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorLime ), ParamColor("Down Color", colorRed ) ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick| styleNoLabel, maskHistogram),2);
_SECTION_END();
_SECTION_BEGIN("OBV");
RS1=ParamToggle("OBV", "Hide|Show",1);
x1=ParamColor("obv color",colorGreen);
PR=Param("lookback PER",9,5,20,1);
_SECTION_END();
_SECTION_BEGIN("BB");
RS2=ParamToggle("BB 1", "Hide|Show",1);
Period = Param("Period", 9, 2, 30, 1 );
Width = Param("Width", 1.5, 0, 10, 0.05 );
x2=ParamColor("BB1 color",colorDarkRed|styleThick);
_SECTION_END();
_SECTION_BEGIN("BB2");
RS3=ParamToggle("BB 2", "Hide|Show",1);
Period1 = Param("Period1",20, 2, 30, 1 );
Width1 = Param("Width1", 2, 0, 10, 0.05 );
x3=ParamColor("BB2 color",colorBlue | styleThick );
_SECTION_END();
_SECTION_BEGIN("Background text");
X6=Param("Fonts",100,50,50,7);
Hue = Param("Hue",0,1,255,1);
Saturation = Param("Saturation",0,1,255,1);
Brightness = Param("Brightness",0,1,255,2);
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
_SECTION_END();
mid= WMA(C,Period);
sd = StDev( C, Period );
Top = mid + Width * sd;
Bot = mid - Width * sd;
mid1= WMA(C,Period1);
sd1 = StDev( C, Period1 );
Top1 = mid1 + Width1 * sd1;
Bot1 = mid1 - Width1 * sd1;
r = RSI(per) ;
if (RS == 1)
{
Plot( R, "", x, 1|styleOwnScale );
}
if (RS1 == 1)
{
Plot(OBV(),"",x1,styleThick|styleNoRescale );
}
if (RS2 == 1)
{
Plot( Top, " ",32 , 4);
Plot( mid, " ", 32,4);
Plot( Bot, " ", 32, 4);
}
if (RS3 == 1)
{
Plot( Top1, " ",29, 4);
Plot( mid1, "", 55,4 );
Plot( Bot1, " ",29 , 4);
}
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleDashed), 2 );
_SECTION_END();
SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
_SECTION_BEGIN("rsi");
rs = ParamToggle("RSI", "Hide|Show",1);
per=Param("RSI-PER",9,5,20,1);
x=ParamColor("rsi color",colorBlack);
PR=Param("lookback PER",9,5,20,1);
_SECTION_END();
_SECTION_BEGIN("GIP-3");
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 )) ));
Cr = IIf(RSI(9) <= LLV(RSI(9),9) , colorRed , IIf(RSI(9) >=HHV(RSI(9),9) , colorGreen ,IIf(C > O , colorWhite , colorBlack)));
SetBarFillColor( Cr );
Plot( C, "Close", Cr, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue(O-C ));
}
_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorLime ), ParamColor("Down Color", colorRed ) ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick| styleNoLabel, maskHistogram),2);
_SECTION_END();
_SECTION_BEGIN("OBV");
RS1=ParamToggle("OBV", "Hide|Show",1);
x1=ParamColor("obv color",colorGreen);
PR=Param("lookback PER",9,5,20,1);
_SECTION_END();
_SECTION_BEGIN("BB");
RS2=ParamToggle("BB 1", "Hide|Show",1);
Period = Param("Period", 9, 2, 30, 1 );
Width = Param("Width", 1.5, 0, 10, 0.05 );
x2=ParamColor("BB1 color",colorDarkRed|styleThick);
_SECTION_END();
_SECTION_BEGIN("BB2");
RS3=ParamToggle("BB 2", "Hide|Show",1);
Period1 = Param("Period1",20, 2, 30, 1 );
Width1 = Param("Width1", 2, 0, 10, 0.05 );
x3=ParamColor("BB2 color",colorBlue | styleThick );
_SECTION_END();
_SECTION_BEGIN("Background text");
X6=Param("Fonts",100,50,50,7);
Hue = Param("Hue",0,1,255,1);
Saturation = Param("Saturation",0,1,255,1);
Brightness = Param("Brightness",0,1,255,2);
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
_SECTION_END();
mid= WMA(C,Period);
sd = StDev( C, Period );
Top = mid + Width * sd;
Bot = mid - Width * sd;
mid1= WMA(C,Period1);
sd1 = StDev( C, Period1 );
Top1 = mid1 + Width1 * sd1;
Bot1 = mid1 - Width1 * sd1;
r = RSI(per) ;
if (RS == 1)
{
Plot( R, "", x, 1|styleOwnScale );
}
if (RS1 == 1)
{
Plot(OBV(),"",x1,styleThick|styleNoRescale );
}
if (RS2 == 1)
{
Plot( Top, " ",32 , 4);
Plot( mid, " ", 32,4);
Plot( Bot, " ", 32, 4);
}
if (RS3 == 1)
{
Plot( Top1, " ",29, 4);
Plot( mid1, "", 55,4 );
Plot( Bot1, " ",29 , 4);
}
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleDashed), 2 );
_SECTION_END();