so I was playing with the GuiSlider for the first time. Works good. I added it to the code. Default timeframe is 5min but you can use the slider to change the timeframe. Also made the colors a bit better visible
CellHeight = Param( "Cell Height", 40, 30, 50, 1 );
CellWidth = Param( "Cell Width", 500, 200, 1000, 1 );
transx = Param( "Move Button Pack (X-Axis, bars)", 0, 0, 2000, 10 );
transy = Param( "Move Button Pack (Y-Axis, bars)", 15, 0, 2000, 5 );
trigger = ParamTrigger( "Reset Static Variables", "Click Here" );
x0 = 0 + transx;
y0 = 0 + transy;
idSlider = 1;
row = 1;
timestep = in1Minute;
slider = GuiSlider( idSlider, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
if( slider == guiNew OR trigger )
{
GuiSetValue( idSlider, 5 );
GuiSetRange( idSlider, 1, 240, 1, 5 );
GuiEnable( idSlider, True );
}
GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
tf = timestep * GuiGetValue( idSlider ); // set timeframe here
Title = Name() +
" | " + Now( 1 ) + " | " + Now( 2 ) +
" | " + EncodeColor( colorGold ) + tf / 60 + " Min" + " | " + EncodeColor( colorWhite );
exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, tf, expandPoint ) );
firstbarOfPeriod = Ref( lastbarOfPeriod, -1 );
stepf = ValueWhen( lastbarOfPeriod, bi );
if( !( tf > Interval() ) )
{
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
}
else
{
//Plot( C, "C", colorWhite, styleCandle | styleNoDraw, Null, Null, 0, 0, 1 );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 2, 1 );
}
prch = H;
prcl = L;
TimeFrameSet( tf );
prcH = H;
prcL = L;
prcO = O;
prcC = C;
TimeFrameRestore();
prcH = TimeFrameExpand( prcH, tf, exp1 );
prcL = TimeFrameExpand( prcL, tf, exp1 );
prcO = TimeFrameExpand( prcO, tf, exp1 );
prcC = TimeFrameExpand( prcC, tf, exp1 );
// highest volume
hv = HighestSince( firstbarOfPeriod, V );
hvidx = ValueWhen( hv == V, bi );
hvPrice = ValueWhen( hv == V, C );
hv = IIf( lastbarOfPeriod, hv, 0 );
hvPrice = IIf( lastbarOfPeriod, hvPrice, 0 );
hvidx = IIf( lastbarOfPeriod, hvidx, 0 );
flg = 0;
prevPrice = 0;
if( tf > Interval() )
{
for( i = fvb + 1; i <= lvb; i++ )
{
if( lastbarOfPeriod[i] )
{
// body
x0 = stepf[i - 1] + 1;
x1 = stepf[i];
y0 = prcO[i];
y1 = prcC[i];
if( y0 > y1 )
{
clr = ColorRGB( 255, 204, 204 );
flg = 0;
}
else
if( y0 < y1 )
{
clr = ColorRGB( 204, 255, 255 );
flg = 0;
}
else
{
clr = colorLightGrey;
flg = 1;
}
GfxSetZOrder( -1 );
if( flg == 0 )
{
GfxSelectPen( clr, 1, 0 );
GfxSelectSolidBrush( clr );
GfxRectangle( x0, y0, x1, y1 );
}
else
if( flg == 1 )
{
GfxSelectPen( clr, 1, 0 );
GfxMoveTo( x0, y0 );
GfxLineTo( x1, y1 );
}
// wicks
GfxSelectPen( clr, 4, 0 );
x = ( x0 + x1 ) / 2;
y0 = prcH[i];
y1 = prcL[i];
GfxMoveTo( x, y0 );
GfxLineTo( x, y1 );
// draw cross section at highest volume within interval
GfxSetZOrder( 3 );
y = hvPrice[i];
if( y > prevPrice )
GfxSelectPen( colorDarkGreen, 4, 0 );
else
GfxSelectPen( colorDarkRed, 4, 0 );
x = hvidx[i];
y0 = prcH[i];
y1 = prcL[i];
GfxMoveTo( x, y0 );
GfxLineTo( x, y1 );
x0 = stepf[i - 1] + 1;
x1 = stepf[i];
GfxMoveTo( x0, y );
GfxLineTo( x1, y );
prevPrice = y;
}
}
}