Overlay index graph over stock graph of indicator - Chainkin Volatility

I am looking to overlay the chainkin volatility of the index over the stock. I need help in passing the NSEI to the function.

Appreciate help in advance.

Below is the code:

_SECTION_BEGIN("Chaikin Volatility");
function ChaikinVolatility( periods )
{
 return ROC( EMA( High - Low, periods ), periods );
}

Plot( ChaikinVolatility( Param("Periods", 10, 2, 100 ) ),
		_DEFAULT_NAME(), ParamColor( "Color", ColorCycle ) );
PlotForeign( "^NSEI", "Nifty 50", colorRed,style=styleLine|styleOwnScale );

_SECTION_END();

You need to use SetForeign prior to calling Chaikin.

http://www.amibroker.com/f?setforeign

Thank you!! Tomasz .

I am seeing two values in bracket for the SetForeign ticker.

Chaikin Volatility (10,10) = Value, like in the image here.

I am curious why is that happening, can anyone throw some light on it?

@erukumk, you need to post your modified formula where you see the "two values" to get a pertinent answer.

Moreover, please, avoid posting screenshot images using services outside of the forum.
Include your image in the post using the appropriate tags to upload it from a file:

image

or directly "paste" it in the message if you already did a "copy" operation from some application on your PC.

2 Likes

Hi @beppe ,
Going forward will directly paste the screenshot.

zGI52zW

Below is the modified code:

_SECTION_BEGIN("Chaikin Volatility");
function ChaikinVolatility( periods )
{
 return ROC( EMA( High - Low, periods ), periods );
}

Plot( ChaikinVolatility( Param("Periods", 10, 2, 100 ) ),
		_DEFAULT_NAME(), colorBlue );

TR = ParamToggle( "Show Index", "Hide|Show", 0 ); 
if ( TR == 1 ) 
	{
	SetForeign("^NSEI");

	//Plot( ChaikinVolatility( Param("Periods", 10, 2, 100 ) ), "Index Volatility(Periods)", colorAqua );
	Plot( ChaikinVolatility( Param("Periods", 10, 2, 100 ) ), _DEFAULT_NAME(), colorAqua );
	RestorePriceArrays(); 
	}

_SECTION_END();

You need to check if ^NSEI symbol is correct and it EXISTS in the database.
If symbol does not have any qutoes or does not exist SetForeign would fail and won't do anything (leaving data unchanged).

@Tomasz the symbol is correct and has data in it. Earlier snapshot had the same stock and index so showed same values for both.

IEMD15l60b

I have made small changes to the code so posting the latest code.

_SECTION_BEGIN( "Chaikin Volatility" );
function ChaikinVolatility( periods )
{
    return ROC( EMA( High - Low, periods ), periods );
}

Plot( ChaikinVolatility( Param( "Periods", 10, 2, 100 ) ), "Stock "+_DEFAULT_NAME(), colorLightBlue );

TR = ParamToggle( "Show Index", "Hide|Show", 0 );

if( TR == 1 )
{
    SetForeign( "^NSEI" );

    //Plot( ChaikinVolatility( Param("Periods", 10, 2, 100 ) ), "Index Volatility(Periods)", colorAqua );
    Plot( ChaikinVolatility( Param( "Periods", 10, 2, 100 ) ), "Index "+_DEFAULT_NAME(), colorAqua );
    RestorePriceArrays();
}

_SECTION_END();
_SECTION_BEGIN( "Chaikin Volatility" );
function ChaikinVolatility( periods )
{
    return ROC( EMA( High - Low, periods ), periods );
}

index_name = "^NSEI";

TR = ParamToggle( "Show Index", "Hide|Show", 0 );

if ( Name() != index_name )
    Plot( ChaikinVolatility( Param( "Periods", 10, 2, 100 ) ), "Stock "+_DEFAULT_NAME(), colorLightBlue );

if( TR == 1 )
{
    SetForeign( index_name );

    //Plot( ChaikinVolatility( Param("Periods", 10, 2, 100 ) ), "Index Volatility(Periods)", colorAqua );
    Plot( ChaikinVolatility( Param( "Periods", 10, 2, 100 ) ), "Index "+_DEFAULT_NAME(), colorAqua );
    RestorePriceArrays();
}

_SECTION_END();

The program does EXACTLY what you told it to do. You TOLD it to display same thing twice and it displays same thing twice (if selected symbol is the same as index).

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