pl. correct this code

bharatk8

Active Member
#1
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();
 

iamaaditya

Active Member
#4
Hey i copied your AFL and it worked very fine without any alteration. So i suppose the code is fine but some settings may be giving you the problem.
Try SETCHARTOPTIONS() in your code to change some of the display settings. Also since all other plots (except price) already has styleOwnScale so there should be no problem regarding scaling.

If it still doesn't work, let me know will try to do some code changes.

have a nice weekend
 

iamaaditya

Active Member
#5
Just so that you may not get confused, i also tried changing the symbols and it worked fine for all symbols.

Make sure that from Parameters - GIP-3 Style is not hidden (that is the source for other other plots)
 

bharatk8

Active Member
#6
Thanks for help.I checked GIP-3 style.It was not hidden (see image).I chose all other option in GIP-3 one by one.But it did not work.

I have also tried one code suggested for this problem too(see image).But it did not help.Pl. do needful.
 
Last edited:

iamaaditya

Active Member
#7
Are we on the same page ? the code you pasted above doesn't have the "CUSTOM RSI" section (seen in pic above).
are you trying to plot the RSI on the same pane as Price ? If yes, then you cannot plot the constant lines (Plot-40 and Plot-65), this will skew the scaling.

Can you do one favor, just try the code you pasted in your first post, and if you still have problem, i don't mind rewriting the logic for you.
 

bharatk8

Active Member
#8
dear aaditya,

checked code as it is. This code does not show OBV line on chart.When I make any change in scale code to get OBV also, it starts giving problem.It will be nice if you can tweak the code.Otherwise I will have to find substitute of OBV which does not clash with RSI and BB.
 
#10
Sorry for late reply, just got too busy. (you know expiry of FnO et cetera).

Well , if you surely think OBV is the one causing the problem, then i
have rewritten the OBV formula for you (which is a very simple formula
by the way).

Try to use the following formula:
bv[0] = V[0];
for(i=1; i<BarCount; i++) {
if(C>C[i-1])
bv = bv[i-1] + V;
else
bv = bv[i-1] - V;
}

Plot(bv, "bv", colorWhite, styleLine | styleOwnScale);

-----------------------------------------------------------------------------------------------------------
First let me alert you that the above the formula will plot the OBV
but the absolute number will not be the same, but if you plot both of
them then they should overlap upto 99%. And in OBV we are interested
in the graph and the line movement and i dont' think anyone needs the
absolute value of OBV.

Even after this it doesnot work, then try one thing, take a blank
chart, drag Price (from the Basic), volume, rsi, bb (and whatever you
want) and see if it works.

Let us know, how it develops. Let's solve this problem by this
weekend. (weekdays are very hectic)
 

Similar threads