Highest Tic Volume in Higher timeframe chart

Wanted to get highest Tic volume in tic timeframe and display on higher timeframe chart say 5 minute chart bar on tic price.

How do I approach ? I would appreciate if any help on this

or is it possible to draw 5 minute chart in tic timeframe ?tic-vol

Thanks
Ramesh

here is some code to draw the 5min chart in the tick timeframe.

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
bardisplayswitch = ParamToggle( "Show True Bar width", "No|Yes", 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

tf = in5Minute; // set timeframe here

exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, TF, expandPoint ) );
stepf = lastbarOfPeriod = ValueWhen( lastbarOfPeriod, bi );

if( !bardisplayswitch OR !( tf > Interval() ) )
{
    Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
}
else
{
    Plot( C, "C", colorWhite, styleCandle | styleNoDraw, Null, Null, 0, 0, 1 );
}

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

TimeFrameSet( tf );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

prcO2 = O;
prcC2 = C;
TimeFrameRestore();

prcH2 = TimeFrameExpand( prcH, tf, exp1 );
prcL2 = TimeFrameExpand( prcL, tf, exp1 );
prcO2 = TimeFrameExpand( prcO2, tf, exp1 );
prcC2 = TimeFrameExpand( prcC2, tf, exp1 );

GfxSetZOrder( -1 );
GfxSetCoordsMode( 1 );

if( bardisplayswitch AND tf > Interval() )
{
    for( i = fvb + 1; i <= lvb; i++ )
    {
        if( stepf[i] != stepf[i - 1] )
        {
            // body
            x0 = stepf[i - 1];
            x1 = stepf[i];
            y0 = prcO2[i];
            y1 = prcC2[i];

            if( y0 > y1 )
                clr = colorRed;
            else
                if( y0 < y1 )
                    clr = colorBlue;
                else
                    clr = colorLightGrey;

            GfxSelectPen( clr, 1, 0 );
            GfxSelectSolidBrush( clr );
            GfxRectangle( x0, y0, x1, y1 );

            // wicks
            if( priceSwitch )
            {
                GfxSelectPen( clr, 3, 0 );
                x = ( x0 + x1 ) / 2;
                y0 = prcH2[i];
                y1 = prcL2[i];
                GfxMoveTo( x, y0 );
                GfxLineTo( x, y1 );
            }
        }
    }
}

nq

3 Likes

little update of that code

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
bardisplayswitch = ParamToggle( "Show True Bar width", "No|Yes", 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

tf = in5Minute; // set timeframe here

exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, TF, expandPoint ) );
stepf = lastbarOfPeriod = ValueWhen( lastbarOfPeriod, bi );

if( !bardisplayswitch OR !( tf > Interval() ) )
{
    Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
}
else
{
    Plot( C, "C", colorWhite, styleCandle | styleNoDraw, Null, Null, 0, 0, 1 );
}

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

TimeFrameSet( tf );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

prcO2 = O;
prcC2 = C;
TimeFrameRestore();

prcH2 = TimeFrameExpand( prcH, tf, exp1 );
prcL2 = TimeFrameExpand( prcL, tf, exp1 );
prcO2 = TimeFrameExpand( prcO2, tf, exp1 );
prcC2 = TimeFrameExpand( prcC2, tf, exp1 );

GfxSetZOrder( -1 );
GfxSetCoordsMode( 1 );

flg = 0;
if( bardisplayswitch AND tf > Interval() )
{
    for( i = fvb + 1; i <= lvb; i++ )
    {
        if( stepf[i] != stepf[i - 1] )
        {
            // body
            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y0 = prcO2[i];
            y1 = prcC2[i];

            if( y0 > y1 )
            {
                clr = colorRed;
                flg = 0;
            }
            else
                if( y0 < y1 )
                {
                    clr = colorBlue;
                    flg = 0;
                }
                else
                {
                    clr = colorLightGrey;
                    flg = 1;
                }

            if( flg == 0 )
            {
                GfxSelectPen( clr, 1, 0 );
                GfxSelectSolidBrush( clr );
                GfxRectangle( x0, y0, x1, y1 );
            }
            else
                if( flg == 1 )
                {
                    GfxSelectPen( clr, 3, 0 );
                    GfxMoveTo( x0, y0 );
                    GfxLineTo( x1, y1 );
                }

            // wicks
            if( priceSwitch )
            {
                GfxSelectPen( clr, 3, 0 );
                x = ( x0 + x1 ) / 2;
                y0 = prcH2[i];
                y1 = prcL2[i];
                GfxMoveTo( x, y0 );
                GfxLineTo( x, y1 );
            }
        }
    }
}
1 Like

Thank you so much, will try to map highest tic volume on candle

-Ramesh

hi

you can indicate the location of the highest tick volume as follows (see yellow line in chart)

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
bardisplayswitch = ParamToggle( "Show True Bar width", "No|Yes", 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

tf = in5Minute; // set timeframe here

exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, TF, expandPoint ) );
firstbarOfPeriod = Ref( lastbarOfPeriod, -1 );
stepf = ValueWhen( lastbarOfPeriod, bi );

if( !bardisplayswitch OR !( 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, 0, 1 );
}

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

TimeFrameSet( tf );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

prcO2 = O;
prcC2 = C;
TimeFrameRestore();

prcH2 = TimeFrameExpand( prcH, tf, exp1 );
prcL2 = TimeFrameExpand( prcL, tf, exp1 );
prcO2 = TimeFrameExpand( prcO2, tf, exp1 );
prcC2 = TimeFrameExpand( prcC2, tf, exp1 );

// highest volume
hv = HighestSince( firstbarOfPeriod, V );
hvidx = ValueWhen( hv == V, bi ); 
hv = IIf( lastbarOfPeriod, hv, 0 );
hvidx = IIf( lastbarOfPeriod, hvidx, 0 );

GfxSetZOrder( -1 );
GfxSetCoordsMode( 1 );

flg = 0;
if( bardisplayswitch AND tf > Interval() )
{
    for( i = fvb + 1; i <= lvb; i++ )
    {
        if( lastbarOfPeriod[i] )
        {
            // body
            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y0 = prcO2[i];
            y1 = prcC2[i];

            if( y0 > y1 )
            {
                clr = colorRed;
                flg = 0;
            }
            else
                if( y0 < y1 )
                {
                    clr = colorBlue;
                    flg = 0;
                }
                else
                {
                    clr = colorLightGrey;
                    flg = 1;
                }

            if( flg == 0 )
            {
                GfxSelectPen( clr, 1, 0 );
                GfxSelectSolidBrush( clr );
                GfxRectangle( x0, y0, x1, y1 );
            }
            else
                if( flg == 1 )
                {
                    GfxSelectPen( clr, 3, 0 );
                    GfxMoveTo( x0, y0 );
                    GfxLineTo( x1, y1 );
                }

            // wicks
            if( priceSwitch )
            {
                GfxSelectPen( clr, 3, 0 );
                x = ( x0 + x1 ) / 2;
                y0 = prcH2[i];
                y1 = prcL2[i];
                GfxMoveTo( x, y0 );
                GfxLineTo( x, y1 );
            }
            
            // draw spot of highest volume
            x = hvidx[i];
            y0 = prcO2[i];
            y1 = prcC2[i];
            GfxSelectPen( colorYellow, 2, 0 );
            GfxMoveTo( x, y0 );
            GfxLineTo( x, y1 );
        }
    }
}

si

1 Like

Super sir, trying to understand code . Can we put highest tic volume w.r.t price horizontally and tic bar color green if price is greater than previous tic or else red.

Thank you so much

-Ramesh

i think you mean the PriceVolDistribution?

maybe like this?

GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
bardisplayswitch = ParamToggle( "Show True Bar width", "No|Yes", 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

tf = in15Minute; // set timeframe here

exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, TF, expandPoint ) );
firstbarOfPeriod = Ref( lastbarOfPeriod, -1 );
stepf = ValueWhen( lastbarOfPeriod, bi );

if( !bardisplayswitch OR !( 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, 1, 1 );
}

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

TimeFrameSet( tf );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

prcO2 = O;
prcC2 = C;
TimeFrameRestore();

prcH2 = TimeFrameExpand( prcH, tf, exp1 );
prcL2 = TimeFrameExpand( prcL, tf, exp1 );
prcO2 = TimeFrameExpand( prcO2, tf, exp1 );
prcC2 = TimeFrameExpand( prcC2, 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, C, 0 );
hvidx = IIf( lastbarOfPeriod, hvidx, 0 );

GfxSetZOrder( -1 );
flg = 0;
cntbins = 0;
bincolor = 0;
hvp = 0;

if( bardisplayswitch AND tf > Interval() )
{
    for( i = fvb + 1; i <= lvb; i++ )
    {
        if( lastbarOfPeriod[i] )
        {
            // body
            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y0 = prcO2[i];
            y1 = prcC2[i];

            if( y0 > y1 )
            {
                clr = colorRed;
                flg = 0;
            }
            else
                if( y0 < y1 )
                {
                    clr = colorBlue;
                    flg = 0;
                }
                else
                {
                    clr = colorLightGrey;
                    flg = 1;
                }

            if( flg == 0 )
            {
                GfxSelectPen( clr, 1, 0 );
                GfxSelectSolidBrush( clr );
                GfxRectangle( x0, y0, x1, y1 );
            }
            else
                if( flg == 1 )
                {
                    GfxSelectPen( clr, 3, 0 );
                    GfxMoveTo( x0, y0 );
                    GfxLineTo( x1, y1 );
                }

            // wicks
            if( priceSwitch )
            {
                GfxSelectPen( clr, 3, 0 );
                x = ( x0 + x1 ) / 2;
                y0 = prcH2[i];
                y1 = prcL2[i];
                GfxMoveTo( x, y0 );
                GfxLineTo( x, y1 );
            }

            // draw spot of highest volume
            x = hvidx[i];
            y0 = prcO2[i];
            y1 = prcC2[i];
            GfxSelectPen( colorYellow, 2, 0 );
            GfxMoveTo( x, y0 );
            GfxLineTo( x, y1 );

            if( hvPrice[i] > hvp )
            {
                bincolor[cntbins] = 1;
                hvp = hvPrice[i];
            }
            else
                if( hvPrice[i] < hvp )
                {
                    bincolor[cntbins] = -1;
                    hvp = hvPrice[i];
                }

            cntbins += 1;
        }
    }
}

GfxSetZOrder( -2 );
mx = PriceVolDistribution( H, L, hv, cntbins, False, fvb, lvb );
bins = MxGetSize( mx, 0 );

for( i = 0; i < bins; i++ )
{
    if( bincolor[i] == 1 )
    {
        GfxSelectPen( colorGreen );
    }
    else
        if( bincolor[i] == ( -1 ) )
        {
            GfxSelectPen( colorRed );
        }
        else
            if( bincolor[i] == 0 )
            {
                GfxSelectPen( colorLightGrey );
            }

    price = mx[ i ][ 0 ]; // price level
    relvolume = mx[ i ][ 1 ]; // relative volume 0..1
    relbar = relvolume * ( lvb - fvb + 1 );
    GfxMoveTo( fvb, price );
    GfxLineTo( fvb + relbar, price );
}

hello
Acording to the "Highest Tic Volume in Higher time-frame chart" the highest tic volume it is the High of the of every bar in15Minute of the above example, look at the wicks.

so for that reason i donot understand your question.
Please, you maybe have to rephrase again your question.

vbar

instead of vertical line, need horizontal line on tic price ( which is highest volume of 5min candle ) within bar

Also highest volume horizontal line within bar color shd be green if tic > previous tic

Thanks
Ramesh

Sorry for the confusion

Currently vertical line is displayed on highest tic within bar, instead of need horizontal line on tic price within candle.

vbar2

like this?

GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
bardisplayswitch = ParamToggle( "Show True Bar width", "No|Yes", 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

tf = in5Minute; // set timeframe here

exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, TF, expandPoint ) );
firstbarOfPeriod = Ref( lastbarOfPeriod, -1 );
stepf = ValueWhen( lastbarOfPeriod, bi );

if( !bardisplayswitch OR !( 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, 1, 1 );
}

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

TimeFrameSet( tf );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

prcO2 = O;
prcC2 = C;
TimeFrameRestore();

prcH2 = TimeFrameExpand( prcH, tf, exp1 );
prcL2 = TimeFrameExpand( prcL, tf, exp1 );
prcO2 = TimeFrameExpand( prcO2, tf, exp1 );
prcC2 = TimeFrameExpand( prcC2, 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 );

GfxSetZOrder( -1 );
flg = 0;

if( bardisplayswitch AND tf > Interval() )
{
    for( i = fvb + 1; i <= lvb; i++ )
    {
        if( lastbarOfPeriod[i] )
        {
            // body
            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y0 = prcO2[i];
            y1 = prcC2[i];

            if( y0 > y1 )
            {
                clr = colorGreen;
                flg = 0;
            }
            else
                if( y0 < y1 )
                {
                    clr = colorBlue;
                    flg = 0;
                }
                else
                {
                    clr = colorLightGrey;
                    flg = 1;
                }

            if( flg == 0 )
            {
                GfxSelectPen( clr, 1, 0 );
                GfxSelectSolidBrush( clr );
                GfxRectangle( x0, y0, x1, y1 );
            }
            else
                if( flg == 1 )
                {
                    GfxSelectPen( clr, 3, 0 );
                    GfxMoveTo( x0, y0 );
                    GfxLineTo( x1, y1 );
                }

            // wicks
            if( priceSwitch )
            {
                GfxSelectPen( clr, 3, 0 );
                x = ( x0 + x1 ) / 2;
                y0 = prcH2[i];
                y1 = prcL2[i];
                GfxMoveTo( x, y0 );
                GfxLineTo( x, y1 );
            }

            // draw spot of highest volume
            x = hvidx[i];
            y0 = prcO2[i];
            y1 = prcC2[i];
            GfxSelectPen( colorYellow, 2, 0 );
            GfxMoveTo( x, y0 );
            GfxLineTo( x, y1 );
            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y = hvPrice[i];
            GfxMoveTo( x0, y );
            GfxLineTo( x1, y );
        }
    }
}

ym3

1 Like

Without any looping...

/// @link https://forum.amibroker.com/t/highest-tic-volume-in-higher-timeframe-chart/25338/12
function BarMarker(tmfrm) {
	local bi;
	TimeFrameSet(tmfrm);
		bi = BarIndex();
	TimeFrameRestore();
	bi = TimeFrameExpand(bi, tmfrm, expandPoint);
	return Ref(Nz(bi)>0,-1);
}

bar_flag = BarMarker(in5Minute);
bars = HighestSinceBars(bar_flag, V); 
is_lastbar = BarIndex() == LastValue(BarIndex());
price1 = Ref(C, -bars);
price2 = Ref(price1,-1+is_lastbar);
hh_price = ValueWhen(bar_flag OR is_lastbar, price2, 0);

Plot( hh_price, "Highest Vol Price", colorRed, styleStaircase );
Plot( C, "Price", colorDefault, styleStaircase );
Plot( bar_flag, "", colorRed, styleHistogram | styleOwnScale | styleNoLabel, 0, 1 );

Yes Sir, this is exactly what I was looking. Color of the horizontal line shd be yellow if TIC greater than previous TIC else white color.

Thank you so much
-Ramesh

but higher timeframe bar is missing ...

Thanks
Ramesh

Are you kidding?
You already have that one! So just add it.

I was responding to your previous post about highest volume price which is also your THREAD SUBJECT!


/// @link https://forum.amibroker.com/t/highest-tic-volume-in-higher-timeframe-chart/25338/12
function BarMarker(tmfrm) {
	local bi;
	TimeFrameSet(tmfrm);
		bi = BarIndex();
	TimeFrameRestore();
	bi = TimeFrameExpand(bi, tmfrm, expandPoint);
	return Ref(Nz(bi)>0,-1);
}

bar_flag = BarMarker(in5Minute);
bars = HighestSinceBars(bar_flag, V); 
is_lastbar = BarIndex() == LastValue(BarIndex());
price1 = Ref(C, -bars);
price2 = Ref(price1,-1+is_lastbar);
hvol_price = ValueWhen(bar_flag OR is_lastbar, price2, 0);

hvol_color = IIf(hvol_price > ValueWhen(bar_flag, hvol_price, 2), colorYellow, colorWhite);
Plot( hvol_price, "Highest Vol Price", hvol_color, styleStaircase );
Plot( C, "Price", colorDefault, styleStaircase );
Plot( bar_flag, "", colorRed, styleHistogram | styleOwnScale | styleNoLabel, 0, 1 );

here i added the color

GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
bardisplayswitch = ParamToggle( "Show True Bar width", "No|Yes", 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

tf = in5Minute; // set timeframe here

exp1 = expandFirst;
lastbarOfPeriod = Nz( TimeFrameExpand( 1, TF, expandPoint ) );
firstbarOfPeriod = Ref( lastbarOfPeriod, -1 );
stepf = ValueWhen( lastbarOfPeriod, bi );

if( !bardisplayswitch OR !( 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, 1, 1 );
}

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

TimeFrameSet( tf );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

prcO2 = O;
prcC2 = C;
TimeFrameRestore();

prcH2 = TimeFrameExpand( prcH, tf, exp1 );
prcL2 = TimeFrameExpand( prcL, tf, exp1 );
prcO2 = TimeFrameExpand( prcO2, tf, exp1 );
prcC2 = TimeFrameExpand( prcC2, 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 );

GfxSetZOrder( -1 );
flg = 0;
prevPrice = 0;

if( bardisplayswitch AND tf > Interval() )
{
    for( i = fvb + 1; i <= lvb; i++ )
    {
        if( lastbarOfPeriod[i] )
        {
            // body
            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y0 = prcO2[i];
            y1 = prcC2[i];

            if( y0 > y1 )
            {
                clr = colorGreen;
                flg = 0;
            }
            else
                if( y0 < y1 )
                {
                    clr = colorBlue;
                    flg = 0;
                }
                else
                {
                    clr = colorLightGrey;
                    flg = 1;
                }

            if( flg == 0 )
            {
                GfxSelectPen( clr, 1, 0 );
                GfxSelectSolidBrush( clr );
                GfxRectangle( x0, y0, x1, y1 );
            }
            else
                if( flg == 1 )
                {
                    GfxSelectPen( clr, 3, 0 );
                    GfxMoveTo( x0, y0 );
                    GfxLineTo( x1, y1 );
                }

            // wicks
            if( priceSwitch )
            {
                GfxSelectPen( clr, 3, 0 );
                x = ( x0 + x1 ) / 2;
                y0 = prcH2[i];
                y1 = prcL2[i];
                GfxMoveTo( x, y0 );
                GfxLineTo( x, y1 );
            }

            // draw spot of highest volume
            x = hvidx[i];
            y0 = prcO2[i];
            y1 = prcC2[i];
            GfxSelectPen( colorYellow, 4, 0 );
            GfxMoveTo( x, y0 );
            GfxLineTo( x, y1 );

            x0 = stepf[i - 1] + 1;
            x1 = stepf[i];
            y = hvPrice[i];

            if( y > prevPrice )
                GfxSelectPen( colorYellow, 4, 0 );
            else
                GfxSelectPen( colorWhite, 4, 0 );

            GfxMoveTo( x0, y );
            GfxLineTo( x1, y );
            prevPrice = y;
        }
    }
}
3 Likes

Thank you sir

This help a lot

-Ramesh

Why would you use looping for simple thing such as plotting such price line on tick chart?

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;
        }
    }
}
2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.