Australian (ASX) Stock Market Forum

Please correct scales mismatch to improve chart view

Joined
Sep 28, 2012
Posts
9
Reactions
0
I have AFL with BB,,RSI,OBV,gap finder and MTF code for BB.It seems my chart gets compressed due to mismatch of scales.I want price to occupy major portion of chart.Read the code and correct the mistake.


HH = TimeFrameGetPrice("H",inDaily, -1);///for plotting previous day high low line
LL = TimeFrameGetPrice("L",inDaily, -1);
Plot( HH, "High", colorRose,styleThick);
Plot( LL, "Low", colorTurquoise,styleThick);

HHw = TimeFrameGetPrice("H",inWeekly, -1);
LLw = TimeFrameGetPrice("L",inWeekly, -1);
//Plot( HHw, "High", colorPlum,styleThick);
//Plot( LLw, "Low", colorPlum,styleThick);


_SECTION_BEGIN("Price Line");
PriceLineColor= ParamColor("PriceLineColor",ColorRGB(82,82,82));
PriceLevel=ParamField("PriceField", field = 3 );
Daysback= Param("Bars Back",200,10,500,1);
FirstBar= BarCount - DaysBack;
YY= IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);
Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));
Side= Param("Side",1,0,100,1);
Dist= 0;
for( i = 0; i < BarCount; i++ )
{
if(i+Side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-Dist, colorBlue );
}
_SECTION_END();

THL = ParamToggle("Todays Hi Lo","Show|Hide",0);
numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;
isRth = TimeNum() >=091600 & TimeNum() <= 095959;//TimeNum() >= 084500 & TimeNum() <= 085959
isdRth = TimeNum() >= 091600 & TimeNum() <= 153000;
aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );
Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);
//BarIndex(),1);
// AND DateNum()==LastValue(DateNum());
x0 = BarCount-
LastValue(Bars);
x1 = BarCount-1;
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);
DayHlineI = LastValue (DayHline,1); DayLlineI = LastValue (DayLline,1);

if(THL==0)
{
Plot(DayHline,"DayH",colorBlue,styleBar|styleLine );//| styleNoRescale 29 thSEPT
Plot(DayLline,"DayL",colorBlue,styleBar|styleLine );//| styleNoRescale
PlotText(" Day Hi " , LastValue(BarIndex())-(numbars/Hts), DayHlineI +0.05, colorBlue);
PlotText(" Day Lo " , LastValue(BarIndex())-(numbars/Hts), DayLlineI +0.05, colorBlue);
}

////////// Yesterday Hi-Low //////////
DayH = TimeFrameGetPrice("H", inDaily, -1); DayHI = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); DayLI = LastValue (DayL,1); // yesterdays low


//color = IIf(C > MTF + 5 , colorWhite, colorBlack);
//SetBarFillColors(color);
//Plot(C, "Close", color, 64);
//dn = DateNum();
//newDay = dn != Ref( dn, -1);
//Then - refer to NewDay with e.g. ValueWhen:
//myVal = ValueWhen( newDay, Close);
//barcomplete = BarIndex() < LastValue(BarIndex());
//AlertIf( barcomplete AND condition, "", "Text", 1 );

//Condition = V < 0.5 * Ref( V, -1) AND SecsToGo < 600;
GraphXSpace =7; // do not toch my code

_SECTION_BEGIN("gapfinder");
// Input : The number of bars ago from where to start looking for gaps.
// Default is 250 : So, by default we search for Gaps found in last 250 trading days ( 1 year )
period = Param("Lookback Period", 250, 15, 500);
// If we do not have enough bars, adjust the period accorPaperTrading_V5_Parametersdingly.
if( BarCount - period - 1 < 0 ) period = BarCount - 2;


bIsGapUp = ( L > Ref(H, -1) ); // Identify GapUp bars
bIsGapDn = ( H < Ref(L, -1) ); // Identify GapDown bars


// We are not interested in Gap Ups and Gap Downs before the Period e.g. before the last 250 bars.
// So we clear the values for bars before the ones we are interested in.
for( i = 0 ; i < (BarCount - 1 - period) ; i++ )
{
bIsGapUp = False;
bIsGapDn = False;
}


// Now plot GapUp bars with a Up-Triangle below its low.
PlotShapes(IIf(bIsGapUp, shapeSmallUpTriangle, shapeNone), colorRose, 0, L, -13 );
// Now plot GapDown bars with a Down-Triangle below its high.
PlotShapes(IIf(bIsGapDn, shapeSmallDownTriangle, shapeNone), colorRose,0, H,13 );


// Now walk from the first bar (e.g 250 bars ago, to the current bar)
for( i = (BarCount - period - 1) ; i <= (BarCount - 1) ; i++ )
{
dUpper = 0.0; dLower = 0.0; bFilled = True;
// Is the current bar a Gap-Up bar ?
if( bIsGapUp == True )
{
// If yes, the store the Gap (Upper value) and Lower values.
dUpper = L; dLower = H[i-1]; bFilled = False;
// Now walk till the current bar and see if the Gap values have been filled from Above.
// I.e prices are falling and the gap is being falled.
for( j = i+1; j <= (BarCount - 1) ; j++ )
{
// Check whether the current low is lesser than the Gap high. If yes, the Gap
// has been penetrated.
if( L[j] < dUpper )
{
dUpper = L[j];
// Determine whether the Gap has been fully penetrated - if yes, then the
// Gap has been filled.
if( dUpper <= dLower ) bFilled = True;
}
if( bFilled == True ) break;
}
}
else if( bIsGapDn == True )
{
// Same logic as GapUp - except we check whether the Gap has been pierced from Below.
// i.e Prices are rising and the Gap has been filled.
dUpper = L[i-1]; dLower = H; bFilled = False;
for( j = i+1; j <= (BarCount - 1) ; j++ )
{
if( H[j] > dLower )
{
dLower = H[j];
if( dLower >= dUpper ) bFilled = True;
}
if( bFilled == True ) break; // Gap was filled, so move on to find the next gap.
}
}
if( bFilled == False ) // Gap Not filled - so plot horizontal line at the Gap Level.
{
pLine = LineArray(i-1, dLower, BarCount-1,dLower, 1);
Plot(pLine, "", colorLightYellow,styleDashed | styleNoRescale );//
pLine = LineArray(i-1, dUpper, BarCount-1, dUpper, 1);
Plot(pLine, "", colorLightYellow, styleDashed | styleNoRescale);//
}
}
_SECTION_END();

_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("OBV");

RS1=ParamToggle("OBV", "Hide|Show",1);
x1=ParamColor("obv color",colorPaleTurquoise);
PR=Param("lookback PER",9,5,20,1);

_SECTION_END();

_SECTION_BEGIN("BB");

RS2=ParamToggle("BB ", "Hide|Show",1);
Period = Param("Period", 9, 2, 30, 1 );
Width = Param("Width", 1.5, 0, 10, 0.05 );
x2=ParamColor("BB color",colorRed|styleThick);

_SECTION_END();
/*
_SECTION_BEGIN("BB1");

RS3=ParamToggle("BB1", "Hide|Show",1);
Period1 = Param("Period1",20, 2, 30, 1 );
Width1 = Param("Width1", 2, 0, 10, 0.05 );
x3=ParamColor("BB1 color",colorBlue | styleThick );

_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,styleThick );

}
if (RS1 == 1)
{
Plot(OBV(),"",x1,styleThick|styleLeftAxisScale,styleThick );

}
/*if (RS2 == 1)
{
Plot( Top, " ",32 ,styleThick| styleNoRescale );


Plot( mid, " ", 32,styleThick| styleNoRescale );




Plot( Bot, " ", 32, styleThick| styleNoRescale );




}
if (RS3 == 1)
{
//BHH=HH>Top1;
//npclr9=IIf(BHH,colorCustom12,colorBlue);
//Plot( 1.2,"",npclr9,styleThick| styleNoRescale );

Plot( Top1, " ",29, styleThick| styleNoRescale );



Plot( mid1, "", 53,styleThick| styleNoRescale );




Plot( Bot1, " ",29 ,styleThick| styleNoRescale );
}





if (RS2 == 1)
{
Plot( Top, " ",32 ,styleThick);//| styleOwnScale
//dynamic_color = IIf( MACD() > 0, colorGreen, colorRed );
//Plot( MACD(), "My MACD", dynamic_color, styleHistogram | styleThick );

dynamic_color1 = IIf(Mid > DayL, colorBrightGreen, colorRed );
Plot( mid, " ", dynamic_color1,styleThick );
Plot( Bot, " ", 32, styleThick );
}

if (RS3 == 1)
{
Plot( Top1, " ",29, styleThick );
dynamic_color2 = IIf(Mid1 > DayL, colorDarkGreen, colorBlueGrey );
Plot( mid1, " ", dynamic_color2,styleThick );


//Plot( mid1, "", 53,styleThick );
Plot( Bot1, " ",29 ,styleThick );
}
_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",colorRed|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();
r = RSI( per ) ;
if ( RS == 1 )
{
Plot( R, "", x, 1 | styleOwnScale );
}

if (RS1 == 1)
{
Plot(OBV(),"",x1,styleThick|styleOwnScale );
}

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;

if (RS2 == 1) {
Plot( Top, " ",32 ,styleThick|styleNoRescale );
Plot( mid, " ", 32,styleThick|styleNoRescale );
Plot( Bot, " ", 32, styleThick|styleNoRescale );
}
if ( RS3 == 1 )
{
Plot( Top1, " ", 29, styleThick | styleNoRescale );
Plot( mid1, "", 45, styleThick | styleNoRescale );
Plot( Bot1, " ", 29 , styleThick | styleNoRescale );

}
_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();



_SECTION_BEGIN("Monthly BB");


TFm = inMonthly ;
TimeFrameSet(TFm);
ShowBBm9F=ParamToggle("BB9 MTFm F", "Hide|Show",1);
ShowBBm9L=ParamToggle("BB9 MTFm L", "Hide|Show",1);
PMTFm9 = Param("Periom9 MTFm", 9, 2, 30, 1 );
WMTFm9 = Param("Width9 MTFm", 1.5, 0, 10, 0.05 );




ShowBBm20F=ParamToggle("BB20 MTFm F", "Hide|Show",1);
ShowBBm20L=ParamToggle("BB20 MTFm L", "Hide|Show",1);
PMTFm20 = Param("Periom20 MTFm", 20, 2, 30, 1 );
WMTFm20 = Param("Width20 MTFm", 2, 0, 10, 0.05 );


Mm9= WMA(C,PMTFm9);
sdm9 = StDev( C, PMTFm9 );
Topm9 = Mm9 + WMTFm9 * sdm9;
Botm9 = Mm9 - WMTFm9 * sdm9;


Mm20 = WMA(C,PMTFm20);
sdm20 = StDev( C, PMTFm20);
Topm20 = Mm20 + WMTFm20 * sdm20;
Botm20 = Mm20 - WMTFm20 * sdm20;


TimeFrameRestore();


Mm9Fm = TimeFrameExpand(Mm9,TFm, expandFirst );
TP9Fm = TimeFrameExpand(TOPm9,TFm, expandFirst );
BT9Fm = TimeFrameExpand(BOTm9,TFm, expandFirst );
Mm20Fm = TimeFrameExpand(Mm20,TFm, expandFirst );
TP20Fm = TimeFrameExpand(TOPm20,TFm, expandFirst );
BT20Fm = TimeFrameExpand(BOTm20,TFm, expandFirst );
Mm9lm = TimeFrameExpand(Mm9,TFm, expandLast );
TP9lm = TimeFrameExpand(TOPm9,TFm, expandLast );
BT9lm = TimeFrameExpand(BOTm9,TFm, expandLast );
Mm20lm = TimeFrameExpand(Mm20,TFm, expandLast );
TP20lm = TimeFrameExpand(TOPm20,TFm, expandLast );
BT20lm = TimeFrameExpand(BOTm20,TFm, expandLast );


if(ShowBBm9F)


Plot(Mm9Fm, "MID BANm9 monthly First", colorOrange, styleLine |styleDots| styleDashed | styleNoRescale );
if(ShowBBm9F)
Plot(TP9Fm, "TOP BANm9 monthly First", colorDarkRed, styleLine |styleDots| styleNoRescale );
if(ShowBBm9F)
Plot(BT9Fm, "BOT BANm9 monthly First", colorDarkOliveGreen, styleLine |styleDots| styleNoRescale );
if(ShowBBm9L)
Plot(Mm9lm, "MID BANm9 monthly Last", colorOrange, styleLine |styleDots| styleThick| styleNoRescale );
if(ShowBBm9L)
Plot(TP9lm, "TOP BANm9 monthly Last", colorRed, styleLine |styleDots| styleThick| styleNoRescale );
if(ShowBBm9L)
Plot(BT9lm, "BOT BANm9 monthly Last", colorRed, styleLine |styleDots| styleThick| styleNoRescale );


if(ShowBBm20F)
Plot(Mm20Fm, "MID BANm20 monthly First", colorDarkRed, styleLine |styleDots| styleDashed| styleNoRescale );
if(ShowBBm20F)
Plot(TP20Fm, "TOP BANm20 monthly First", colorOrange, styleLine |styleDots| styleDashed| styleNoRescale );
if(ShowBBm20F)
Plot(BT20Fm, "BOT BANm20 monthly First", colorOrange, styleLine |styleDots| styleDashed| styleNoRescale );
if(ShowBBm20L)
Plot(Mm20lm, "MID BANm20 monthly Last", colorDarkRed,styleLine |styleDots| styleThick| styleNoRescale );
if(ShowBBm20L)
Plot(TP20lm, "TOP BANm20 monthly Last", colorOrange, styleLine |styleDots| styleThick| styleNoRescale );
if(ShowBBm20L)
Plot(BT20lm, "BOT BANm20 monthly Last", colorOrange, styleLine | styleDots| styleThick| styleNoRescale );


_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) AND (C>O) , colorRose , IIf(RSI(9) >=HHV(RSI(9),9) AND (C<O) , colorTurquoise ,IIf(RSI(9) <= LLV(RSI(9),9) , colorDarkRed , IIf(RSI(9) >=HHV(RSI(9),9) , colorGreen ,IIf(C > O , colorWhite , colorBlack)))));
Cr = IIf(RSI(9) <= LLV(RSI(9),9) AND (C>O) , colorRose ,IIf(RSI(9) >=HHV(RSI(9),9) AND (C<O) , colorTurquoise ,IIf(RSI(9) <= LLV(RSI(9),9) , colorDarkRed , IIf(RSI(9) >=HHV(RSI(9),9) ,
colorDarkGreen ,IIf(C > O , colorWhite , colorBlack)))));

//Cr = IIf(RSI(9) <= LLV(RSI(9),9) , colorDarkRed , IIf(RSI(9) >=HHV(RSI(9),9) , colorDarkGreen ,IIf(C > O , colorLavender , colorBlack)));
SetBarFillColor( Cr );
Plot( C, "Close", Cr, ParamStyle("Style") | GetPriceStyle(),maskAll );
 

Attachments

Similar threads

Top