StaticVarSet/StaticVarGet Multiple Timeframe Assistance

Hoping someone can help me with StaticVarSet/StaticVarGet's and multiple timeframes. I've spent many hours trying to work out an inconsistency I'm finding on my charts and I'm now so frustrated that I thought I'd ask for help.

AmiBroker Version = 6.30.0

First some background. I receive hourly Forex data from my broker. I've chosen the New York rollover time of 17:00 for the beginning of the day bar. These are my Database | Intraday Settings …

image

... and these are my Preferences | Intraday settings …

image

I use five charts (Daily, 12 hour, 6 hour, 3 hour, 1 hour).

I've gone back to absolute basics to understand StaticVarSet/StaticVarGet.

On the hourly chart I have the following AFL …

_SECTION_BEGIN("Chart");
GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

SetBarsRequired( sbrAll, sbrAll );

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

StaticVarSet( "sVSetClose" + varName + ( varInterval * 24 ), Close ); // Daily
StaticVarSet( "sVSetClose" + varName + ( varInterval * 12 ), Close ); // 12 Hourly
StaticVarSet( "sVSetClose" + varName + ( varInterval * 6 ), Close ); // 6 Hourly
StaticVarSet( "sVSetClose" + varName + ( varInterval * 3 ), Close ); // 3 Hourly

//StaticVarSet( "lastBarClose" + varName + ( varInterval * 24 ), LastValue( Close ) ); // Daily
//StaticVarSet( "lastBarClose" + varName + ( varInterval * 12 ), LastValue( Close ) ); // 12 Hourly
//StaticVarSet( "lastBarClose" + varName + ( varInterval * 6 ), LastValue( Close ) ); // 6 Hourly
//StaticVarSet( "lastBarClose" + varName + ( varInterval * 3 ), LastValue( Close ) ); // 3 Hourly

On the 3, 6, 12 hourly and daily charts I have the following AFL …

_SECTION_BEGIN("Chart");
GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

svGetClose = StaticVarGet( "sVSetClose" + varName + varInterval );
//lastBarClose = StaticVarGet( "lastBarClose" + varName + varInterval );
//svGetClose[ LastValue( BarIndex() ) ] = lastBarClose;

x = SelectedValue( BarIndex() );
y = High[ x ];
z = Low[ x ];

PlotTextSetFont( "SVGC " + svGetClose, "Tahoma", 8, x, y, colorGreen, colorDefault, 80 );
PlotTextSetFont( "C " + Close, "Tahoma", 8, x, y, colorGreen, colorDefault, 100 );
PlotTextSetFont( "I " + varInterval + " secs", "Tahoma", 8, x, y, colorGreen, colorDefault, 140 );

The 12 hour chart with the last bar selected looks like this ...

image

I note that the SVG Close (SVGC) on the last bar is DIFFERENT to the Chart Close (C) on the last bar because the last 12 hour bar is incomplete and therefore takes the close of the last completed bar (as per this post https://forum.amibroker.com/t/timeframeset-and-staticvars/5389/34).

The 12 hour chart with the 4th last bar selected looks like this …

image

I note that the SVG Close (SVGC) is the SAME as the Chart Close (C) on all historical bars except the last bar (the value is actually the Close of the last bar before the 12 hour rollover on the hourly chart (in this case either 16:00 or 04:00)).

This behaviour is consistent across the 3, 6 and 12 hour charts but not the daily which I'll discuss later.

If I move the chart back in history and select the last bar on the chart …

image

... I note that the SVG Close (SVGC) is DIFFERENT to the Chart Close (C) which I don't understand as that last bar is in the past and the bar is completed. Can anyone explain why that's the case?

Now to the daily chart.

The daily chart with the last bar selected looks like this …

image

I note that the SVG Close (SVGC) on the last bar is DIFFERENT to the Chart Close (C) on the last bar because the last daily bar is incomplete and therefore takes the close of the last completed bar as detailed above.

The daily chart with the 4th last bar selected looks like this …

image

I note that the SVG Close (SVGC) is DIFFERENT to the Chart Close (C) on all bars. The SVG Close is actually the Close of the first bar of the daily rollover (i.e. 17:00) not the last bar before the next daily rollover (16:00) from the hourly chart. And this is where I've become very frustrated. I don't understand why there's an inconsistency between the daily chart and any of the lower timeframe charts.

I'm guessing that I've got an incorrect setting in my Database or Preferences but I can't work it out. Can anyone help me with my inconsistency?

As an aside if I uncomment the following lines in the AFL code for the hourly chart …

//StaticVarSet( "lastBarClose" + varName + ( varInterval * 24 ), LastValue( Close ) ); // Daily
//StaticVarSet( "lastBarClose" + varName + ( varInterval * 12 ), LastValue( Close ) ); // 12 Hourly
//StaticVarSet( "lastBarClose" + varName + ( varInterval * 6 ), LastValue( Close ) ); // 6 Hourly
//StaticVarSet( "lastBarClose" + varName + ( varInterval * 3 ), LastValue( Close ) ); // 3 Hourly

... and I uncomment the following lines in the AFL code for the higher timeframe charts …

//lastBarClose = StaticVarGet( "lastBarClose" + varName + varInterval );
//svGetClose[ LastValue( BarIndex() ) ] = lastBarClose;

... I note that the SVG Close (SVGC) on the last bar is the SAME as the Chart Close (C) on the last bar (a behaviour I want in the actual code I'm writing) …

image

... and this also works for the last bar back in the history of the chart …

image

Ultimately I'm trying to grab the value of the close (as an example for this post - my real code is obviously different) of the last bar before rollover on the hourly chart for the various higher timeframes (so for daily that would be 16:00 on the hourly, for 12 hourly that would be 16:00 and 04:00, for 6 hourly that would be 16:00, 22:00, 04:00 and 10:00, etc). With the code above I can achieve this on all timeframes except the daily. Can anybody point out what am I doing wrong with my daily chart?

My apologies for posting so many images but it helps me with my explanation of the problem I've got. Would really appreciate some help.

Many thanks

Craig

1 Like

First, despite all the pictures it is still totally unknown WHY do you want to create so many static variables for every interval? What is the reasoning behind that? To plot a chart? You don't need static variables for that. Secondly if you are after mixing timeframes are you sure you should not be rather using TimeFrame functions instead?
Thirdly static variables are saved with timestamps that were present in DateTime() array when they were created using StaticVarSet . If you read them in interval other than originally created then for example if your "current" interval is 5 hour at current timestamp is 10:00 and static variable was stored with 3 hour interval then it will have data for multiplies of 3 (3:00, 6:00, 9:00, 12:00). So in such case there is no exactly matching record for 10:00 and most recent (previous) record in static would be used (i.e. from 9:00). This may or may not be what you might assume that you would get.

Fourthly, did you read this: http://www.amibroker.com/kb/2006/03/19/how-does-the-daily-time-compression-work/

As written here: How to ask a good question despite the length of the post it is still lacking the description of ultimate GOAL you want to achieve.

IMHO, you should be just working with HOURLY (base) time interval and get daily data using TimeFrame functions if you need it. All without using static variables at all.

That is general rule of any multiple-timeframe coding - work with FINEST interval you have and get longer interval data using TimeFrame functions. This is exactly what documentation says:
http://www.amibroker.com/guide/h_timeframe.html

Quote:

PLEASE NOTE that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.

Also keep in mind that the higher interval you want to get must be divisible by the interval you work with. As in the example above, you can't reliably get 5 hour data from 3 hour data, because 5 is not divisible by 3.

3 Likes

I am trying to work out the order of an Outside Period on higher timeframes based on the hourly data. So on a daily chart the Outside Period order might be that the Low of the previous day was broken first and then the High broken second. Or conversely the High was broken first and then the Low. Or on some occasions it might be a High broken, then a Low broken and then the High is broken again. I've calculated this on the hourly timeframe and the final result is recorded as a number on the last bar before the rollover. The value 21 represents High|Low. The value 12 represents Low|High. The value 212 represents High|Low|High.

It's those values I would like to plot on the higher timeframe.

I will look at TimeFrame functions.

I spent last night revisiting the TimeFrame functions again (I had looked at the functions previously to try and plot the Outside Period order from the lower hourly timeframe on the higher daily and 12 hourly timeframes) but according to this ...

… I don't believe I can use the TimeFrame functions because I want to work in the daily and 12 hourly charts and plot the Outside Period order from the hourly chart on the daily and 12 hourly charts. Please correct me if I'm wrong.

And if I'm correct its the reason I've gone down the path of StaticVarSet and StaticVarGet to try and achieve my goal.

Can anyone provide any suggestions as to how I might plot a value from the last bar on the hourly chart that makes up a daily bar and 12 hourly bar on a daily and 12 hourly chart?

I'm really at a loss as to how I proceed.

Thanks

Craig

I've created a screenshot of exactly what I'm after. Hopefully I can explain it so that others understand.

image

The chart on the left is my hourly chart. I've displayed two full days of 1 hour bars which represent the last two bars on the daily chart. The vertical red lines represent the beginning of the day (17:00 New York Time) on the hourly chart. I've marked the Previous Days High and Previous Days Low with horizontal red lines. Above each hourly bar there's a green number. From the start of the current day on the hourly chart (March 19 @ 17:00) you will notice that the previous days low is broken first. When that happens I assign that and subsequent bars the value of 1. Then the previous days high is broken and I append the number 2 to the result. So at the end of the current day on the hourly chart (March 20 @ 16:00) the number above the bar is 12. This means to me that the previous days low was broken first and then the previous days high was broken. If the previous days high was broken first and then the previous days low was broken then the last bar of the day on the hourly chart would have the number 21. Sometimes the low is broken, then the high and then the low and this would be represented by the number 121. If the high and the low is not broken then that would be represented by the number 0.

Now it's that number at the end of the current day on the hourly chart (March 20 @ 16:00) that I'd like to display on the corresponding bar of the daily chart (last bar on the daily chart with the 12 above it).

I hope that makes sense. If it doesn't let me know and I'll try to explain what I'm after in another way.

(And it looks like you have to zoom in with your browser to see all the detail - sorry)

Some thoughts:

  1. While in the Hourly chart, you must have formulated an array that checks (whether high or low was hit first then retraced back) and stores the value accordingly.
  2. We need to compress that array in the Hourly chart to the Higher timeframes (3 - 6 - 12 hrs or Daily) each separately as required using TimeframeCompress.
  3. Then that compressed array needs to be expanded in the Hourly chart itself using TimeframeExpand.
  4. Now from the Hourly chart the values of this expanded array needs to be stored in separate specific StaticVars using ValueWhen TimeNum == your specific timings (30000, 60000 .... 210000).
    Syntax: ValueWhen( tn == 30000, StaticVarSet( "3AMval", YourArray ) );
  5. Now while formulating the Charts for Higher timeframes the appropriate StaticVars are to be called accordingly.
  6. On Higher timeframe chart decide where you want to plot them in terms of BarIndex (X-Axis) and Price (Y-Axis). Plot!
  • At all times the Hourly chart must be open, such that it receives Ticks or gets refreshed for the StaticVar values to be stored appropriately which is to be called and displayed on Higher Timeframe charts.
2 Likes

Hi Craig,

I posted previously while at work, so please ignore the Syntax (it is wrong!). The correct syntax to use a StaticVar / ValueWhen combo would be:

StaticVarSet( "varname", ValueWhen( Condition, Array ), PersistOrNot );

Anyways, the algorithm that I wrote would ideally work for scenarios where one is simply trying to capture lower timeframe data and plot it onto higher timeframes. But I doubt your needs may differ. So, I have coded in a slightly different manner, however, almost similar to the logic in the algorithm.

Please study these codes, it might help you precisely code your requirements:

For Hourly Charts:

// As per your first post, using Close as the "array" instead of using your custom array.
// Using the similar method you can replicate the same for your custom HL array too.
// Presuming that you want to transfer the following from the Hourly Chart to the Daily Chart (you will have to write separately for each timeframe)
/*
	1. Close of 0300 HRS
	2. Close of 0600 HRS
	3. Close of 0900 HRS
	4. Close of 1200 HRS
	5. Close of 1500 HRS
	6. Close of 1800 HRS
	7. Close of 2100 HRS
*/
_SECTION_BEGIN( "Hourly Chart" );

SetChartOptions( 0, chartShowDates );

tn = TimeNum();
bi = BarIndex();

// To Daily Timeframe only
tf = Interval() * 24;
DayFirstBiComp = TimeFrameCompress( bi, tf, compressOpen );
DayFirstBi = TimeFrameExpand( DayFirstBiComp, tf, expandFirst );
DayLastBiComp = TimeFrameCompress( bi, tf, compressLast );
DayLastBi = TimeFrameExpand( DayLastBiComp, tf, expandFirst );

for( i = SelectedValue( DayFirstBi ); i <= SelectedValue( DayLastBi ); i++ )
{
	if( tn[ i ] == 60000 )
	{
		StaticVarSet( "Hourly0600HrsC" + Name() + tf, C[ i ], 0 );
		PlotTextSetFont( "0600HRS\nClose@\n" + NumToStr( C[ i ], 1.5 ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 50 );				
	}
	
	if( tn[ i ] == 120000 )
	{
		StaticVarSet( "Hourly1200HrsC" + Name() + tf, C[ i ], 0 );
		PlotTextSetFont( "1200HRS\nClose@\n" + NumToStr( C[ i ], 1.5 ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 50 );		
	}
	
	if( tn[ i ] == 180000 )
	{
		StaticVarSet( "Hourly1800HrsC" + Name() + tf, C[ i ], 0 );
		PlotTextSetFont( "1800HRS\nClose@\n" + NumToStr( C[ i ], 1.5 ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 50 );
	}
}
StaticVarSet( "ThisDay" + Name() + tf, SelectedValue( DateNum() ), False );

Plot( Close, "Close", colorDefault, styleCandle | styleNoTitle );

RequestTimedRefresh( 1 );

_SECTION_END();

For Daily Charts:

_SECTION_BEGIN( "Daily Chart" );

SetChartOptions( 0, chartShowDates );

fvb = Status( "FirstVisibleBar" );
lvb = Min( Status( "LastVisibleBar" ), BarCount - 1 );

tf = Interval();
dn = DateNum();
bi = BarIndex();

for( i = fvb; i <= lvb; i++ )
{
	if( dn[ i ] == StaticVarGet( "ThisDay" + Name() + tf ) )
	{
		PlotTextSetFont( "Dated " + DateTimeToStr( DateTimeConvert( 2, dn[ i ] ) ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 53 );
		
		Hourly0600HrsC = StaticVarGet( "Hourly0600HrsC" + Name() + tf );
		PlotTextSetFont( "0600Hrs Close @ " + NumToStr( Hourly0600HrsC, 1.5 ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 42 );
		
		Hourly1200HrsC = StaticVarGet( "Hourly1200HrsC" + Name() + tf );
		PlotTextSetFont( "1200Hrs Close @ " + NumToStr( Hourly1200HrsC, 1.5 ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 28 );
		
		Hourly1800HrsC = StaticVarGet( "Hourly1800HrsC" + Name() + tf );
		PlotTextSetFont( "1800Hrs Close @ " + NumToStr( Hourly1800HrsC, 1.5 ), "Arial", 8, bi[ i ], H[ i ], colorAqua, colorBlack, 14 );
	}
}

Plot( Close, "Close", colorDefault, styleCandle | styleNoTitle );

RequestTimedRefresh( 1 );

_SECTION_END();


(Click on the image to enlarge it)

Kindly note that I am making the selection in the Hourly Chart only and its values are automatically getting reflected to the Daily Chart.

2 Likes

Thank you Cougar

Let me study your code so that I fully understand the solution. I will post back to let you know how I've gone.

Really appreciate the time you've taken to help me out.

Cheers

Craig

Cougar

I've gone through your code and understand how it works. It was this code for the hourly chart that got me thinking …

DayLastBiComp = TimeFrameCompress( bi, tf, compressLast );
DayLastBi = TimeFrameExpand( DayLastBiComp, tf, expandFirst );

The "expandFirst" I hadn't really understood and I plotted some compressed and expanded values on the hourly chart to see what was happening and I think I understand more now.

Going back to the original code I posted I've made a couple of modifications and now use the TimeFrame functions. New code for the hourly chart here …

_SECTION_BEGIN("Chart");
GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

SetBarsRequired( sbrAll, sbrAll );

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

dailyclosecompress24 = TimeFrameCompress( Close, varInterval * 24 );
dailycloseexpand24 = TimeFrameExpand( dailyclosecompress24, varInterval * 24, expandFirst );

dailyclosecompress12 = TimeFrameCompress( Close, varInterval * 12 );
dailycloseexpand12 = TimeFrameExpand( dailyclosecompress12, varInterval * 12, expandFirst );

StaticVarSet( "svSetClose" + varName + ( varInterval * 24 ), dailycloseexpand24 ); // Daily
StaticVarSet( "svSetClose" + varName + ( varInterval * 12 ), dailycloseexpand12 ); // 12 Hourly

And this is the slightly modified code for the higher timeframes …

_SECTION_BEGIN("Chart");
GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

svGetClose = StaticVarGet( "svSetClose" + varName + varInterval );
lastBarClose = StaticVarGet( "lastBarClose" + varName + varInterval );

x = SelectedValue( BarIndex() );
y = High[ x ];
z = Low[ x ];

PlotTextSetFont( "C " + Close, "Tahoma", 8, x, y, colorGreen, colorDefault, 80 );
PlotTextSetFont( "SVG C " + svGetClose, "Tahoma", 8, x, y, colorGreen, colorDefault, 100 );

When I view the Close and svGetClose values on the daily chart the values are the same on all bars that I check (including the very last daily bar and, if I go back in time on the chart, the last visible bar). This is exactly the outcome I'm after.

When I view the Close and svGetClose values on the 12 hour chart the values are the same on all bars EXCEPT the very last 12 hourly bar and, if I go back in time on the chart, the last visible bar).

I don't understand why there's a difference but if I can make the behaviour the same for both timeframes then I will have a working solution for my Outside Period order issue I'm trying to resolve.

Really appreciate your assistance to date.

Cheers

Craig

Sorry I noticed a small error in my code for the higher timeframes. Should be this …

_SECTION_BEGIN("Chart");
GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

svGetClose = StaticVarGet( "svSetClose" + varName + varInterval );

x = SelectedValue( BarIndex() );
y = High[ x ];
z = Low[ x ];

PlotTextSetFont( "C " + Close, "Tahoma", 8, x, y, colorGreen, colorDefault, 80 );
PlotTextSetFont( "SVG C " + svGetClose, "Tahoma", 8, x, y, colorGreen, colorDefault, 100 );

Hello Craig,

No need to recreate TimeFrame Compress/Expand manually using Loops on Hourly Chart. I have not extensively tested the below codes for all the possibilities, but it seems to be working. Not sure, on how to use it as Exploration or Backtest (may be check later) but as long as you use it as indicator for visual purposes on chart, after a refresh (its crucial) the value of last bar would show-up as you want.

For Hourly:

_SECTION_BEGIN("Hourly Chart");
GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
_SECTION_END();

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

bi = BarIndex();

//Daily
closecompress24 = TimeFrameCompress( Close, varInterval * 24 );
closeexpand24 = TimeFrameExpand( closecompress24, varInterval * 24, expandFirst );
StaticVarSet( "svSetClose" + varName + ( varInterval * 24 ), closeexpand24, 0 ); // Daily

//12-Hourly
dt12 = StaticVarGet( "DT" + varName + varInterval * 12 );
LastBi12HrComp = TimeFrameCompress( bi, varInterval * 12, compressLast );
LastBi12Hr = Lookup( TimeFrameExpand( LastBi12HrComp, varInterval * 12 ), dt12 );

closecompress12 = TimeFrameCompress( Close, varInterval * 12 );
closeexpand12 = TimeFrameExpand( closecompress12, varInterval * 12, expandFirst );
StaticVarSet( "svSetClose" + varName + ( varInterval * 12 ), IIf( LastBi12Hr >= BarCount - 1 - 12, LastValue( C ), closeexpand12 ), 0 ); // 12 Hourly

//6-Hourly
dt6 = StaticVarGet( "DT" + varName + varInterval * 6 );
LastBi6HrComp = TimeFrameCompress( bi, varInterval * 6, compressLast );
LastBi6Hr = Lookup( TimeFrameExpand( LastBi6HrComp, varInterval * 6 ), dt6 );

closecompress6 = TimeFrameCompress( Close, varInterval * 6 );
closeexpand6 = TimeFrameExpand( closecompress6, varInterval * 6, expandFirst );
StaticVarSet( "svSetClose" + varName + ( varInterval * 6 ), IIf( LastBi6Hr >= BarCount - 1 - 6, LastValue( C ), closeexpand6 ), 0 ); // 6 Hourly

RequestTimedRefresh( 1 );

For Higher Timeframes:

_SECTION_BEGIN("Chart");

GraphXSpace = 50;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
	Open %.5f, High %.5f, Low %.5f, Close %.5f
	{{VALUES}}", O, H, L, C ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

varName = Name(); // Set varName to chart symbol
varInterval = Interval(); // Set varInterval to chart interval (seconds)

svGetClose = StaticVarGet( "svSetClose" + varName + varInterval );
lastBarClose = StaticVarGet( "lastBarClose" + varName + varInterval );

x = SelectedValue( BarIndex() );
y = High[ x ];
z = Low[ x ];

PlotTextSetFont( "C " + Close, "Tahoma", 8, x, y, colorGreen, colorDefault, 80 );
PlotTextSetFont( "SVG C " + svGetClose, "Tahoma", 8, x, y, colorGreen, colorDefault, 100 );

dt = DateTime();
StaticVarSet( "DT" + varName + varInterval, SelectedValue( dt ), 0 );

RequestTimedRefresh( 1 );
4 Likes

Thanks Cougar.

Let me try out the code and I'll let you know

Cheers

Craig

Cougar

I've looked through the code and understand how it's working. Appreciate the time you took to respond to my post.

Many thanks

Craig