Plot shapes and Graph0

Hi guys,

Some times when attempting to plot shapes, I get the error

"graph0 has not been initialized" - Why is this. Graph0 functions are obsolete. How do I correct this?

Cheers

Without your code no one will be able to answer your query.
Ask question with proper code and error screenshot.

2 Likes

I get this error as well, too:

image

Here is the code I'm using:

  • Amibroker Pro 6.30.5
  • Norgate Data
  • Win 11
_SECTION_BEGIN("Price");
{

	//plot chart data
	thickness = Param( "Bar thickness", -20, -100, 10, 1 );
	
	rc = ROC( C, 1 );
	color = IIf( rc >= 0, colorBlue, IIf( rc < 0, colorRed, -1 ) );

	style = styleNoTitle | styleBar;
	
	PlotOHLC(O, H, L, C, "", color, style, Null, Null, 0, 0, thickness ); 
	
	SetChartOptions( 0, chartShowArrows | chartShowDates );
	
	_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
	
	// Three weeks tight
	ROC_C 	= abs(ROC(C, 1));
	TWTRaw	= ROC_C < 1.5 AND Ref(ROC_C, -1) < 1.5;
	TWT		= TWTRaw OR Sum( Ref( TWTRaw, 2 ), 3 );
		
	PlotShapes(IIf(TWT, shapeHollowSquare, shapeNone), colorGreen, 0, graph0, 0, 0);
	
}
_SECTION_END();	

(Yes I know the use of Ref is non-causal, but this is just for plotting purposes)

I thought graph0 was a built-in parameter such as colorGreen or ShapeNone, per the online reference.

Plotshapes works fine if I use the default values, but if I want to set the offset or XShift input parameters, I'm stuck because I don't know what to use for the yposition input parameter, if graph0 isn't working.

Hope this gives a more digestible issue to support resolution of this kind of error!

Thanks,
Mike

One workaround is to set yPosition to Close and this works fine of course.

graph0 is only defined if you have Plot() call PRECEDING the use of graph0 variable in global context.
You either have to use Plot() or assign graph0 or pass actual value instead of graph0

The problem with your formula is that you have curly braces that don't belong there.
_SECTIONS don't use curly braces. You should write the code without braces

_SECTION_BEGIN("Test");

//plot chart data
thickness = Param( "Bar thickness", -20, -100, 10, 1 );

rc = ROC( C, 1 );
color = IIf( rc >= 0, colorBlue, IIf( rc < 0, colorRed, -1 ) );

style = styleNoTitle | styleBar;

PlotOHLC(O, H, L, C, "", color, style, Null, Null, 0, 0, thickness ); 

SetChartOptions( 0, chartShowArrows | chartShowDates );

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

// Three weeks tight
ROC_C 	= abs(ROC(C, 1));
TWTRaw	= ROC_C < 1.5 AND Ref(ROC_C, -1) < 1.5;
TWT		= TWTRaw OR Sum( Ref( TWTRaw, 2 ), 3 );
	
PlotShapes(IIf(TWT, shapeHollowSquare, shapeNone), colorGreen, 0, graph0, 0, 0);

_SECTION_END();

In fact you should remove _SECTIONS as they are placed AUTOMATICALLY by AmiBroker when you do drag-and-drop and should not be used by hand.

2 Likes

Thanks, Tomasz!

To clarify:

I was using sections so that the Parameter within is grouped into the Price section of the Parameters window, like so:
image

I used the curly braces only so that I can fold the section when coding. It doesn't impact the code when compiled as far as I can tell.

Thanks!
Mike

Sorry, curly braces affect parsing in such that everything that is inside curly braces is a block and as such it is parsed entirely BEFORE execution starts. For this reason graph0 gets resolved to specific address before Plot() is actually executed and what Plot sets is some other variable not graph0. Therefore if you use braces it is recommended NOT to use old-style graph0 hidden variable. graph0 is really old stuff that is left for backward compatibility with formulas that were written before Plot() ever existed.

I will try to address that issue in next update.

2 Likes

Thanks for the clarification on the effect of curly braces. Wasn't aware it changed this!

Take care and happy new year

Hey Mich -

In below ref(), aint you looking into future? (2 weeks Ahead). Wondering did you miss a "-" sign in ref() or was it by design?

TWT		= TWTRaw OR Sum( Ref( TWTRaw, 2 ), 3 );

Also, Have a look how MarketSmith intuitively does background coloring for tight bars, its beyond my AFL skills to achieve this, if you get your hands on this, please let me know.

1 Like

Read my original post, where I specifically say:

(Yes I know the use of Ref is non-causal, but this is just for plotting purposes)

:wink:

And sure you can use low level graphics to maybe get what Marketsmith is able to do in terms of visuals. I just used plotshapes for now for ease of demonstration.

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